ZF-11589: PHP Fatal Error in Zend_Controller_Broker_PluginTest

Issue Type: Unit Tests: Problem Created: 2011-07-21T22:48:20.000+0000 Last Updated: 2011-07-28T21:58:08.000+0000 Status: Resolved Fix version(s): - 1.11.10 (04/Aug/11)

Reporter: Adam Lundrigan (adamlundrigan) Assignee: Mickael Perraud (mikaelkael) Tags: - Zend_Controller

Related issues: Attachments:


When running the Zend_Controller_Plugin test suite (./ Controller_Plugin) I get the following error:

<pre class="highlight">
Starting test 'Zend_Controller_Plugin_BrokerTest::testBrokerCatchesExceptions'.
PHP Fatal error:  Call to a member function setDispatched() on a non-object in /usr/local/apache2/htdocs/lib/zfdev/trunk/library/Zend/Controller/Plugin/Broker.php on line 316


Posted by Adam Lundrigan (adamlundrigan) on 2011-07-21T23:01:53.000+0000

In unit test Zend_Controller_Plugin_BrokerTest::testBrokerCatchesExceptions, the broker instance is only given the request object as a parameter to the hook methods (in this case, preDispatch), and not injected via setRequest. This causes Zend_Controller_Plugin_Broker::preDispatch to throw a PHP fatal error because it calls $this->getRequest()->setDispatched(false):

<pre class="highlight">
public function preDispatch(Zend_Controller_Request_Abstract $request)
    foreach ($this->_plugins as $plugin) {
        try {
        } catch (Exception $e) {
            if (Zend_Controller_Front::getInstance()->throwExceptions()) {
                throw new Zend_Controller_Exception($e->getMessage() . $e->getTraceAsString(), $e->getCode(), $e);
            } else {
                // skip rendering of normal dispatch give the error handler a try
                $this->getRequest()->setDispatched(false);     // <---- ERROR IS TRIGGERED HERE

and getRequest() returns null as setRequest wasn't given a request instance.

As I see it, there are two ways to fix this: 1. Fix the unit test: Inject $request via setRequest

<pre class="highlight">
Index: tests/Zend/Controller/Plugin/BrokerTest.php
--- tests/Zend/Controller/Plugin/BrokerTest.php (revision 24251)
+++ tests/Zend/Controller/Plugin/BrokerTest.php (working copy)
@@ -186,6 +186,7 @@
         $response = new Zend_Controller_Response_Cli();
         $broker   = new Zend_Controller_Plugin_Broker();
+        $broker->setRequest($request);
         $broker->registerPlugin(new Zend_Controller_Plugin_BrokerTest_ExceptionTestPlugin());
         try {
  1. Change Zend_Controller_Plugin_Broker::preDispatch to call setDispatched directly it's argument $request:
<pre class="highlight">
Index: library/Zend/Controller/Plugin/Broker.php
--- library/Zend/Controller/Plugin/Broker.php   (revision 24251)
+++ library/Zend/Controller/Plugin/Broker.php   (working copy)
@@ -313,7 +313,7 @@
                 } else {
                                        // skip rendering of normal dispatch give the error handler a try
-                                       $this->getRequest()->setDispatched(false);
+                                       $request->setDispatched(false);

(Yes, that line and comment above it are tabbed and not space-indented. That should be fixed)

Thoughts? Both options fix this specific issue, but which fix is best overall (ie: is this an implementation issue with the broker or a just a test construction issue?)

Posted by Mickael Perraud (mikaelkael) on 2011-07-28T21:58:08.000+0000

Fixed by r24295

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.