Skip to content
This repository was archived by the owner on Jul 3, 2020. It is now read-only.

Commit 1f2b0c6

Browse files
authored
Merge pull request #349 from webimpress/hotfix/tests
Tests fixes - pass on ZF2 and ZF3
2 parents b47e9a2 + 5d006cb commit 1f2b0c6

File tree

6 files changed

+60
-13
lines changed

6 files changed

+60
-13
lines changed

tests/Bootstrap.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
* and is licensed under the MIT license.
1717
*/
1818

19+
use Zend\Mvc\Application;
1920
use ZfcRbacTest\Util\ServiceManagerFactory;
2021

2122
ini_set('error_reporting', E_ALL);
@@ -39,9 +40,13 @@
3940

4041
$loader->add('ZfcRbacTest\\', __DIR__);
4142

43+
$r = new \ReflectionClass(Application::class);
44+
$requiredParams = $r->getConstructor()->getNumberOfRequiredParameters();
45+
$version = $requiredParams == 1 ? 3 : 2;
46+
4247
$configFiles = [
43-
__DIR__ . '/TestConfiguration.php',
44-
__DIR__ . '/TestConfiguration.php.dist'
48+
sprintf(__DIR__ . '/TestConfigurationV%s.php', $version),
49+
sprintf(__DIR__ . '/TestConfigurationV%s.php.dist', $version),
4550
];
4651

4752
foreach ($configFiles as $configFile) {

tests/TestConfigurationV3.php.dist

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/*
3+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14+
*
15+
* This software consists of voluntary contributions made by many individuals
16+
* and is licensed under the MIT license.
17+
*/
18+
19+
return [
20+
'modules' => [
21+
'Zend\Router',
22+
'ZfcRbac',
23+
'DoctrineModule',
24+
'DoctrineORMModule',
25+
],
26+
'module_listener_options' => [
27+
'config_glob_paths' => [
28+
__DIR__ . '/testing.config.php',
29+
],
30+
'module_paths' => [
31+
],
32+
],
33+
];

tests/ZfcRbacTest/Guard/RouteGuardTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
namespace ZfcRbacTest\Guard;
2020

2121
use Zend\Mvc\MvcEvent;
22-
use Zend\Mvc\Router\RouteMatch;
22+
use Zend\Mvc\Router\RouteMatch as V2RouteMatch;
23+
use Zend\Router\RouteMatch;
2324
use ZfcRbac\Guard\ControllerGuard;
2425
use ZfcRbac\Guard\GuardInterface;
2526
use ZfcRbac\Guard\RouteGuard;

tests/ZfcRbacTest/Guard/RoutePermissionsGuardTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
namespace ZfcRbacTest\Guard;
1919

2020
use Zend\Mvc\MvcEvent;
21-
use Zend\Mvc\Router\RouteMatch;
21+
use Zend\Mvc\Router\RouteMatch as V2RouteMatch;
22+
use Zend\Router\RouteMatch;
2223
use ZfcRbac\Guard\ControllerGuard;
2324
use ZfcRbac\Guard\GuardInterface;
2425
use ZfcRbac\Guard\RouteGuard;

tests/ZfcRbacTest/View/Strategy/RedirectStrategyTest.php

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
use Zend\Http\Request as HttpRequest;
2323
use Zend\Http\Response as HttpResponse;
2424
use Zend\Mvc\MvcEvent;
25-
use Zend\Mvc\Router\Http\TreeRouteStack;
25+
use Zend\Mvc\Router\Http\TreeRouteStack as V2TreeRouteStack;
26+
use Zend\Router\Http\TreeRouteStack;
2627
use ZfcRbac\Exception\UnauthorizedException;
2728
use ZfcRbac\Options\RedirectStrategyOptions;
2829
use ZfcRbac\View\Strategy\RedirectStrategy;
@@ -58,9 +59,9 @@ public function testCanRedirectWhenDisconnected()
5859
{
5960
$response = new HttpResponse();
6061

61-
$router = new TreeRouteStack();
62+
$router = $this->createTreeRouteStack();
6263
$router->addRoute('login', [
63-
'type' => 'Zend\Mvc\Router\Http\Literal',
64+
'type' => 'literal',
6465
'options' => [
6566
'route' => '/login'
6667
]
@@ -92,9 +93,9 @@ public function testCanRedirectWhenConnected()
9293
{
9394
$response = new HttpResponse();
9495

95-
$router = new TreeRouteStack();
96+
$router = $this->createTreeRouteStack();
9697
$router->addRoute('home', [
97-
'type' => 'Zend\Mvc\Router\Http\Literal',
98+
'type' => 'literal',
9899
'options' => [
99100
'route' => '/home'
100101
]
@@ -126,9 +127,9 @@ public function testWontRedirectWhenConnectedAndOptionDisabled()
126127
{
127128
$response = new HttpResponse();
128129

129-
$router = new TreeRouteStack();
130+
$router = $this->createTreeRouteStack();
130131
$router->addRoute('home', [
131-
'type' => 'Zend\Mvc\Router\Http\Literal',
132+
'type' => 'literal',
132133
'options' => [
133134
'route' => '/home'
134135
]
@@ -160,9 +161,9 @@ public function testCanAppendPreviousUri()
160161
$request = new HttpRequest();
161162
$request->setUri('http://example.com');
162163

163-
$router = new TreeRouteStack();
164+
$router = $this->createTreeRouteStack();
164165
$router->addRoute('login', [
165-
'type' => 'Zend\Mvc\Router\Http\Literal',
166+
'type' => 'literal',
166167
'options' => [
167168
'route' => '/login'
168169
]
@@ -194,4 +195,10 @@ public function testCanAppendPreviousUri()
194195
$mvcEvent->getResponse()->getHeaders()->get('Location')->getFieldValue()
195196
);
196197
}
198+
199+
public function createTreeRouteStack($routePluginManager = null)
200+
{
201+
$class = class_exists(V2TreeRouteStack::class) ? V2TreeRouteStack::class : TreeRouteStack::class;
202+
return new $class($routePluginManager);
203+
}
197204
}

0 commit comments

Comments
 (0)