On Sat, Sep 5, 2009 at 6:19 AM, Jens Kleikamp <[email protected]>wrote:

> David Mintz wrote:
>
>> Playing around with Zend_Application and friends, I made a Bootstrap.php
>> which does this:
>>
>> protected function _initLog() {
>>
>>        printf ("running %s:%s()\n",__CLASS__,__FUNCTION__);
>>        return new Zend_Log(new Zend_Log_Writer_Firebug());
>> }
>> ---
>>
>> And a controller plugin:
>>
>> ---
>>
>> class Plugin_OurTestPlugin extends Zend_Controller_Plugin_Abstract {
>>
>>
>>    function preDispatch(Zend_Controller_Request_Abstract $request ) {
>>
>>        $front = Zend_Controller_Front::getInstance();
>>        $bootstrap = $front->getParam('bootstrap');
>>        printf ("\$bootstrap is a %s.\n", gettype($bootstrap));
>>        $log = $front->getParam('bootstrap')->getResource('log');
>>        $log->info('woo hoo, your controller plugin works');
>>    }
>> }
>> ---
>> In a browser, the printf statement outputs " $bootstrap is a object" and
>> indeed it is, but when I run phpunit tests from the command line, --
>> forgive
>> all the "echo" output, I have temporarily polluted my code with echo()s in
>> order to determine what's executing --
>>
>>
>> Bootstrap constructor running...
>> running Bootstrap:_initLog()
>> we are bootstrapping the application in
>> /opt/www/shitou/tests/ControllerTestCase.php
>> $bootstrap is a NULL.
>>
>> Fatal error: Call to a member function getResource() on a non-object in
>> /opt/www/shitou/application/plugins/OurTestPlugin.php on line 14
>> <snip/>
>>
>


>
> I stumbled across the same issue lately.
>
> The bootstrap object is assigned as a frontcontroller param in the run()
> method of Zend_Application_Bootstrap_Bootstrap. But this method is not
> executed in the test environment, only bootstrap().
> I think thatæ„€ the reason for the error you get (Fatal error: Call to a
> member function getResource() on a non-object...)
>
> As a workaround I set the frontcontroller param "bootstrap" manually within
> the callback method appBootstrap() of my testclasses.
>
> public function setUp()
> {
>        <snip>...
> }
>
> public function appBootstrap()
> {
>        $this->application->bootstrap();
>
>        // set bootstrap param
>        $bootstrap = $this->application->getBootstrap();
>        $front = $bootstrap->getResource('FrontController');
>        $front->setParam('bootstrap', $bootstrap);
> }
>
>
Sweet! That works. Thank you very much.

btw maybe this deserves to be mentioned in the official docs.

-- 
David Mintz
http://davidmintz.org/

The subtle source is clear and bright
The tributary streams flow through the darkness

Reply via email to