|
|
|
huajun qi
|
We are trying to build a stable and easy-to-use testing system within Zend Framework.
I created a module named user, and some models such as User_Model_User class under application/modules/user/models, actually made it work with your help. All models have extended Zend_Db_Table class.
Now I want to test the model. I watched a great video tutorial at: http://www.zendcasts.com/unit-testing-with-the-zend-framework-with-zend_test-and-phpunit/2009/06/, and I followed it to bulid testing framework. I have written phpunit.xml, bootstrap file, controllertestcast.php, and UserTest.php file. I add a testing function:
public function testCanItWork(){ $this->assertTrue(true); }
in UserTest.php. Everything goes well. When I try to test the model really, errors are reported that User_Model_User are not found, I include it and got another error message "Zend_Db_Table are not found",
I include all required files, but still get errors: Zend_Db_Table has no adapter. I am totally confused. I don't know how to fix it. I have found that the application has been bootstraped, but why the classes I need are not autoloaded?
I have read configurations and register it, set default adapter for Zend_Db_Table in application's bootstrap file, and the application are bootstraped successfully, but why I can not get it?
|
||||||||||||||||
|
huajun qi
|
I believe your way can work in production environment, but i doubt whether it works in testing environment?
And even though it works, I still can no get configs i registered, so i don't think path is the essence of problem.
2009/10/12 Marcus Ramsden <[hidden email]>
-- Location: |
|
huajun qi
|
Of course.
bootstrap.php: <?php error_reporting(E_ALL|E_STRICT); // Define path to application directory defined('APPLICATION_PATH') || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../../application')); // Define application environment defined('APPLICATION_ENV') || define('APPLICATION_ENV', (getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'testing')); // Ensure library/ is on include_path set_include_path(implode(PATH_SEPARATOR, array( realpath(APPLICATION_PATH . '/../library'), get_include_path() ))); /** Zend_Application */ require_once 'Zend/Application.php'; require_once 'ControllerTestCase.php'; ControllerTestCase.php: <?php require_once 'Zend/Application.php'; require_once 'Zend/Test/PHPUnit/ControllerTestCase.php'; class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase { protected $application; public function setUp() { $this->bootstrap = array ($this, 'appBootstrap' ); parent::setUp (); } //bootstrap the application public function appBootstrap() { $this->application = new Zend_Application ( APPLICATION_ENV, APPLICATION_PATH . '/configs/application.ini' ); $this->application->bootstrap (); } } ?> And bootstrap file in application: <?phpclass Bootstrap extends Zend_Application_Bootstrap_Bootstrap {protected function _initControllers(){$this->bootstrap ( 'FrontController' );$front = $this->frontController;$front->throwExceptions ( true );$front->addModuleDirectory ( '../application/modules' );}protected function _initConfig(){$config=new Zend_Config(array(APPLICATION_PATH . '/configs/application.ini'));Zend_Registry::set('config',$config);}protected function _initDatabase() {$dbresource = $this->getPluginResource ( 'db' );$db = $dbresource->getDbAdapter ();Zend_Registry::set ( 'db', $db );Zend_Db_Table::setDefaultAdapter ( $db );}protected function _initLog() {$logconfigs = $this->getOption('log');$logger = new Zend_Log ( );$writer = new Zend_Log_Writer_Stream ( $logconfigs['filepath'] );$logger->addWriter ( $writer );Zend_Registry::set ( 'logger', $logger );}protected function _initModels() {$autoloader = Zend_Loader_Autoloader::getInstance ();$autoloader->registerNamespace ( 'Mt' );}} 2009/10/12 Marcus Ramsden <[hidden email]>
-- Location: |
||||||||||||||||
| Free Embeddable Forum Powered by Nabble | Help |