Skip to content
Permalink
Browse files

Fix router reload regression in integration testing.

  • Loading branch information...
dereuromark committed Oct 31, 2018
1 parent ca28b41 commit 0cc4139047526bdb52f9d366704d9bb704e39503
Showing with 22 additions and 3 deletions.
  1. +9 −1 src/TestSuite/IntegrationTestCase.php
  2. +13 −2 src/TestSuite/MiddlewareDispatcher.php
@@ -172,6 +172,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.
*
@@ -207,6 +214,7 @@ public function tearDown()
$this->_csrfToken = false;
$this->_retainFlashMessages = false;
$this->_useHttpServer = false;
$this->_disableRouterReload = true;
}
/**
@@ -518,7 +526,7 @@ protected function _sendRequest($url, $method, $data = [])
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);
@@ -54,6 +54,13 @@ class MiddlewareDispatcher
*/
protected $_constructorArgs;
/**
* Allow router reloading to be disabled.
*
* @var bool
*/
protected $_disableRouterReload = false;
/**
* The application that is being dispatched.
*
@@ -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 @@ protected function resolveRoute(array $url)
}
$out = Router::url($url);
Router::reload();
if (!$this->_disableRouterReload) {
Router::reload();
}
return $out;
}

0 comments on commit 0cc4139

Please sign in to comment.
You can’t perform that action at this time.