Browse Source

Fix router reload regression in integration testing.

mscherer 7 years ago
parent
commit
0cc4139047
2 changed files with 22 additions and 3 deletions
  1. 9 1
      src/TestSuite/IntegrationTestCase.php
  2. 13 2
      src/TestSuite/MiddlewareDispatcher.php

+ 9 - 1
src/TestSuite/IntegrationTestCase.php

@@ -173,6 +173,13 @@ abstract class IntegrationTestCase extends TestCase
     protected $_cookieEncryptionKey;
 
     /**
+     * Allow router reloading to be disabled.
+     * 
+     * @var bool
+     */
+    protected $_disableRouterReload = false;
+
+    /**
      * Auto-detect if the HTTP middleware stack should be used.
      *
      * @return void
@@ -207,6 +214,7 @@ abstract class IntegrationTestCase extends TestCase
         $this->_csrfToken = false;
         $this->_retainFlashMessages = false;
         $this->_useHttpServer = false;
+        $this->_disableRouterReload = true;
     }
 
     /**
@@ -518,7 +526,7 @@ abstract class IntegrationTestCase extends TestCase
     protected function _makeDispatcher()
     {
         if ($this->_useHttpServer) {
-            return new MiddlewareDispatcher($this, $this->_appClass, $this->_appArgs);
+            return new MiddlewareDispatcher($this, $this->_appClass, $this->_appArgs, $this->_disableRouterReload);
         }
 
         return new LegacyRequestDispatcher($this);

+ 13 - 2
src/TestSuite/MiddlewareDispatcher.php

@@ -55,6 +55,13 @@ class MiddlewareDispatcher
     protected $_constructorArgs;
 
     /**
+     * Allow router reloading to be disabled.
+     *
+     * @var bool
+     */
+    protected $_disableRouterReload = false;
+
+    /**
      * The application that is being dispatched.
      *
      * @var \Cake\Core\HttpApplicationInterface
@@ -68,13 +75,15 @@ class MiddlewareDispatcher
      * @param string|null $class The application class name. Defaults to App\Application.
      * @param array|null $constructorArgs The constructor arguments for your application class.
      *   Defaults to `['./config']`
+     * @param bool $disableRouterReload Disable Router::reload() call.
      * @throws \LogicException If it cannot load class for use in integration testing.
      */
-    public function __construct($test, $class = null, $constructorArgs = null)
+    public function __construct($test, $class = null, $constructorArgs = null, $disableRouterReload = false)
     {
         $this->_test = $test;
         $this->_class = $class ?: Configure::read('App.namespace') . '\Application';
         $this->_constructorArgs = $constructorArgs ?: [CONFIG];
+        $this->_disableRouterReload = $disableRouterReload;
 
         try {
             $reflect = new ReflectionClass($this->_class);
@@ -126,7 +135,9 @@ class MiddlewareDispatcher
         }
 
         $out = Router::url($url);
-        Router::reload();
+        if (!$this->_disableRouterReload) {
+            Router::reload();
+        }
 
         return $out;
     }