Hi, finally managed to get phpunit configured all nice and happy with that,
but i'm having some trouble autoloading my models into my test scripts. I
think the issue is that i am calling my models with their namespace prefix
(new Domain_Model_Something) whereas the test scripts have no idea of the
namespace as it is throwing a file not found on an include statement.

My directory structure is:
project/
project/application
project/application/models
project/application/controllers (etc)
project/application/tests
project/library 
project/httpdocs

Here is my phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>

        
                
                        ./controllers
                
                
                        ./models
                
                
                        ./
                
        


...and the phpunit bootstrap, TestHelper.php;
<?php
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1); 

date_default_timezone_set('Europe/London');

define('APPLICATION_ENV', 'testing');
define('APPLICATION_PATH', realpath(dirname(__FILE__) .
'/../../application'));

// Directories for include path
$root = realpath(dirname(__FILE__) . '/../../');
$library = $root . DIRECTORY_SEPARATOR . 'library';
$models = $root . DIRECTORY_SEPARATOR . 'application' . DIRECTORY_SEPARATOR
.'models';

$path = array(
    $library,
    $models,
    get_include_path()
);

set_include_path(implode(PATH_SEPARATOR, $path));

require_once 'Zend/Loader/Autoloader.php';
$loader = Zend_Loader_Autoloader::getInstance();

// Unset global variables
unset($root, $library, $models, $path);

And my simple test:
require_once 'PHPUnit/Framework.php';
        class News_ArticleTest extends PHPUnit_Framework_TestCase
        {
                public function testInstance(){
                        $news = new Domain_Model_News_Article();
                        $this->assertInstanceOf('Domain_Model_News_Article', 
$news);
                }
        }

Do i need to add the 'Domain' namespace to the autoloader? Testing with
loading Zend_ classes seems to be ok so i can only assume it has no idea
what or where a 'Domain_Model_' is?

--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/Testing-ZF-models-with-PHPUnit-tp3348158p3348158.html
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to