Unit Testing with Zend_Test: Call to a member function hasResource() on a non-object in Zend's ErrorController

StackOverflow https://stackoverflow.com/questions/4568797

سؤال

I am getting this error

Fatal error: Call to a member function hasResource() on a non-object in D:\Projects\Tickle\application\controllers\ErrorController.php on line 53

where line 53 looks like

if (!$bootstrap->hasResource('Log')) {

It seems like $this->getInvokeArg('bootstrap') returns null. I got no other errors. I read somewhere else for another problem that an exception maybe raised that resets my controller or bootstrap or something like that. Is it possible that that exception not be shown? even in the PHP error log?

My current setup looks like

The single test runs fine but I still got the error

D:\Projects\Tickle\tests>phpunit
PHPUnit 3.5.5 by Sebastian Bergmann.

.
Fatal error: Call to a member function hasResource() on a non-object in D:\Projects\Tickle\application\controllers\Error
Controller.php on line 53
هل كانت مفيدة؟

المحلول

bootstrap param is registered when you call $application->run(). In your unit test bootstrap, run is not called. You have to set the boostrap param yourself with this code :

Zend_Controller_Front::getInstance()->setParam('bootstrap', $bootstrap);
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top