php - testing with phpunit -
i'm trying test controllers. followed guide:
http://www.zendcasts.com/unit-testing-a ... s/2010/11/
everything ok until wanted use call in test function: $this->dispatch('/'); thing problem bootstrapping, don't know how resolve this. paste files involved in testing:
application.ini = http://pastie.org/2248669
phpunit.xml =
<phpunit bootstrap="./application/bootstrap.php" colors="true"> <testsuite name="application test suite"> <directory>./application</directory> </testsuite> <testsuite name="library test suite"> <directory>./library</directory> </testsuite> <filter> <!-- if zend framework inside project's library, uncomment filter --> <whitelist> <directory suffix=".php">../application</directory> <directory suffix=".php">../library/kolcms</directory> <exclude> <directory suffix=".php">../library/zend</directory> <directory suffix=".php">../library/kolcms/model/db</directory> <directory suffix=".phtml">../library/</directory> <directory suffix=".phtml">../application/</directory> <file suffix=".php">../application/bootstrap.php</file> </exclude> </whitelist> </filter> <logging> <log type="coverage-html" target="./log/report" charset="utf-8" yui="true" highlight = "true" lowupperbound="50" highlowerbound="80" /> </logging> bootstrap.php =
<?php // define path application directory defined('application_path') || define('application_path', realpath(dirname(__file__) . '/../../application')); // define application environment define('application_env', 'testing'); // ensure library/ on include_path set_include_path(implode(path_separator, array( realpath(application_path . '/../library'), realpath(application_path . '/../../../zend'), get_include_path() ))); /** zend_application */ require_once 'zend/application.php'; require_once 'controllertestcase.php'; // create application, bootstrap, , run $application = new zend_application( application_env, application_path . '/configs/application.ini' ); $application->bootstrap(); clearstatcache(); controllertestcase.php =
<?php require_once 'zend/test/phpunit/controllertestcase.php'; class controllertestcase extends zend_test_phpunit_controllertestcase { /** * * @var zend_application */ protected $application; public function setup() { $this->bootstrap = array($this,'appbootstrap'); parent::setup(); } public function appbootstrap() { $this->application = new zend_application( application_env, application_path . '/configs/application.ini' ); $this->application->bootstrap(); } public function teardown() { $this->resetrequest(); $this->resetresponse(); parent::teardown(); } } indexcontrollertest.php =
<?php include_once application_path . '/modules/core/controllers/indexcontroller.php'; class core_indexcontrollertest extends controllertestcase { public function testdefaultshouldinvokeaction() { $this->dispatch('/core/index/index'); $this->assertcontroller('index'); $this->assertaction('index'); $this->assertmodule('core'); } } and here phpunit output:
$ phpunit phpunit 3.5.5 sebastian bergmann. php fatal error: call member function hasresource() on non-object in /home/aykut/dev/kolonicms/application/modules/core/controllers/errorcontroller.php on line 49 fatal error: call member function hasresource() on non-object in /home/aykut/dev/kolonicms/application/modules/core/controllers/errorcontroller.php on line 49 can me, please. thank you
my guess don't have route url /core/index/index, , zf redirecting error controller. next, errorcontroller.php has bug causes call hasresource() method on variable doesn't hold object or null. easier diagnose issue if fix error controller first.
this precisely why built separate abstract test-case classes controllers , views. don't zend's controllertestcase tests route, dispatcher, , views in addition controller.
Comments
Post a Comment