Ok, it's official: i'm going nuts. This has bothered me for some time now and it's the single thing that stops me to unit test my app(s).
I'm following this tutorial, with some modifications (the autoloader, notably): http://blog.fedecarg.com/2008/12/27/testing-zend-framework-controllers/ PHPUnit 5.5.15 (it works; tested with non-ZF unit-tests) ZF 1.11.3 PHP 5.3.5 NetBeans 7.0.1 WinXP *myApp/tests/boostrap.php * > > error_reporting( E_ALL | E_STRICT ); > ini_set('display_startup_errors', 1); > ini_set('display_errors', 1); > date_default_timezone_set('Europe/London'); > > define('APPLICATION_PATH', realpath(dirname(__FILE__) . > '/../application')); > define('APPLICATION_ENV', 'development'); > define('LIBRARY_PATH', realpath(dirname(__FILE__) . '/../library')); > define('TESTS_PATH', realpath(dirname(__FILE__))); > > //$_SERVER['SERVER_NAME'] = 'http://localhost'; > > $includePaths = array(LIBRARY_PATH, get_include_path()); > set_include_path(implode(PATH_SEPARATOR, $includePaths)); > > require_once "Zend/Loader/Autoloader.php"; > Zend_Loader_Autoloader::getInstance(); > > Zend_Session::$_unitTestEnabled = true; > Zend_Session::start(); > *myApp/phpunit.xml* > <phpunit bootstrap="./bootstrap.php" colors="true"> > <testsuite name="brainy"> > <directory>./application</directory> > <directory>./library</directory> > </testsuite> > > <filter> > <whitelist> > <directory suffix=".php">../application/</directory> > <exclude> > <file>../application/Bootstrap.php</file> > <!-- > <file>application/controllers/ErrorController.php</file>--> > <directory suffix=".phtml">../application/views</directory> > </exclude> > </whitelist> > </filter> > > > <logging> > <log type="coverage-html" target="./log/report" charset="UTF-8" > yui="true" highlight="true" lowUpperBound="50" highLowerBound="80" /> > <log type="testdox" target="./log/testdox.html"/> > </logging> > </phpunit> > *myApp/tests/application/ControllerTestCase.php* > <?php > > class ControllerTestCase extends Zend_Test_PHPUnit_ControllerTestCase > { > public $application; > > public function setUp() > { > $this->application = new Zend_Application( > APPLICATION_ENV, > APPLICATION_PATH . '/configs/application.ini' > ); > > $this->application->bootstrap(); > parent::setUp(); > } > > public function tearDown() > { > Zend_Controller_Front::getInstance()->resetInstance(); > $this->resetRequest(); > $this->resetResponse(); > > $this->request->setPost(array()); > $this->request->setQuery(array()); > } > > // public function bootstrap() > // { > // $this->application->bootstrap(); > // } > } > * myApp/tests/application/controllers/IndexControllerTest.php * > > require_once APPLICATION_PATH . '/controllers/IndexController.php'; > require_once TESTS_PATH . '/application/ControllerTestCase.php'; > > /** > * @group Controllers > */ > class IndexControllerTest extends ControllerTestCase > { > public function testDefaultShouldInvokeIndexAction() > { > $this->dispatch('/'); > $this->assertController('index'); > $this->assertAction('index'); > } > > public function testViewObjectContainsStringProperty() > { > $this->dispatch('/'); > > $controller = new IndexController( > $this->request, > $this->response, > $this->request->getParams() > ); > $controller->indexAction(); > > $this->assertTrue(isset($controller->view->containerClass)); > } > } > Here's ONE of the errors when running PHPUnit in NB (each of them - 3 - has the same exception): > IndexControllerTest::testDefaultShouldInvokeIndexAction() > Zend_Loader_PluginLoader_Exception: Plugin by name 'Meta' was not found in > the registry; used paths: > Helpers_View_: library/helpers/view/ > Zend_View_Helper_: > Zend/View/Helper/;D:\xampp\htdocs\myApp\application/views\helpers/ > D:\xampp\ZendFramework-1.11.3\library\Zend\Loader\PluginLoader.php:412 > D:\xampp\ZendFramework-1.11.3\library\Zend\View\Abstract.php:1174 > D:\xampp\ZendFramework-1.11.3\library\Zend\View\Abstract.php:610 > D:\xampp\ZendFramework-1.11.3\library\Zend\View\Abstract.php:336 > D:\xampp\htdocs\myApp\application\Bootstrap.php:113 > D:\xampp\htdocs\myApp\application\Bootstrap.php:113 > > D:\xampp\ZendFramework-1.11.3\library\Zend\Application\Bootstrap\BootstrapAbstract.php:667 > > D:\xampp\ZendFramework-1.11.3\library\Zend\Application\Bootstrap\BootstrapAbstract.php:620 > > D:\xampp\ZendFramework-1.11.3\library\Zend\Application\Bootstrap\BootstrapAbstract.php:584 > D:\xampp\ZendFramework-1.11.3\library\Zend\Application.php:355 > D:\xampp\htdocs\myApp\tests\application\ControllerTestCase.php:14 > This is what bothers ZF: *myApp\application\Bootstrap.php* > public function _initMeta() > { > $this->bootstrap('view'); > $view = $this->getResource('view'); > $metaDataArr = $this->_config->custom->meta->toArray(); > return $view->meta($metaDataArr); // <-- line 113 > } > This view helper is actually stored in the library folder (not being app-specific): *myApp\library\helpers\view\Meta.php* > <?php > > class Helpers_View_Meta extends Zend_View_Helper_Abstract > { > private $_dataArr = array(); > > private $_metaTemplate = > '<meta name="description" content="%s" /> > <meta name="keywords" content="%s" /> > <meta name="language" content="%s" /> > <meta name="copyright" content="%s" /> > <meta name="robots" content="%s" />'; > > public function meta($dataArr = array()) > { > $this->_dataArr = array_merge($this->_dataArr, $dataArr); > return $this; > } > > public function __toString() > { > return sprintf($this->_metaTemplate, > @$this->_dataArr['description'], > @$this->_dataArr['keywords'], > @$this->_dataArr['language'], > @$this->_dataArr['copyright'], > @$this->_dataArr['robots'] > ); > } > } This is in *myApp/application/configs/application.ini*: resources.view.helperPath.Helpers_View = "library/helpers/view" The application actually works fine. I know about *some* of the differences between an application bootstrap and a testing one, but I guess I miss something. I've tried several layouts for unit testing (moving the bootstrap here and there), and the same exception is thrown. I do apologize for the long code dump, though. Regards, Adrian.
