diff --git a/tests/Bootstrap.php b/tests/Bootstrap.php index f2f9e8a..ebd6f21 100644 --- a/tests/Bootstrap.php +++ b/tests/Bootstrap.php @@ -16,6 +16,7 @@ * and is licensed under the MIT license. */ +use Zend\Mvc\Application; use ZfcRbacTest\Util\ServiceManagerFactory; ini_set('error_reporting', E_ALL); @@ -39,9 +40,13 @@ $loader->add('ZfcRbacTest\\', __DIR__); +$r = new \ReflectionClass(Application::class); +$requiredParams = $r->getConstructor()->getNumberOfRequiredParameters(); +$version = $requiredParams == 1 ? 3 : 2; + $configFiles = [ - __DIR__ . '/TestConfiguration.php', - __DIR__ . '/TestConfiguration.php.dist' + sprintf(__DIR__ . '/TestConfigurationV%s.php', $version), + sprintf(__DIR__ . '/TestConfigurationV%s.php.dist', $version), ]; foreach ($configFiles as $configFile) { diff --git a/tests/TestConfiguration.php.dist b/tests/TestConfigurationV2.php.dist similarity index 100% rename from tests/TestConfiguration.php.dist rename to tests/TestConfigurationV2.php.dist diff --git a/tests/TestConfigurationV3.php.dist b/tests/TestConfigurationV3.php.dist new file mode 100644 index 0000000..6217535 --- /dev/null +++ b/tests/TestConfigurationV3.php.dist @@ -0,0 +1,33 @@ + [ + 'Zend\Router', + 'ZfcRbac', + 'DoctrineModule', + 'DoctrineORMModule', + ], + 'module_listener_options' => [ + 'config_glob_paths' => [ + __DIR__ . '/testing.config.php', + ], + 'module_paths' => [ + ], + ], +]; diff --git a/tests/ZfcRbacTest/Guard/RouteGuardTest.php b/tests/ZfcRbacTest/Guard/RouteGuardTest.php index 6371d0d..c979247 100644 --- a/tests/ZfcRbacTest/Guard/RouteGuardTest.php +++ b/tests/ZfcRbacTest/Guard/RouteGuardTest.php @@ -19,7 +19,8 @@ namespace ZfcRbacTest\Guard; use Zend\Mvc\MvcEvent; -use Zend\Mvc\Router\RouteMatch; +use Zend\Mvc\Router\RouteMatch as V2RouteMatch; +use Zend\Router\RouteMatch; use ZfcRbac\Guard\ControllerGuard; use ZfcRbac\Guard\GuardInterface; use ZfcRbac\Guard\RouteGuard; diff --git a/tests/ZfcRbacTest/Guard/RoutePermissionsGuardTest.php b/tests/ZfcRbacTest/Guard/RoutePermissionsGuardTest.php index a952ede..45f837b 100644 --- a/tests/ZfcRbacTest/Guard/RoutePermissionsGuardTest.php +++ b/tests/ZfcRbacTest/Guard/RoutePermissionsGuardTest.php @@ -18,7 +18,8 @@ namespace ZfcRbacTest\Guard; use Zend\Mvc\MvcEvent; -use Zend\Mvc\Router\RouteMatch; +use Zend\Mvc\Router\RouteMatch as V2RouteMatch; +use Zend\Router\RouteMatch; use ZfcRbac\Guard\ControllerGuard; use ZfcRbac\Guard\GuardInterface; use ZfcRbac\Guard\RouteGuard; diff --git a/tests/ZfcRbacTest/View/Strategy/RedirectStrategyTest.php b/tests/ZfcRbacTest/View/Strategy/RedirectStrategyTest.php index d3c2ef0..c84919e 100644 --- a/tests/ZfcRbacTest/View/Strategy/RedirectStrategyTest.php +++ b/tests/ZfcRbacTest/View/Strategy/RedirectStrategyTest.php @@ -22,7 +22,8 @@ use Zend\Http\Request as HttpRequest; use Zend\Http\Response as HttpResponse; use Zend\Mvc\MvcEvent; -use Zend\Mvc\Router\Http\TreeRouteStack; +use Zend\Mvc\Router\Http\TreeRouteStack as V2TreeRouteStack; +use Zend\Router\Http\TreeRouteStack; use ZfcRbac\Exception\UnauthorizedException; use ZfcRbac\Options\RedirectStrategyOptions; use ZfcRbac\View\Strategy\RedirectStrategy; @@ -58,9 +59,9 @@ public function testCanRedirectWhenDisconnected() { $response = new HttpResponse(); - $router = new TreeRouteStack(); + $router = $this->createTreeRouteStack(); $router->addRoute('login', [ - 'type' => 'Zend\Mvc\Router\Http\Literal', + 'type' => 'literal', 'options' => [ 'route' => '/login' ] @@ -92,9 +93,9 @@ public function testCanRedirectWhenConnected() { $response = new HttpResponse(); - $router = new TreeRouteStack(); + $router = $this->createTreeRouteStack(); $router->addRoute('home', [ - 'type' => 'Zend\Mvc\Router\Http\Literal', + 'type' => 'literal', 'options' => [ 'route' => '/home' ] @@ -126,9 +127,9 @@ public function testWontRedirectWhenConnectedAndOptionDisabled() { $response = new HttpResponse(); - $router = new TreeRouteStack(); + $router = $this->createTreeRouteStack(); $router->addRoute('home', [ - 'type' => 'Zend\Mvc\Router\Http\Literal', + 'type' => 'literal', 'options' => [ 'route' => '/home' ] @@ -160,9 +161,9 @@ public function testCanAppendPreviousUri() $request = new HttpRequest(); $request->setUri('http://example.com'); - $router = new TreeRouteStack(); + $router = $this->createTreeRouteStack(); $router->addRoute('login', [ - 'type' => 'Zend\Mvc\Router\Http\Literal', + 'type' => 'literal', 'options' => [ 'route' => '/login' ] @@ -194,4 +195,10 @@ public function testCanAppendPreviousUri() $mvcEvent->getResponse()->getHeaders()->get('Location')->getFieldValue() ); } + + public function createTreeRouteStack($routePluginManager = null) + { + $class = class_exists(V2TreeRouteStack::class) ? V2TreeRouteStack::class : TreeRouteStack::class; + return new $class($routePluginManager); + } }