2

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
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
  • have you managed to run the tests? – St.Woland Dec 31 '10 at 09:01
  • @St.Woland, Hmm yes, now that you've asked, it seems all tests run, at least when I just have 1 test. Maybe it gets thrown right at the end, does it trigger anything? – Jiew Meng Dec 31 '10 at 09:27
  • Try disabling error resource for your application and see what output you get. It may be related to some other error in your code. – St.Woland Dec 31 '10 at 09:31
  • @St.Woland, what do you mean by disabling error resource? – Jiew Meng Dec 31 '10 at 13:55
  • There is a resource named ErrorHandler. It initializes controller plugin ErrorHandler. I suggest that you look up your application.ini for any mentioning of `errorHandler` and comment those lines out. – St.Woland Jan 01 '11 at 21:30
  • @St.Woland, It seems my `application.ini` generated by Zend_Tool does not have `errorHandler` in it. It looks like http://pastebin.com/DqbvZC5K – Jiew Meng Jan 02 '11 at 02:37

1 Answers1

6

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);
Maxence
  • 12,868
  • 5
  • 57
  • 69
  • Oh ... I can use `$application->getBootstrap()` but how can I get `$application` from my `ControllerTestCase`? I tried putting that line in my phpunit's `bootstrap.php` it didn't work, I still got missing resource – Jiew Meng Jan 02 '11 at 02:33
  • Some oddities I find too, I am getting "No default module defined" tho I am not using modules and in my `application.ini` I have already defined `controllerDirectory` my Qn & Sol [**here**](http://stackoverflow.com/questions/4507165/zend-test-no-default-module-defined-for-this-application). I wonder if they are related. It seems like my frontController is reset or something. When I `$bootstrap = $this->getFrontController()->getParam('bootstrap')` and `print_r($bootstrap)` I get nothing – Jiew Meng Jan 02 '11 at 02:43
  • Ok I solved the problem with **http://stackoverflow.com/questions/2507996/getting-a-no-default-module-defined-for-this-application-exception-while-runnin/2510549#2510549** – Jiew Meng Jan 02 '11 at 03:09