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

Commit

Permalink
Merge pull request #349 from webimpress/hotfix/tests
Browse files Browse the repository at this point in the history
Tests fixes - pass on ZF2 and ZF3
  • Loading branch information
bakura10 committed Oct 14, 2016
2 parents b47e9a2 + 5d006cb commit 1f2b0c6
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 13 deletions.
9 changes: 7 additions & 2 deletions tests/Bootstrap.php
Expand Up @@ -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);
Expand 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) {
Expand Down
File renamed without changes.
33 changes: 33 additions & 0 deletions tests/TestConfigurationV3.php.dist
@@ -0,0 +1,33 @@
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license.
*/

return [
'modules' => [
'Zend\Router',
'ZfcRbac',
'DoctrineModule',
'DoctrineORMModule',
],
'module_listener_options' => [
'config_glob_paths' => [
__DIR__ . '/testing.config.php',
],
'module_paths' => [
],
],
];
3 changes: 2 additions & 1 deletion tests/ZfcRbacTest/Guard/RouteGuardTest.php
Expand Up @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion tests/ZfcRbacTest/Guard/RoutePermissionsGuardTest.php
Expand Up @@ -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;
Expand Down
25 changes: 16 additions & 9 deletions tests/ZfcRbacTest/View/Strategy/RedirectStrategyTest.php
Expand Up @@ -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;
Expand Down Expand Up @@ -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'
]
Expand Down Expand Up @@ -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'
]
Expand Down Expand Up @@ -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'
]
Expand Down Expand Up @@ -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'
]
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 1f2b0c6

Please sign in to comment.