Initial Commit
This commit is contained in:
33
vendor/symfony/routing/Tests/Loader/AbstractAnnotationLoaderTest.php
vendored
Normal file
33
vendor/symfony/routing/Tests/Loader/AbstractAnnotationLoaderTest.php
vendored
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
abstract class AbstractAnnotationLoaderTest extends TestCase
|
||||
{
|
||||
public function getReader()
|
||||
{
|
||||
return $this->getMockBuilder('Doctrine\Common\Annotations\Reader')
|
||||
->disableOriginalConstructor()
|
||||
->getMock()
|
||||
;
|
||||
}
|
||||
|
||||
public function getClassLoader($reader)
|
||||
{
|
||||
return $this->getMockBuilder('Symfony\Component\Routing\Loader\AnnotationClassLoader')
|
||||
->setConstructorArgs(array($reader))
|
||||
->getMockForAbstractClass()
|
||||
;
|
||||
}
|
||||
}
|
||||
270
vendor/symfony/routing/Tests/Loader/AnnotationClassLoaderTest.php
vendored
Normal file
270
vendor/symfony/routing/Tests/Loader/AnnotationClassLoaderTest.php
vendored
Normal file
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Doctrine\Common\Annotations\AnnotationRegistry;
|
||||
use Symfony\Component\Routing\Annotation\Route as RouteAnnotation;
|
||||
use Symfony\Component\Routing\Loader\AnnotationClassLoader;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\AbstractClassController;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\ActionPathController;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\DefaultValueController;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\ExplicitLocalizedActionPathController;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\InvokableController;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\InvokableLocalizedController;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\LocalizedActionPathController;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\LocalizedMethodActionControllers;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\LocalizedPrefixLocalizedActionController;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\LocalizedPrefixMissingLocaleActionController;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\LocalizedPrefixMissingRouteLocaleActionController;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\LocalizedPrefixWithRouteWithoutLocale;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\MethodActionControllers;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\MissingRouteNameController;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\NothingButNameController;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\PrefixedActionLocalizedRouteController;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\PrefixedActionPathController;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\AnnotationFixtures\RouteWithPrefixController;
|
||||
|
||||
class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
||||
{
|
||||
/**
|
||||
* @var AnnotationClassLoader
|
||||
*/
|
||||
private $loader;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$reader = new AnnotationReader();
|
||||
$this->loader = new class($reader) extends AnnotationClassLoader {
|
||||
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot)
|
||||
{
|
||||
}
|
||||
};
|
||||
AnnotationRegistry::registerLoader('class_exists');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideTestSupportsChecksResource
|
||||
*/
|
||||
public function testSupportsChecksResource($resource, $expectedSupports)
|
||||
{
|
||||
$this->assertSame($expectedSupports, $this->loader->supports($resource), '->supports() returns true if the resource is loadable');
|
||||
}
|
||||
|
||||
public function provideTestSupportsChecksResource()
|
||||
{
|
||||
return array(
|
||||
array('class', true),
|
||||
array('\fully\qualified\class\name', true),
|
||||
array('namespaced\class\without\leading\slash', true),
|
||||
array('ÿClassWithLegalSpecialCharacters', true),
|
||||
array('5', false),
|
||||
array('foo.foo', false),
|
||||
array(null, false),
|
||||
);
|
||||
}
|
||||
|
||||
public function testSupportsChecksTypeIfSpecified()
|
||||
{
|
||||
$this->assertTrue($this->loader->supports('class', 'annotation'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($this->loader->supports('class', 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
|
||||
public function testSimplePathRoute()
|
||||
{
|
||||
$routes = $this->loader->load(ActionPathController::class);
|
||||
$this->assertCount(1, $routes);
|
||||
$this->assertEquals('/path', $routes->get('action')->getPath());
|
||||
}
|
||||
|
||||
public function testInvokableControllerLoader()
|
||||
{
|
||||
$routes = $this->loader->load(InvokableController::class);
|
||||
$this->assertCount(1, $routes);
|
||||
$this->assertEquals('/here', $routes->get('lol')->getPath());
|
||||
}
|
||||
|
||||
public function testInvokableLocalizedControllerLoading()
|
||||
{
|
||||
$routes = $this->loader->load(InvokableLocalizedController::class);
|
||||
$this->assertCount(2, $routes);
|
||||
$this->assertEquals('/here', $routes->get('action.en')->getPath());
|
||||
$this->assertEquals('/hier', $routes->get('action.nl')->getPath());
|
||||
}
|
||||
|
||||
public function testLocalizedPathRoutes()
|
||||
{
|
||||
$routes = $this->loader->load(LocalizedActionPathController::class);
|
||||
$this->assertCount(2, $routes);
|
||||
$this->assertEquals('/path', $routes->get('action.en')->getPath());
|
||||
$this->assertEquals('/pad', $routes->get('action.nl')->getPath());
|
||||
}
|
||||
|
||||
public function testLocalizedPathRoutesWithExplicitPathPropety()
|
||||
{
|
||||
$routes = $this->loader->load(ExplicitLocalizedActionPathController::class);
|
||||
$this->assertCount(2, $routes);
|
||||
$this->assertEquals('/path', $routes->get('action.en')->getPath());
|
||||
$this->assertEquals('/pad', $routes->get('action.nl')->getPath());
|
||||
}
|
||||
|
||||
public function testDefaultValuesForMethods()
|
||||
{
|
||||
$routes = $this->loader->load(DefaultValueController::class);
|
||||
$this->assertCount(1, $routes);
|
||||
$this->assertEquals('/{default}/path', $routes->get('action')->getPath());
|
||||
$this->assertEquals('value', $routes->get('action')->getDefault('default'));
|
||||
}
|
||||
|
||||
public function testMethodActionControllers()
|
||||
{
|
||||
$routes = $this->loader->load(MethodActionControllers::class);
|
||||
$this->assertCount(2, $routes);
|
||||
$this->assertEquals('/the/path', $routes->get('put')->getPath());
|
||||
$this->assertEquals('/the/path', $routes->get('post')->getPath());
|
||||
}
|
||||
|
||||
public function testLocalizedMethodActionControllers()
|
||||
{
|
||||
$routes = $this->loader->load(LocalizedMethodActionControllers::class);
|
||||
$this->assertCount(4, $routes);
|
||||
$this->assertEquals('/the/path', $routes->get('put.en')->getPath());
|
||||
$this->assertEquals('/the/path', $routes->get('post.en')->getPath());
|
||||
}
|
||||
|
||||
public function testRouteWithPathWithPrefix()
|
||||
{
|
||||
$routes = $this->loader->load(PrefixedActionPathController::class);
|
||||
$this->assertCount(1, $routes);
|
||||
$route = $routes->get('action');
|
||||
$this->assertEquals('/prefix/path', $route->getPath());
|
||||
$this->assertEquals('lol=fun', $route->getCondition());
|
||||
$this->assertEquals('frankdejonge.nl', $route->getHost());
|
||||
}
|
||||
|
||||
public function testLocalizedRouteWithPathWithPrefix()
|
||||
{
|
||||
$routes = $this->loader->load(PrefixedActionLocalizedRouteController::class);
|
||||
$this->assertCount(2, $routes);
|
||||
$this->assertEquals('/prefix/path', $routes->get('action.en')->getPath());
|
||||
$this->assertEquals('/prefix/pad', $routes->get('action.nl')->getPath());
|
||||
}
|
||||
|
||||
public function testLocalizedPrefixLocalizedRoute()
|
||||
{
|
||||
$routes = $this->loader->load(LocalizedPrefixLocalizedActionController::class);
|
||||
$this->assertCount(2, $routes);
|
||||
$this->assertEquals('/nl/actie', $routes->get('action.nl')->getPath());
|
||||
$this->assertEquals('/en/action', $routes->get('action.en')->getPath());
|
||||
}
|
||||
|
||||
public function testInvokableClassMultipleRouteLoad()
|
||||
{
|
||||
$classRouteData1 = array(
|
||||
'name' => 'route1',
|
||||
'path' => '/1',
|
||||
'schemes' => array('https'),
|
||||
'methods' => array('GET'),
|
||||
);
|
||||
|
||||
$classRouteData2 = array(
|
||||
'name' => 'route2',
|
||||
'path' => '/2',
|
||||
'schemes' => array('https'),
|
||||
'methods' => array('GET'),
|
||||
);
|
||||
|
||||
$reader = $this->getReader();
|
||||
$reader
|
||||
->expects($this->exactly(1))
|
||||
->method('getClassAnnotations')
|
||||
->will($this->returnValue(array(new RouteAnnotation($classRouteData1), new RouteAnnotation($classRouteData2))))
|
||||
;
|
||||
$reader
|
||||
->expects($this->once())
|
||||
->method('getMethodAnnotations')
|
||||
->will($this->returnValue(array()))
|
||||
;
|
||||
$loader = new class($reader) extends AnnotationClassLoader {
|
||||
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
$routeCollection = $loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass');
|
||||
$route = $routeCollection->get($classRouteData1['name']);
|
||||
|
||||
$this->assertSame($classRouteData1['path'], $route->getPath(), '->load preserves class route path');
|
||||
$this->assertEquals($classRouteData1['schemes'], $route->getSchemes(), '->load preserves class route schemes');
|
||||
$this->assertEquals($classRouteData1['methods'], $route->getMethods(), '->load preserves class route methods');
|
||||
|
||||
$route = $routeCollection->get($classRouteData2['name']);
|
||||
|
||||
$this->assertSame($classRouteData2['path'], $route->getPath(), '->load preserves class route path');
|
||||
$this->assertEquals($classRouteData2['schemes'], $route->getSchemes(), '->load preserves class route schemes');
|
||||
$this->assertEquals($classRouteData2['methods'], $route->getMethods(), '->load preserves class route methods');
|
||||
}
|
||||
|
||||
public function testMissingPrefixLocale()
|
||||
{
|
||||
$this->expectException(\LogicException::class);
|
||||
$this->loader->load(LocalizedPrefixMissingLocaleActionController::class);
|
||||
}
|
||||
|
||||
public function testMissingRouteLocale()
|
||||
{
|
||||
$this->expectException(\LogicException::class);
|
||||
$this->loader->load(LocalizedPrefixMissingRouteLocaleActionController::class);
|
||||
}
|
||||
|
||||
public function testRouteWithoutName()
|
||||
{
|
||||
$routes = $this->loader->load(MissingRouteNameController::class)->all();
|
||||
$this->assertCount(1, $routes);
|
||||
$this->assertEquals('/path', reset($routes)->getPath());
|
||||
}
|
||||
|
||||
public function testNothingButName()
|
||||
{
|
||||
$routes = $this->loader->load(NothingButNameController::class)->all();
|
||||
$this->assertCount(1, $routes);
|
||||
$this->assertEquals('/', reset($routes)->getPath());
|
||||
}
|
||||
|
||||
public function testNonExistingClass()
|
||||
{
|
||||
$this->expectException(\LogicException::class);
|
||||
$this->loader->load('ClassThatDoesNotExist');
|
||||
}
|
||||
|
||||
public function testLoadingAbstractClass()
|
||||
{
|
||||
$this->expectException(\LogicException::class);
|
||||
$this->loader->load(AbstractClassController::class);
|
||||
}
|
||||
|
||||
public function testLocalizedPrefixWithoutRouteLocale()
|
||||
{
|
||||
$routes = $this->loader->load(LocalizedPrefixWithRouteWithoutLocale::class);
|
||||
$this->assertCount(2, $routes);
|
||||
$this->assertEquals('/en/suffix', $routes->get('action.en')->getPath());
|
||||
$this->assertEquals('/nl/suffix', $routes->get('action.nl')->getPath());
|
||||
}
|
||||
|
||||
public function testLoadingRouteWithPrefix()
|
||||
{
|
||||
$routes = $this->loader->load(RouteWithPrefixController::class);
|
||||
$this->assertCount(1, $routes);
|
||||
$this->assertEquals('/prefix/path', $routes->get('action')->getPath());
|
||||
}
|
||||
}
|
||||
109
vendor/symfony/routing/Tests/Loader/AnnotationDirectoryLoaderTest.php
vendored
Normal file
109
vendor/symfony/routing/Tests/Loader/AnnotationDirectoryLoaderTest.php
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
|
||||
|
||||
class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
|
||||
{
|
||||
protected $loader;
|
||||
protected $reader;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->reader = $this->getReader();
|
||||
$this->loader = new AnnotationDirectoryLoader(new FileLocator(), $this->getClassLoader($this->reader));
|
||||
}
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$this->reader->expects($this->exactly(3))->method('getClassAnnotation');
|
||||
|
||||
$this->reader
|
||||
->expects($this->any())
|
||||
->method('getMethodAnnotations')
|
||||
->will($this->returnValue(array()))
|
||||
;
|
||||
|
||||
$this->reader
|
||||
->expects($this->any())
|
||||
->method('getClassAnnotations')
|
||||
->will($this->returnValue(array()))
|
||||
;
|
||||
|
||||
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
|
||||
}
|
||||
|
||||
public function testLoadIgnoresHiddenDirectories()
|
||||
{
|
||||
$this->expectAnnotationsToBeReadFrom(array(
|
||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
|
||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass',
|
||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\FooClass',
|
||||
));
|
||||
|
||||
$this->reader
|
||||
->expects($this->any())
|
||||
->method('getMethodAnnotations')
|
||||
->will($this->returnValue(array()))
|
||||
;
|
||||
|
||||
$this->reader
|
||||
->expects($this->any())
|
||||
->method('getClassAnnotations')
|
||||
->will($this->returnValue(array()))
|
||||
;
|
||||
|
||||
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses');
|
||||
}
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$fixturesDir = __DIR__.'/../Fixtures';
|
||||
|
||||
$this->assertTrue($this->loader->supports($fixturesDir), '->supports() returns true if the resource is loadable');
|
||||
$this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
|
||||
|
||||
$this->assertTrue($this->loader->supports($fixturesDir, 'annotation'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($this->loader->supports($fixturesDir, 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
|
||||
public function testItSupportsAnyAnnotation()
|
||||
{
|
||||
$this->assertTrue($this->loader->supports(__DIR__.'/../Fixtures/even-with-not-existing-folder', 'annotation'));
|
||||
}
|
||||
|
||||
public function testLoadFileIfLocatedResourceIsFile()
|
||||
{
|
||||
$this->reader->expects($this->exactly(1))->method('getClassAnnotation');
|
||||
|
||||
$this->reader
|
||||
->expects($this->any())
|
||||
->method('getMethodAnnotations')
|
||||
->will($this->returnValue(array()))
|
||||
;
|
||||
|
||||
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php');
|
||||
}
|
||||
|
||||
private function expectAnnotationsToBeReadFrom(array $classes)
|
||||
{
|
||||
$this->reader->expects($this->exactly(\count($classes)))
|
||||
->method('getClassAnnotation')
|
||||
->with($this->callback(function (\ReflectionClass $class) use ($classes) {
|
||||
return \in_array($class->getName(), $classes);
|
||||
}));
|
||||
}
|
||||
}
|
||||
85
vendor/symfony/routing/Tests/Loader/AnnotationFileLoaderTest.php
vendored
Normal file
85
vendor/symfony/routing/Tests/Loader/AnnotationFileLoaderTest.php
vendored
Normal file
@@ -0,0 +1,85 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
|
||||
|
||||
class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
|
||||
{
|
||||
protected $loader;
|
||||
protected $reader;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->reader = $this->getReader();
|
||||
$this->loader = new AnnotationFileLoader(new FileLocator(), $this->getClassLoader($this->reader));
|
||||
}
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$this->reader->expects($this->once())->method('getClassAnnotation');
|
||||
|
||||
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php');
|
||||
}
|
||||
|
||||
public function testLoadTraitWithClassConstant()
|
||||
{
|
||||
$this->reader->expects($this->never())->method('getClassAnnotation');
|
||||
|
||||
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooTrait.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Did you forgot to add the "<?php" start tag at the beginning of the file?
|
||||
*/
|
||||
public function testLoadFileWithoutStartTag()
|
||||
{
|
||||
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/NoStartTagClass.php');
|
||||
}
|
||||
|
||||
public function testLoadVariadic()
|
||||
{
|
||||
$route = new Route(array('path' => '/path/to/{id}'));
|
||||
$this->reader->expects($this->once())->method('getClassAnnotation');
|
||||
$this->reader->expects($this->once())->method('getMethodAnnotations')
|
||||
->will($this->returnValue(array($route)));
|
||||
|
||||
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/VariadicClass.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 7.0
|
||||
*/
|
||||
public function testLoadAnonymousClass()
|
||||
{
|
||||
$this->reader->expects($this->never())->method('getClassAnnotation');
|
||||
$this->reader->expects($this->never())->method('getMethodAnnotations');
|
||||
|
||||
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/AnonymousClassInTrait.php');
|
||||
}
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$fixture = __DIR__.'/../Fixtures/annotated.php';
|
||||
|
||||
$this->assertTrue($this->loader->supports($fixture), '->supports() returns true if the resource is loadable');
|
||||
$this->assertFalse($this->loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
|
||||
|
||||
$this->assertTrue($this->loader->supports($fixture, 'annotation'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($this->loader->supports($fixture, 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
}
|
||||
49
vendor/symfony/routing/Tests/Loader/ClosureLoaderTest.php
vendored
Normal file
49
vendor/symfony/routing/Tests/Loader/ClosureLoaderTest.php
vendored
Normal file
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Routing\Loader\ClosureLoader;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
class ClosureLoaderTest extends TestCase
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new ClosureLoader();
|
||||
|
||||
$closure = function () {};
|
||||
|
||||
$this->assertTrue($loader->supports($closure), '->supports() returns true if the resource is loadable');
|
||||
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
|
||||
|
||||
$this->assertTrue($loader->supports($closure, 'closure'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($loader->supports($closure, 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$loader = new ClosureLoader();
|
||||
|
||||
$route = new Route('/');
|
||||
$routes = $loader->load(function () use ($route) {
|
||||
$routes = new RouteCollection();
|
||||
|
||||
$routes->add('foo', $route);
|
||||
|
||||
return $routes;
|
||||
});
|
||||
|
||||
$this->assertEquals($route, $routes->get('foo'), '->load() loads a \Closure resource');
|
||||
}
|
||||
}
|
||||
74
vendor/symfony/routing/Tests/Loader/DirectoryLoaderTest.php
vendored
Normal file
74
vendor/symfony/routing/Tests/Loader/DirectoryLoaderTest.php
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Config\Loader\LoaderResolver;
|
||||
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
|
||||
use Symfony\Component\Routing\Loader\DirectoryLoader;
|
||||
use Symfony\Component\Routing\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
class DirectoryLoaderTest extends AbstractAnnotationLoaderTest
|
||||
{
|
||||
private $loader;
|
||||
private $reader;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$locator = new FileLocator();
|
||||
$this->reader = $this->getReader();
|
||||
$this->loader = new DirectoryLoader($locator);
|
||||
$resolver = new LoaderResolver(array(
|
||||
new YamlFileLoader($locator),
|
||||
new AnnotationFileLoader($locator, $this->getClassLoader($this->reader)),
|
||||
$this->loader,
|
||||
));
|
||||
$this->loader->setResolver($resolver);
|
||||
}
|
||||
|
||||
public function testLoadDirectory()
|
||||
{
|
||||
$collection = $this->loader->load(__DIR__.'/../Fixtures/directory', 'directory');
|
||||
$this->verifyCollection($collection);
|
||||
}
|
||||
|
||||
public function testImportDirectory()
|
||||
{
|
||||
$collection = $this->loader->load(__DIR__.'/../Fixtures/directory_import', 'directory');
|
||||
$this->verifyCollection($collection);
|
||||
}
|
||||
|
||||
private function verifyCollection(RouteCollection $collection)
|
||||
{
|
||||
$routes = $collection->all();
|
||||
|
||||
$this->assertCount(3, $routes, 'Three routes are loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
|
||||
for ($i = 1; $i <= 3; ++$i) {
|
||||
$this->assertSame('/route/'.$i, $routes['route'.$i]->getPath());
|
||||
}
|
||||
}
|
||||
|
||||
public function testSupports()
|
||||
{
|
||||
$fixturesDir = __DIR__.'/../Fixtures';
|
||||
|
||||
$this->assertFalse($this->loader->supports($fixturesDir), '->supports(*) returns false');
|
||||
|
||||
$this->assertTrue($this->loader->supports($fixturesDir, 'directory'), '->supports(*, "directory") returns true');
|
||||
$this->assertFalse($this->loader->supports($fixturesDir, 'foo'), '->supports(*, "foo") returns false');
|
||||
}
|
||||
}
|
||||
17
vendor/symfony/routing/Tests/Loader/FileLocatorStub.php
vendored
Normal file
17
vendor/symfony/routing/Tests/Loader/FileLocatorStub.php
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Config\FileLocatorInterface;
|
||||
|
||||
class FileLocatorStub implements FileLocatorInterface
|
||||
{
|
||||
public function locate($name, $currentPath = null, $first = true)
|
||||
{
|
||||
if (0 === strpos($name, 'http')) {
|
||||
return $name;
|
||||
}
|
||||
|
||||
return rtrim($currentPath, '/').'/'.$name;
|
||||
}
|
||||
}
|
||||
45
vendor/symfony/routing/Tests/Loader/GlobFileLoaderTest.php
vendored
Normal file
45
vendor/symfony/routing/Tests/Loader/GlobFileLoaderTest.php
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Config\Resource\GlobResource;
|
||||
use Symfony\Component\Routing\Loader\GlobFileLoader;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
class GlobFileLoaderTest extends TestCase
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new GlobFileLoader(new FileLocator());
|
||||
|
||||
$this->assertTrue($loader->supports('any-path', 'glob'), '->supports() returns true if the resource has the glob type');
|
||||
$this->assertFalse($loader->supports('any-path'), '->supports() returns false if the resource is not of glob type');
|
||||
}
|
||||
|
||||
public function testLoadAddsTheGlobResourceToTheContainer()
|
||||
{
|
||||
$loader = new GlobFileLoaderWithoutImport(new FileLocator());
|
||||
$collection = $loader->load(__DIR__.'/../Fixtures/directory/*.yml');
|
||||
|
||||
$this->assertEquals(new GlobResource(__DIR__.'/../Fixtures/directory', '/*.yml', false), $collection->getResources()[0]);
|
||||
}
|
||||
}
|
||||
|
||||
class GlobFileLoaderWithoutImport extends GlobFileLoader
|
||||
{
|
||||
public function import($resource, $type = null, $ignoreErrors = false, $sourceResource = null)
|
||||
{
|
||||
return new RouteCollection();
|
||||
}
|
||||
}
|
||||
148
vendor/symfony/routing/Tests/Loader/ObjectRouteLoaderTest.php
vendored
Normal file
148
vendor/symfony/routing/Tests/Loader/ObjectRouteLoaderTest.php
vendored
Normal file
@@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Routing\Loader\ObjectRouteLoader;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
class ObjectRouteLoaderTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @group legacy
|
||||
* @expectedDeprecation Referencing service route loaders with a single colon is deprecated since Symfony 4.1. Use my_route_provider_service::loadRoutes instead.
|
||||
*/
|
||||
public function testLoadCallsServiceAndReturnsCollectionWithLegacyNotation()
|
||||
{
|
||||
$loader = new ObjectRouteLoaderForTest();
|
||||
|
||||
// create a basic collection that will be returned
|
||||
$collection = new RouteCollection();
|
||||
$collection->add('foo', new Route('/foo'));
|
||||
|
||||
$loader->loaderMap = array(
|
||||
'my_route_provider_service' => new RouteService($collection),
|
||||
);
|
||||
|
||||
$actualRoutes = $loader->load(
|
||||
'my_route_provider_service:loadRoutes',
|
||||
'service'
|
||||
);
|
||||
|
||||
$this->assertSame($collection, $actualRoutes);
|
||||
// the service file should be listed as a resource
|
||||
$this->assertNotEmpty($actualRoutes->getResources());
|
||||
}
|
||||
|
||||
public function testLoadCallsServiceAndReturnsCollection()
|
||||
{
|
||||
$loader = new ObjectRouteLoaderForTest();
|
||||
|
||||
// create a basic collection that will be returned
|
||||
$collection = new RouteCollection();
|
||||
$collection->add('foo', new Route('/foo'));
|
||||
|
||||
$loader->loaderMap = array(
|
||||
'my_route_provider_service' => new RouteService($collection),
|
||||
);
|
||||
|
||||
$actualRoutes = $loader->load(
|
||||
'my_route_provider_service::loadRoutes',
|
||||
'service'
|
||||
);
|
||||
|
||||
$this->assertSame($collection, $actualRoutes);
|
||||
// the service file should be listed as a resource
|
||||
$this->assertNotEmpty($actualRoutes->getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @dataProvider getBadResourceStrings
|
||||
*/
|
||||
public function testExceptionWithoutSyntax($resourceString)
|
||||
{
|
||||
$loader = new ObjectRouteLoaderForTest();
|
||||
$loader->load($resourceString);
|
||||
}
|
||||
|
||||
public function getBadResourceStrings()
|
||||
{
|
||||
return array(
|
||||
array('Foo'),
|
||||
array('Foo:Bar:baz'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
*/
|
||||
public function testExceptionOnNoObjectReturned()
|
||||
{
|
||||
$loader = new ObjectRouteLoaderForTest();
|
||||
$loader->loaderMap = array('my_service' => 'NOT_AN_OBJECT');
|
||||
$loader->load('my_service::method');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \BadMethodCallException
|
||||
*/
|
||||
public function testExceptionOnBadMethod()
|
||||
{
|
||||
$loader = new ObjectRouteLoaderForTest();
|
||||
$loader->loaderMap = array('my_service' => new \stdClass());
|
||||
$loader->load('my_service::method');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \LogicException
|
||||
*/
|
||||
public function testExceptionOnMethodNotReturningCollection()
|
||||
{
|
||||
$service = $this->getMockBuilder('stdClass')
|
||||
->setMethods(array('loadRoutes'))
|
||||
->getMock();
|
||||
$service->expects($this->once())
|
||||
->method('loadRoutes')
|
||||
->will($this->returnValue('NOT_A_COLLECTION'));
|
||||
|
||||
$loader = new ObjectRouteLoaderForTest();
|
||||
$loader->loaderMap = array('my_service' => $service);
|
||||
$loader->load('my_service::loadRoutes');
|
||||
}
|
||||
}
|
||||
|
||||
class ObjectRouteLoaderForTest extends ObjectRouteLoader
|
||||
{
|
||||
public $loaderMap = array();
|
||||
|
||||
protected function getServiceObject($id)
|
||||
{
|
||||
return isset($this->loaderMap[$id]) ? $this->loaderMap[$id] : null;
|
||||
}
|
||||
}
|
||||
|
||||
class RouteService
|
||||
{
|
||||
private $collection;
|
||||
|
||||
public function __construct($collection)
|
||||
{
|
||||
$this->collection = $collection;
|
||||
}
|
||||
|
||||
public function loadRoutes()
|
||||
{
|
||||
return $this->collection;
|
||||
}
|
||||
}
|
||||
169
vendor/symfony/routing/Tests/Loader/PhpFileLoaderTest.php
vendored
Normal file
169
vendor/symfony/routing/Tests/Loader/PhpFileLoaderTest.php
vendored
Normal file
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
use Symfony\Component\Routing\Loader\PhpFileLoader;
|
||||
use Symfony\Component\Routing\Route;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
class PhpFileLoaderTest extends TestCase
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new PhpFileLoader($this->getMockBuilder('Symfony\Component\Config\FileLocator')->getMock());
|
||||
|
||||
$this->assertTrue($loader->supports('foo.php'), '->supports() returns true if the resource is loadable');
|
||||
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
|
||||
|
||||
$this->assertTrue($loader->supports('foo.php', 'php'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($loader->supports('foo.php', 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
|
||||
public function testLoadWithRoute()
|
||||
{
|
||||
$loader = new PhpFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('validpattern.php');
|
||||
$routes = $routeCollection->all();
|
||||
|
||||
$this->assertCount(1, $routes, 'One route is loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
|
||||
foreach ($routes as $route) {
|
||||
$this->assertSame('/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertSame('{locale}.example.com', $route->getHost());
|
||||
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
|
||||
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
|
||||
$this->assertEquals(array('https'), $route->getSchemes());
|
||||
}
|
||||
}
|
||||
|
||||
public function testLoadWithImport()
|
||||
{
|
||||
$loader = new PhpFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('validresource.php');
|
||||
$routes = $routeCollection->all();
|
||||
|
||||
$this->assertCount(1, $routes, 'One route is loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
|
||||
foreach ($routes as $route) {
|
||||
$this->assertSame('/prefix/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertSame('{locale}.example.com', $route->getHost());
|
||||
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
|
||||
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
|
||||
$this->assertEquals(array('https'), $route->getSchemes());
|
||||
}
|
||||
}
|
||||
|
||||
public function testThatDefiningVariableInConfigFileHasNoSideEffects()
|
||||
{
|
||||
$locator = new FileLocator(array(__DIR__.'/../Fixtures'));
|
||||
$loader = new PhpFileLoader($locator);
|
||||
$routeCollection = $loader->load('with_define_path_variable.php');
|
||||
$resources = $routeCollection->getResources();
|
||||
$this->assertCount(1, $resources);
|
||||
$this->assertContainsOnly('Symfony\Component\Config\Resource\ResourceInterface', $resources);
|
||||
$fileResource = reset($resources);
|
||||
$this->assertSame(
|
||||
realpath($locator->locate('with_define_path_variable.php')),
|
||||
(string) $fileResource
|
||||
);
|
||||
}
|
||||
|
||||
public function testRoutingConfigurator()
|
||||
{
|
||||
$locator = new FileLocator(array(__DIR__.'/../Fixtures'));
|
||||
$loader = new PhpFileLoader($locator);
|
||||
$routeCollectionClosure = $loader->load('php_dsl.php');
|
||||
$routeCollectionObject = $loader->load('php_object_dsl.php');
|
||||
|
||||
$expectedCollection = new RouteCollection();
|
||||
|
||||
$expectedCollection->add('foo', (new Route('/foo'))
|
||||
->setOptions(array('utf8' => true))
|
||||
->setCondition('abc')
|
||||
);
|
||||
$expectedCollection->add('buz', (new Route('/zub'))
|
||||
->setDefaults(array('_controller' => 'foo:act'))
|
||||
);
|
||||
$expectedCollection->add('c_root', (new Route('/sub/pub/'))
|
||||
->setRequirements(array('id' => '\d+'))
|
||||
);
|
||||
$expectedCollection->add('c_bar', (new Route('/sub/pub/bar'))
|
||||
->setRequirements(array('id' => '\d+'))
|
||||
);
|
||||
$expectedCollection->add('c_pub_buz', (new Route('/sub/pub/buz'))
|
||||
->setHost('host')
|
||||
->setRequirements(array('id' => '\d+'))
|
||||
);
|
||||
$expectedCollection->add('z_c_root', new Route('/zub/pub/'));
|
||||
$expectedCollection->add('z_c_bar', new Route('/zub/pub/bar'));
|
||||
$expectedCollection->add('z_c_pub_buz', (new Route('/zub/pub/buz'))->setHost('host'));
|
||||
$expectedCollection->add('r_root', new Route('/bus'));
|
||||
$expectedCollection->add('r_bar', new Route('/bus/bar/'));
|
||||
$expectedCollection->add('ouf', (new Route('/ouf'))
|
||||
->setSchemes(array('https'))
|
||||
->setMethods(array('GET'))
|
||||
->setDefaults(array('id' => 0))
|
||||
);
|
||||
|
||||
$expectedCollection->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_dsl_sub.php')));
|
||||
$expectedCollection->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_dsl_sub_root.php')));
|
||||
|
||||
$expectedCollectionClosure = $expectedCollection;
|
||||
$expectedCollectionObject = clone $expectedCollection;
|
||||
|
||||
$expectedCollectionClosure->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_dsl.php')));
|
||||
$expectedCollectionObject->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_object_dsl.php')));
|
||||
|
||||
$this->assertEquals($expectedCollectionClosure, $routeCollectionClosure);
|
||||
$this->assertEquals($expectedCollectionObject, $routeCollectionObject);
|
||||
}
|
||||
|
||||
public function testRoutingConfiguratorCanImportGlobPatterns()
|
||||
{
|
||||
$locator = new FileLocator(array(__DIR__.'/../Fixtures/glob'));
|
||||
$loader = new PhpFileLoader($locator);
|
||||
$routeCollection = $loader->load('php_dsl.php');
|
||||
|
||||
$route = $routeCollection->get('bar_route');
|
||||
$this->assertSame('AppBundle:Bar:view', $route->getDefault('_controller'));
|
||||
|
||||
$route = $routeCollection->get('baz_route');
|
||||
$this->assertSame('AppBundle:Baz:view', $route->getDefault('_controller'));
|
||||
}
|
||||
|
||||
public function testRoutingI18nConfigurator()
|
||||
{
|
||||
$locator = new FileLocator(array(__DIR__.'/../Fixtures'));
|
||||
$loader = new PhpFileLoader($locator);
|
||||
$routeCollection = $loader->load('php_dsl_i18n.php');
|
||||
|
||||
$expectedCollection = new RouteCollection();
|
||||
|
||||
$expectedCollection->add('foo.en', (new Route('/glish/foo'))->setDefaults(array('_locale' => 'en', '_canonical_route' => 'foo')));
|
||||
$expectedCollection->add('bar.en', (new Route('/glish/bar'))->setDefaults(array('_locale' => 'en', '_canonical_route' => 'bar')));
|
||||
$expectedCollection->add('baz.en', (new Route('/baz'))->setDefaults(array('_locale' => 'en', '_canonical_route' => 'baz')));
|
||||
$expectedCollection->add('c_foo.fr', (new Route('/ench/pub/foo'))->setDefaults(array('_locale' => 'fr', '_canonical_route' => 'c_foo')));
|
||||
$expectedCollection->add('c_bar.fr', (new Route('/ench/pub/bar'))->setDefaults(array('_locale' => 'fr', '_canonical_route' => 'c_bar')));
|
||||
|
||||
$expectedCollection->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_dsl_sub_i18n.php')));
|
||||
$expectedCollection->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_dsl_i18n.php')));
|
||||
|
||||
$this->assertEquals($expectedCollection, $routeCollection);
|
||||
}
|
||||
}
|
||||
444
vendor/symfony/routing/Tests/Loader/XmlFileLoaderTest.php
vendored
Normal file
444
vendor/symfony/routing/Tests/Loader/XmlFileLoaderTest.php
vendored
Normal file
@@ -0,0 +1,444 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Routing\Loader\XmlFileLoader;
|
||||
use Symfony\Component\Routing\Tests\Fixtures\CustomXmlFileLoader;
|
||||
|
||||
class XmlFileLoaderTest extends TestCase
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new XmlFileLoader($this->getMockBuilder('Symfony\Component\Config\FileLocator')->getMock());
|
||||
|
||||
$this->assertTrue($loader->supports('foo.xml'), '->supports() returns true if the resource is loadable');
|
||||
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
|
||||
|
||||
$this->assertTrue($loader->supports('foo.xml', 'xml'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($loader->supports('foo.xml', 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
|
||||
public function testLoadWithRoute()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('validpattern.xml');
|
||||
$route = $routeCollection->get('blog_show');
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
|
||||
$this->assertSame('/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('{locale}.example.com', $route->getHost());
|
||||
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertSame('\w+', $route->getRequirement('locale'));
|
||||
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
|
||||
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
|
||||
$this->assertEquals(array('https'), $route->getSchemes());
|
||||
$this->assertEquals('context.getMethod() == "GET"', $route->getCondition());
|
||||
}
|
||||
|
||||
public function testLoadWithNamespacePrefix()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('namespaceprefix.xml');
|
||||
|
||||
$this->assertCount(1, $routeCollection->all(), 'One route is loaded');
|
||||
|
||||
$route = $routeCollection->get('blog_show');
|
||||
$this->assertSame('/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('{_locale}.example.com', $route->getHost());
|
||||
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertSame('\w+', $route->getRequirement('slug'));
|
||||
$this->assertSame('en|fr|de', $route->getRequirement('_locale'));
|
||||
$this->assertNull($route->getDefault('slug'));
|
||||
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
|
||||
$this->assertSame(1, $route->getDefault('page'));
|
||||
}
|
||||
|
||||
public function testLoadWithImport()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('validresource.xml');
|
||||
$routes = $routeCollection->all();
|
||||
|
||||
$this->assertCount(2, $routes, 'Two routes are loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
|
||||
foreach ($routes as $route) {
|
||||
$this->assertSame('/{foo}/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('123', $route->getDefault('foo'));
|
||||
$this->assertSame('\d+', $route->getRequirement('foo'));
|
||||
$this->assertSame('bar', $route->getOption('foo'));
|
||||
$this->assertSame('', $route->getHost());
|
||||
$this->assertSame('context.getMethod() == "POST"', $route->getCondition());
|
||||
}
|
||||
}
|
||||
|
||||
public function testLoadLocalized()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('localized.xml');
|
||||
$routes = $routeCollection->all();
|
||||
|
||||
$this->assertCount(2, $routes, 'Two routes are loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
|
||||
$this->assertEquals('/route', $routeCollection->get('localized.fr')->getPath());
|
||||
$this->assertEquals('/path', $routeCollection->get('localized.en')->getPath());
|
||||
}
|
||||
|
||||
public function testLocalizedImports()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
|
||||
$routeCollection = $loader->load('importer-with-locale.xml');
|
||||
$routes = $routeCollection->all();
|
||||
|
||||
$this->assertCount(2, $routes, 'Two routes are loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
|
||||
$this->assertEquals('/le-prefix/le-suffix', $routeCollection->get('imported.fr')->getPath());
|
||||
$this->assertEquals('/the-prefix/suffix', $routeCollection->get('imported.en')->getPath());
|
||||
}
|
||||
|
||||
public function testLocalizedImportsOfNotLocalizedRoutes()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
|
||||
$routeCollection = $loader->load('importer-with-locale-imports-non-localized-route.xml');
|
||||
$routes = $routeCollection->all();
|
||||
|
||||
$this->assertCount(2, $routes, 'Two routes are loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
|
||||
$this->assertEquals('/le-prefix/suffix', $routeCollection->get('imported.fr')->getPath());
|
||||
$this->assertEquals('/the-prefix/suffix', $routeCollection->get('imported.en')->getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @dataProvider getPathsToInvalidFiles
|
||||
*/
|
||||
public function testLoadThrowsExceptionWithInvalidFile($filePath)
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$loader->load($filePath);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @dataProvider getPathsToInvalidFiles
|
||||
*/
|
||||
public function testLoadThrowsExceptionWithInvalidFileEvenWithoutSchemaValidation($filePath)
|
||||
{
|
||||
$loader = new CustomXmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$loader->load($filePath);
|
||||
}
|
||||
|
||||
public function getPathsToInvalidFiles()
|
||||
{
|
||||
return array(array('nonvalidnode.xml'), array('nonvalidroute.xml'), array('nonvalid.xml'), array('missing_id.xml'), array('missing_path.xml'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessage Document types are not allowed.
|
||||
*/
|
||||
public function testDocTypeIsNotAllowed()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$loader->load('withdoctype.xml');
|
||||
}
|
||||
|
||||
public function testNullValues()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('null_values.xml');
|
||||
$route = $routeCollection->get('blog_show');
|
||||
|
||||
$this->assertTrue($route->hasDefault('foo'));
|
||||
$this->assertNull($route->getDefault('foo'));
|
||||
$this->assertTrue($route->hasDefault('bar'));
|
||||
$this->assertNull($route->getDefault('bar'));
|
||||
$this->assertEquals('foo', $route->getDefault('foobar'));
|
||||
$this->assertEquals('bar', $route->getDefault('baz'));
|
||||
}
|
||||
|
||||
public function testScalarDataTypeDefaults()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('scalar_defaults.xml');
|
||||
$route = $routeCollection->get('blog');
|
||||
|
||||
$this->assertSame(
|
||||
array(
|
||||
'_controller' => 'AcmeBlogBundle:Blog:index',
|
||||
'slug' => null,
|
||||
'published' => true,
|
||||
'page' => 1,
|
||||
'price' => 3.5,
|
||||
'archived' => false,
|
||||
'free' => true,
|
||||
'locked' => false,
|
||||
'foo' => null,
|
||||
'bar' => null,
|
||||
),
|
||||
$route->getDefaults()
|
||||
);
|
||||
}
|
||||
|
||||
public function testListDefaults()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('list_defaults.xml');
|
||||
$route = $routeCollection->get('blog');
|
||||
|
||||
$this->assertSame(
|
||||
array(
|
||||
'_controller' => 'AcmeBlogBundle:Blog:index',
|
||||
'values' => array(true, 1, 3.5, 'foo'),
|
||||
),
|
||||
$route->getDefaults()
|
||||
);
|
||||
}
|
||||
|
||||
public function testListInListDefaults()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('list_in_list_defaults.xml');
|
||||
$route = $routeCollection->get('blog');
|
||||
|
||||
$this->assertSame(
|
||||
array(
|
||||
'_controller' => 'AcmeBlogBundle:Blog:index',
|
||||
'values' => array(array(true, 1, 3.5, 'foo')),
|
||||
),
|
||||
$route->getDefaults()
|
||||
);
|
||||
}
|
||||
|
||||
public function testListInMapDefaults()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('list_in_map_defaults.xml');
|
||||
$route = $routeCollection->get('blog');
|
||||
|
||||
$this->assertSame(
|
||||
array(
|
||||
'_controller' => 'AcmeBlogBundle:Blog:index',
|
||||
'values' => array('list' => array(true, 1, 3.5, 'foo')),
|
||||
),
|
||||
$route->getDefaults()
|
||||
);
|
||||
}
|
||||
|
||||
public function testMapDefaults()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('map_defaults.xml');
|
||||
$route = $routeCollection->get('blog');
|
||||
|
||||
$this->assertSame(
|
||||
array(
|
||||
'_controller' => 'AcmeBlogBundle:Blog:index',
|
||||
'values' => array(
|
||||
'public' => true,
|
||||
'page' => 1,
|
||||
'price' => 3.5,
|
||||
'title' => 'foo',
|
||||
),
|
||||
),
|
||||
$route->getDefaults()
|
||||
);
|
||||
}
|
||||
|
||||
public function testMapInListDefaults()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('map_in_list_defaults.xml');
|
||||
$route = $routeCollection->get('blog');
|
||||
|
||||
$this->assertSame(
|
||||
array(
|
||||
'_controller' => 'AcmeBlogBundle:Blog:index',
|
||||
'values' => array(array(
|
||||
'public' => true,
|
||||
'page' => 1,
|
||||
'price' => 3.5,
|
||||
'title' => 'foo',
|
||||
)),
|
||||
),
|
||||
$route->getDefaults()
|
||||
);
|
||||
}
|
||||
|
||||
public function testMapInMapDefaults()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('map_in_map_defaults.xml');
|
||||
$route = $routeCollection->get('blog');
|
||||
|
||||
$this->assertSame(
|
||||
array(
|
||||
'_controller' => 'AcmeBlogBundle:Blog:index',
|
||||
'values' => array('map' => array(
|
||||
'public' => true,
|
||||
'page' => 1,
|
||||
'price' => 3.5,
|
||||
'title' => 'foo',
|
||||
)),
|
||||
),
|
||||
$route->getDefaults()
|
||||
);
|
||||
}
|
||||
|
||||
public function testNullValuesInList()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('list_null_values.xml');
|
||||
$route = $routeCollection->get('blog');
|
||||
|
||||
$this->assertSame(array(null, null, null, null, null, null), $route->getDefault('list'));
|
||||
}
|
||||
|
||||
public function testNullValuesInMap()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('map_null_values.xml');
|
||||
$route = $routeCollection->get('blog');
|
||||
|
||||
$this->assertSame(
|
||||
array(
|
||||
'boolean' => null,
|
||||
'integer' => null,
|
||||
'float' => null,
|
||||
'string' => null,
|
||||
'list' => null,
|
||||
'map' => null,
|
||||
),
|
||||
$route->getDefault('map')
|
||||
);
|
||||
}
|
||||
|
||||
public function testLoadRouteWithControllerAttribute()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
|
||||
$routeCollection = $loader->load('routing.xml');
|
||||
|
||||
$route = $routeCollection->get('app_homepage');
|
||||
|
||||
$this->assertSame('AppBundle:Homepage:show', $route->getDefault('_controller'));
|
||||
}
|
||||
|
||||
public function testLoadRouteWithoutControllerAttribute()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
|
||||
$routeCollection = $loader->load('routing.xml');
|
||||
|
||||
$route = $routeCollection->get('app_logout');
|
||||
|
||||
$this->assertNull($route->getDefault('_controller'));
|
||||
}
|
||||
|
||||
public function testLoadRouteWithControllerSetInDefaults()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
|
||||
$routeCollection = $loader->load('routing.xml');
|
||||
|
||||
$route = $routeCollection->get('app_blog');
|
||||
|
||||
$this->assertSame('AppBundle:Blog:list', $route->getDefault('_controller'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessageRegExp /The routing file "[^"]*" must not specify both the "controller" attribute and the defaults key "_controller" for "app_blog"/
|
||||
*/
|
||||
public function testOverrideControllerInDefaults()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
|
||||
$loader->load('override_defaults.xml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideFilesImportingRoutesWithControllers
|
||||
*/
|
||||
public function testImportRouteWithController($file)
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
|
||||
$routeCollection = $loader->load($file);
|
||||
|
||||
$route = $routeCollection->get('app_homepage');
|
||||
$this->assertSame('FrameworkBundle:Template:template', $route->getDefault('_controller'));
|
||||
|
||||
$route = $routeCollection->get('app_blog');
|
||||
$this->assertSame('FrameworkBundle:Template:template', $route->getDefault('_controller'));
|
||||
|
||||
$route = $routeCollection->get('app_logout');
|
||||
$this->assertSame('FrameworkBundle:Template:template', $route->getDefault('_controller'));
|
||||
}
|
||||
|
||||
public function provideFilesImportingRoutesWithControllers()
|
||||
{
|
||||
yield array('import_controller.xml');
|
||||
yield array('import__controller.xml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessageRegExp /The routing file "[^"]*" must not specify both the "controller" attribute and the defaults key "_controller" for the "import" tag/
|
||||
*/
|
||||
public function testImportWithOverriddenController()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
|
||||
$loader->load('import_override_defaults.xml');
|
||||
}
|
||||
|
||||
public function testImportRouteWithGlobMatchingSingleFile()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/glob')));
|
||||
$routeCollection = $loader->load('import_single.xml');
|
||||
|
||||
$route = $routeCollection->get('bar_route');
|
||||
$this->assertSame('AppBundle:Bar:view', $route->getDefault('_controller'));
|
||||
}
|
||||
|
||||
public function testImportRouteWithGlobMatchingMultipleFiles()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/glob')));
|
||||
$routeCollection = $loader->load('import_multiple.xml');
|
||||
|
||||
$route = $routeCollection->get('bar_route');
|
||||
$this->assertSame('AppBundle:Bar:view', $route->getDefault('_controller'));
|
||||
|
||||
$route = $routeCollection->get('baz_route');
|
||||
$this->assertSame('AppBundle:Baz:view', $route->getDefault('_controller'));
|
||||
}
|
||||
|
||||
public function testImportRouteWithNamePrefix()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/import_with_name_prefix')));
|
||||
$routeCollection = $loader->load('routing.xml');
|
||||
|
||||
$this->assertNotNull($routeCollection->get('app_blog'));
|
||||
$this->assertEquals('/blog', $routeCollection->get('app_blog')->getPath());
|
||||
$this->assertNotNull($routeCollection->get('api_app_blog'));
|
||||
$this->assertEquals('/api/blog', $routeCollection->get('api_app_blog')->getPath());
|
||||
}
|
||||
|
||||
public function testImportRouteWithNoTrailingSlash()
|
||||
{
|
||||
$loader = new XmlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/import_with_no_trailing_slash')));
|
||||
$routeCollection = $loader->load('routing.xml');
|
||||
|
||||
$this->assertEquals('/slash/', $routeCollection->get('a_app_homepage')->getPath());
|
||||
$this->assertEquals('/no-slash', $routeCollection->get('b_app_homepage')->getPath());
|
||||
}
|
||||
}
|
||||
307
vendor/symfony/routing/Tests/Loader/YamlFileLoaderTest.php
vendored
Normal file
307
vendor/symfony/routing/Tests/Loader/YamlFileLoaderTest.php
vendored
Normal file
@@ -0,0 +1,307 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
use Symfony\Component\Routing\Loader\YamlFileLoader;
|
||||
|
||||
class YamlFileLoaderTest extends TestCase
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new YamlFileLoader($this->getMockBuilder('Symfony\Component\Config\FileLocator')->getMock());
|
||||
|
||||
$this->assertTrue($loader->supports('foo.yml'), '->supports() returns true if the resource is loadable');
|
||||
$this->assertTrue($loader->supports('foo.yaml'), '->supports() returns true if the resource is loadable');
|
||||
$this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
|
||||
|
||||
$this->assertTrue($loader->supports('foo.yml', 'yaml'), '->supports() checks the resource type if specified');
|
||||
$this->assertTrue($loader->supports('foo.yaml', 'yaml'), '->supports() checks the resource type if specified');
|
||||
$this->assertFalse($loader->supports('foo.yml', 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
|
||||
public function testLoadDoesNothingIfEmpty()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$collection = $loader->load('empty.yml');
|
||||
|
||||
$this->assertEquals(array(), $collection->all());
|
||||
$this->assertEquals(array(new FileResource(realpath(__DIR__.'/../Fixtures/empty.yml'))), $collection->getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @dataProvider getPathsToInvalidFiles
|
||||
*/
|
||||
public function testLoadThrowsExceptionWithInvalidFile($filePath)
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$loader->load($filePath);
|
||||
}
|
||||
|
||||
public function getPathsToInvalidFiles()
|
||||
{
|
||||
return array(
|
||||
array('nonvalid.yml'),
|
||||
array('nonvalid2.yml'),
|
||||
array('incomplete.yml'),
|
||||
array('nonvalidkeys.yml'),
|
||||
array('nonesense_resource_plus_path.yml'),
|
||||
array('nonesense_type_without_resource.yml'),
|
||||
array('bad_format.yml'),
|
||||
);
|
||||
}
|
||||
|
||||
public function testLoadSpecialRouteName()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('special_route_name.yml');
|
||||
$route = $routeCollection->get('#$péß^a|');
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
|
||||
$this->assertSame('/true', $route->getPath());
|
||||
}
|
||||
|
||||
public function testLoadWithRoute()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('validpattern.yml');
|
||||
$route = $routeCollection->get('blog_show');
|
||||
|
||||
$this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
|
||||
$this->assertSame('/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('{locale}.example.com', $route->getHost());
|
||||
$this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
|
||||
$this->assertSame('\w+', $route->getRequirement('locale'));
|
||||
$this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
|
||||
$this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
|
||||
$this->assertEquals(array('https'), $route->getSchemes());
|
||||
$this->assertEquals('context.getMethod() == "GET"', $route->getCondition());
|
||||
}
|
||||
|
||||
public function testLoadWithResource()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
|
||||
$routeCollection = $loader->load('validresource.yml');
|
||||
$routes = $routeCollection->all();
|
||||
|
||||
$this->assertCount(2, $routes, 'Two routes are loaded');
|
||||
$this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
|
||||
|
||||
foreach ($routes as $route) {
|
||||
$this->assertSame('/{foo}/blog/{slug}', $route->getPath());
|
||||
$this->assertSame('123', $route->getDefault('foo'));
|
||||
$this->assertSame('\d+', $route->getRequirement('foo'));
|
||||
$this->assertSame('bar', $route->getOption('foo'));
|
||||
$this->assertSame('', $route->getHost());
|
||||
$this->assertSame('context.getMethod() == "POST"', $route->getCondition());
|
||||
}
|
||||
}
|
||||
|
||||
public function testLoadRouteWithControllerAttribute()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
|
||||
$routeCollection = $loader->load('routing.yml');
|
||||
|
||||
$route = $routeCollection->get('app_homepage');
|
||||
|
||||
$this->assertSame('AppBundle:Homepage:show', $route->getDefault('_controller'));
|
||||
}
|
||||
|
||||
public function testLoadRouteWithoutControllerAttribute()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
|
||||
$routeCollection = $loader->load('routing.yml');
|
||||
|
||||
$route = $routeCollection->get('app_logout');
|
||||
|
||||
$this->assertNull($route->getDefault('_controller'));
|
||||
}
|
||||
|
||||
public function testLoadRouteWithControllerSetInDefaults()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
|
||||
$routeCollection = $loader->load('routing.yml');
|
||||
|
||||
$route = $routeCollection->get('app_blog');
|
||||
|
||||
$this->assertSame('AppBundle:Blog:list', $route->getDefault('_controller'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessageRegExp /The routing file "[^"]*" must not specify both the "controller" key and the defaults key "_controller" for "app_blog"/
|
||||
*/
|
||||
public function testOverrideControllerInDefaults()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
|
||||
$loader->load('override_defaults.yml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideFilesImportingRoutesWithControllers
|
||||
*/
|
||||
public function testImportRouteWithController($file)
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
|
||||
$routeCollection = $loader->load($file);
|
||||
|
||||
$route = $routeCollection->get('app_homepage');
|
||||
$this->assertSame('FrameworkBundle:Template:template', $route->getDefault('_controller'));
|
||||
|
||||
$route = $routeCollection->get('app_blog');
|
||||
$this->assertSame('FrameworkBundle:Template:template', $route->getDefault('_controller'));
|
||||
|
||||
$route = $routeCollection->get('app_logout');
|
||||
$this->assertSame('FrameworkBundle:Template:template', $route->getDefault('_controller'));
|
||||
}
|
||||
|
||||
public function provideFilesImportingRoutesWithControllers()
|
||||
{
|
||||
yield array('import_controller.yml');
|
||||
yield array('import__controller.yml');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
* @expectedExceptionMessageRegExp /The routing file "[^"]*" must not specify both the "controller" key and the defaults key "_controller" for "_static"/
|
||||
*/
|
||||
public function testImportWithOverriddenController()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/controller')));
|
||||
$loader->load('import_override_defaults.yml');
|
||||
}
|
||||
|
||||
public function testImportRouteWithGlobMatchingSingleFile()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/glob')));
|
||||
$routeCollection = $loader->load('import_single.yml');
|
||||
|
||||
$route = $routeCollection->get('bar_route');
|
||||
$this->assertSame('AppBundle:Bar:view', $route->getDefault('_controller'));
|
||||
}
|
||||
|
||||
public function testImportRouteWithGlobMatchingMultipleFiles()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/glob')));
|
||||
$routeCollection = $loader->load('import_multiple.yml');
|
||||
|
||||
$route = $routeCollection->get('bar_route');
|
||||
$this->assertSame('AppBundle:Bar:view', $route->getDefault('_controller'));
|
||||
|
||||
$route = $routeCollection->get('baz_route');
|
||||
$this->assertSame('AppBundle:Baz:view', $route->getDefault('_controller'));
|
||||
}
|
||||
|
||||
public function testImportRouteWithNamePrefix()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/import_with_name_prefix')));
|
||||
$routeCollection = $loader->load('routing.yml');
|
||||
|
||||
$this->assertNotNull($routeCollection->get('app_blog'));
|
||||
$this->assertEquals('/blog', $routeCollection->get('app_blog')->getPath());
|
||||
$this->assertNotNull($routeCollection->get('api_app_blog'));
|
||||
$this->assertEquals('/api/blog', $routeCollection->get('api_app_blog')->getPath());
|
||||
}
|
||||
|
||||
public function testRemoteSourcesAreNotAccepted()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocatorStub());
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$loader->load('http://remote.com/here.yml');
|
||||
}
|
||||
|
||||
public function testLoadingLocalizedRoute()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
|
||||
$routes = $loader->load('localized-route.yml');
|
||||
|
||||
$this->assertCount(3, $routes);
|
||||
}
|
||||
|
||||
public function testImportingRoutesFromDefinition()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
|
||||
$routes = $loader->load('importing-localized-route.yml');
|
||||
|
||||
$this->assertCount(3, $routes);
|
||||
$this->assertEquals('/nl', $routes->get('home.nl')->getPath());
|
||||
$this->assertEquals('/en', $routes->get('home.en')->getPath());
|
||||
$this->assertEquals('/here', $routes->get('not_localized')->getPath());
|
||||
}
|
||||
|
||||
public function testImportingRoutesWithLocales()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
|
||||
$routes = $loader->load('importer-with-locale.yml');
|
||||
|
||||
$this->assertCount(2, $routes);
|
||||
$this->assertEquals('/nl/voorbeeld', $routes->get('imported.nl')->getPath());
|
||||
$this->assertEquals('/en/example', $routes->get('imported.en')->getPath());
|
||||
}
|
||||
|
||||
public function testImportingNonLocalizedRoutesWithLocales()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
|
||||
$routes = $loader->load('importer-with-locale-imports-non-localized-route.yml');
|
||||
|
||||
$this->assertCount(2, $routes);
|
||||
$this->assertEquals('/nl/imported', $routes->get('imported.nl')->getPath());
|
||||
$this->assertEquals('/en/imported', $routes->get('imported.en')->getPath());
|
||||
}
|
||||
|
||||
public function testImportingRoutesWithOfficialLocales()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
|
||||
$routes = $loader->load('officially_formatted_locales.yml');
|
||||
|
||||
$this->assertCount(3, $routes);
|
||||
$this->assertEquals('/omelette-au-fromage', $routes->get('official.fr.UTF-8')->getPath());
|
||||
$this->assertEquals('/eu-não-sou-espanhol', $routes->get('official.pt-PT')->getPath());
|
||||
$this->assertEquals('/churrasco', $routes->get('official.pt_BR')->getPath());
|
||||
}
|
||||
|
||||
public function testImportingRoutesFromDefinitionMissingLocalePrefix()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$loader->load('missing-locale-in-importer.yml');
|
||||
}
|
||||
|
||||
public function testImportingRouteWithoutPathOrLocales()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
$loader->load('route-without-path-or-locales.yml');
|
||||
}
|
||||
|
||||
public function testImportingWithControllerDefault()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/localized')));
|
||||
$routes = $loader->load('importer-with-controller-default.yml');
|
||||
$this->assertCount(3, $routes);
|
||||
$this->assertEquals('DefaultController::defaultAction', $routes->get('home.en')->getDefault('_controller'));
|
||||
$this->assertEquals('DefaultController::defaultAction', $routes->get('home.nl')->getDefault('_controller'));
|
||||
$this->assertEquals('DefaultController::defaultAction', $routes->get('not_localized')->getDefault('_controller'));
|
||||
}
|
||||
|
||||
public function testImportRouteWithNoTrailingSlash()
|
||||
{
|
||||
$loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures/import_with_no_trailing_slash')));
|
||||
$routeCollection = $loader->load('routing.yml');
|
||||
|
||||
$this->assertEquals('/slash/', $routeCollection->get('a_app_homepage')->getPath());
|
||||
$this->assertEquals('/no-slash', $routeCollection->get('b_app_homepage')->getPath());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user