简体   繁体   中英

PHPUnit test failing on plugin

my phpunit test fails with this error:

C:\workspace\internal_jets3\tests>phpunit --verbose
PHPUnit 3.5.7 by Sebastian Bergmann.


Fatal error: Call to a member function getOptions() on a non-object in C:\worksp
ace\internal_jets3\library\My\Controller\Plugin\ModuleLayoutLoader.php on line 7

Extract from plugin:

class My_Controller_Plugin_ModuleLayoutLoader extends Zend_Controller_Plugin_Abstract
{
    public function preDispatch(Zend_Controller_Request_Abstract $request)
    {
        $config = Zend_Controller_Front::getInstance()->getParam('bootstrap')->getOptions();

Any help on how to include plugins in testing will be helpful. Thanks!

Edit @Gordon It's not really that obvious to me. Doing a var_dump of:

var_dump(Zend_Controller_Front::getInstance()->getParam('bootstrap'));
die();

gives me:

object(Bootstrap)[3]
      protected '_appNamespace' => boolean false
      protected '_resourceLoader' => null
      protected '_application' => 

which says 'object' to me; and halfway down the dump is:

  protected '_options' => 

So this confuses me - I'm not familiar how to correctly phpunit test this object.

to set up PHPUnit in Zend environment, you have to fire your Zend bootstrap inside your phpunit bootstrap. After this, you still have a bootstrap object in your application. And your errormessage said that Zend_Controller_Front::getInstance()->getParam('bootstrap') is NULL. Are you sure, that you've debugged at the right place?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM