mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-10 03:29:25 +03:00
Merge pull request #1007 from bgarel/use-or-between-path-patterns
Change the behavior of path_patterns filter to use OR instead of AND
This commit is contained in:
commit
e8f44b2a04
@ -38,11 +38,11 @@ final class FilteredRouteCollectionBuilder
|
|||||||
private function match(Route $route): bool
|
private function match(Route $route): bool
|
||||||
{
|
{
|
||||||
foreach ($this->pathPatterns as $pathPattern) {
|
foreach ($this->pathPatterns as $pathPattern) {
|
||||||
if (!preg_match('{'.$pathPattern.'}', $route->getPath())) {
|
if (preg_match('{'.$pathPattern.'}', $route->getPath())) {
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
43
Tests/Routing/FilteredRouteCollectionBuilderTest.php
Normal file
43
Tests/Routing/FilteredRouteCollectionBuilderTest.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This file is part of the NelmioApiDocBundle package.
|
||||||
|
*
|
||||||
|
* (c) Nelmio
|
||||||
|
*
|
||||||
|
* For the full copyright and license information, please view the LICENSE
|
||||||
|
* file that was distributed with this source code.
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace Nelmio\ApiDocBundle\Tests\Routing;
|
||||||
|
|
||||||
|
use Nelmio\ApiDocBundle\Routing\FilteredRouteCollectionBuilder;
|
||||||
|
use Symfony\Component\Routing\Route;
|
||||||
|
use Symfony\Component\Routing\RouteCollection;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests for FilteredRouteCollectionBuilder class
|
||||||
|
*/
|
||||||
|
class FilteredRouteCollectionBuilderTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testFilter()
|
||||||
|
{
|
||||||
|
$pathPattern = [
|
||||||
|
'^/api/foo',
|
||||||
|
'^/api/bar',
|
||||||
|
];
|
||||||
|
|
||||||
|
$routes = new RouteCollection();
|
||||||
|
$routes->add('r1', new Route('/api/bar/action1'));
|
||||||
|
$routes->add('r2', new Route('/api/foo/action1'));
|
||||||
|
$routes->add('r3', new Route('/api/foo/action2'));
|
||||||
|
$routes->add('r4', new Route('/api/demo'));
|
||||||
|
$routes->add('r5', new Route('/_profiler/test/test'));
|
||||||
|
|
||||||
|
$routeBuilder = new FilteredRouteCollectionBuilder($pathPattern);
|
||||||
|
$filteredRoutes = $routeBuilder->filter($routes);
|
||||||
|
|
||||||
|
$this->assertCount(3, $filteredRoutes);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user