0

I have this part of code in my indexController:

public function init()
{
  $this->_translate = $this->getInvokeArg('bootstrap')->getResource('translate');
}

This works all fine and in PRD i don't get any errors

But when i am running my unit tests it generates the following error:

Fatal error: Call to a member function getResource() on a non-object in K:\stage 5\application\controllers\IndexController.php on line 9

This is my testcode:

class IndexControllerTest extends ControllerTestCase
{
    public function testCanDisplayOurHomepage()
    {
        //Go to the main page of the webapplication
        $this->dispatch('/');

        //check if we don't end up in an error controller
        $this->assertNotController('error');
        $this->assertNotAction('error');

        //Ok no error lets check if we are on the home page
        $this->assertModule('default');
        $this->assertController('index');
        $this->assertAction('index');
        $this->assertResponseCode(200);


    }
}
1
  • Please let me know the class for getResource and class of $this->getInvokeArg('bootstrap'). Commented Jan 23, 2011 at 17:50

2 Answers 2

3

This was not working in my unit tests because I was only calling the application bootstrap and not then calling run.

/** Zend_Application */
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
);
$application->bootstrap();

To fix the problem I added this to the phpunit boostrap

$appBootstrap = $application->getBootstrap();
$front   = $appBootstrap->getResource('FrontController');
$front->setParam('bootstrap', $appBootstrap);

and now $bootstrap = $this->getInvokeArg('bootstrap'); works fine in PHPUnit.

Sign up to request clarification or add additional context in comments.

Comments

1

Have you tried calling the bootstrap for translate in your Bootstrap call?

$this->bootstrap("translate")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.