chciałem napisać testy jednostkowe do swojej nowej aplikacji pisanej w ZF. Przeczytałem już kilka tutoriali w Sieci na ten temat, ale nie mogę sobie poradzić z jednym problemem.
Mianowicie: nie mogę wykorzystać swoich klas, które są przechowywane w ./application/model. Testy przechowuje oczywiście w katalogu ./tests/application/constrollers.
Test, który chcę odpalić wygląda tak:
Kod
require_once 'PHPUnit/Framework/TestCase.php';
class TestControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{
private $model = null;
public function setUp(){
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$this->bootstrap = array($application->getBootstrap(), 'bootstrap');
$this->model = new Application_Model_TagList(100);
return parent::setUp();
}
public function testFirst(){
$this->model->addItem(new Application_Model_Tag('pierwszy_tag'));
$this->assertEquals(count($this->model->getArray()), 1);
}
public function tearDown()
{
/* Tear Down Routine */
}
}
class TestControllerTest extends Zend_Test_PHPUnit_ControllerTestCase
{
private $model = null;
public function setUp(){
$application = new Zend_Application(APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini');
$this->bootstrap = array($application->getBootstrap(), 'bootstrap');
$this->model = new Application_Model_TagList(100);
return parent::setUp();
}
public function testFirst(){
$this->model->addItem(new Application_Model_Tag('pierwszy_tag'));
$this->assertEquals(count($this->model->getArray()), 1);
}
public function tearDown()
{
/* Tear Down Routine */
}
}
plik ./tests/application/boostrap.php ma taką zawartość:
Kod
set_include_path(implode(PATH_SEPARATOR, array(
realpath(dirname(__FILE__) . '/../../library'),
get_include_path(),
)));
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'testing');
defined('APPLICATION_LOAD_TESTDATA') || define('APPLICATION_LOAD_TESTDATA', true);
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
spl_autoload_unregister(array($autoloader, 'autoload'));
Zend_Loader_Autoloader::resetInstance();
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('PHPUnit_');
realpath(dirname(__FILE__) . '/../../library'),
get_include_path(),
)));
defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application'));
defined('APPLICATION_ENV') || define('APPLICATION_ENV', 'testing');
defined('APPLICATION_LOAD_TESTDATA') || define('APPLICATION_LOAD_TESTDATA', true);
require_once 'Zend/Loader/Autoloader.php';
$autoloader = Zend_Loader_Autoloader::getInstance();
spl_autoload_unregister(array($autoloader, 'autoload'));
Zend_Loader_Autoloader::resetInstance();
$autoloader = Zend_Loader_Autoloader::getInstance();
$autoloader->registerNamespace('PHPUnit_');
a ./tests/phpunit.xml taką:
<phpunit bootstrap="./application/bootstrap.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" stopOnFailure="false"> <testsuite name="Test_ZF"> <directory>./application/</directory> </testsuite> </phpunit>
Test odpalam poleceniem "phpunit" będąc w katalogu ./tests. W odpowiedzi konsola zwraca mi komunikat:
Cytat
szymon@szymon-Vostro-1440:/var/www/tt/tests$ phpunit
PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from /var/www/tt/tests/phpunit.xml
.E
Time: 1 second, Memory: 8.25Mb
There was 1 error:
1) TestControllerTest::testFirst
Zend_Db_Table_Exception: No adapter found for Application_Model_DbTable_MomentToTag
/var/www/tt/library/Zend/Db/Table/Abstract.php:755
/var/www/tt/library/Zend/Db/Table/Abstract.php:739
/var/www/tt/library/Zend/Db/Table/Abstract.php:268
/var/www/tt/application/models/TagList.php:15
/var/www/tt/tests/application/controllers/TestControllerTest.php:16
FAILURES!
Tests: 2, Assertions: 1, Errors: 1.
PHPUnit 3.6.10 by Sebastian Bergmann.
Configuration read from /var/www/tt/tests/phpunit.xml
.E
Time: 1 second, Memory: 8.25Mb
There was 1 error:
1) TestControllerTest::testFirst
Zend_Db_Table_Exception: No adapter found for Application_Model_DbTable_MomentToTag
/var/www/tt/library/Zend/Db/Table/Abstract.php:755
/var/www/tt/library/Zend/Db/Table/Abstract.php:739
/var/www/tt/library/Zend/Db/Table/Abstract.php:268
/var/www/tt/application/models/TagList.php:15
/var/www/tt/tests/application/controllers/TestControllerTest.php:16
FAILURES!
Tests: 2, Assertions: 1, Errors: 1.
Co mam zrobić, aby móc bezproblemowo używać testów jednostkowych wykorzystujących bibliotekę Zenda i moje klasy?
Proszę o pomoc, bo już nie mam do tego cierpliwości. Z góry dzięki

Pozdrawiam