Laravel version update
Laravel version update
This commit is contained in:
@@ -11,7 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
abstract class AbstractAnnotationLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
abstract class AbstractAnnotationLoaderTest extends TestCase
|
||||
{
|
||||
public function getReader()
|
||||
{
|
||||
|
@@ -127,20 +127,19 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
||||
|
||||
$this->assertSame($routeData['path'], $route->getPath(), '->load preserves path annotation');
|
||||
$this->assertCount(
|
||||
count($routeData['requirements']),
|
||||
\count($routeData['requirements']),
|
||||
array_intersect_assoc($routeData['requirements'], $route->getRequirements()),
|
||||
'->load preserves requirements annotation'
|
||||
);
|
||||
$this->assertCount(
|
||||
count($routeData['options']),
|
||||
\count($routeData['options']),
|
||||
array_intersect_assoc($routeData['options'], $route->getOptions()),
|
||||
'->load preserves options annotation'
|
||||
);
|
||||
$defaults = array_replace($methodArgs, $routeData['defaults']);
|
||||
$this->assertCount(
|
||||
count($defaults),
|
||||
array_intersect_assoc($defaults, $route->getDefaults()),
|
||||
'->load preserves defaults annotation and merges them with default arguments in method signature'
|
||||
\count($routeData['defaults']),
|
||||
$route->getDefaults(),
|
||||
'->load preserves defaults annotation'
|
||||
);
|
||||
$this->assertEquals($routeData['schemes'], $route->getSchemes(), '->load preserves schemes annotation');
|
||||
$this->assertEquals($routeData['methods'], $route->getMethods(), '->load preserves methods annotation');
|
||||
@@ -150,6 +149,7 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
||||
public function testClassRouteLoad()
|
||||
{
|
||||
$classRouteData = array(
|
||||
'name' => 'prefix_',
|
||||
'path' => '/prefix',
|
||||
'schemes' => array('https'),
|
||||
'methods' => array('GET'),
|
||||
@@ -174,7 +174,115 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
||||
;
|
||||
|
||||
$routeCollection = $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass');
|
||||
$route = $routeCollection->get($methodRouteData['name']);
|
||||
$route = $routeCollection->get($classRouteData['name'].$methodRouteData['name']);
|
||||
|
||||
$this->assertSame($classRouteData['path'].$methodRouteData['path'], $route->getPath(), '->load concatenates class and method route path');
|
||||
$this->assertEquals(array_merge($classRouteData['schemes'], $methodRouteData['schemes']), $route->getSchemes(), '->load merges class and method route schemes');
|
||||
$this->assertEquals(array_merge($classRouteData['methods'], $methodRouteData['methods']), $route->getMethods(), '->load merges class and method route methods');
|
||||
}
|
||||
|
||||
public function testInvokableClassRouteLoad()
|
||||
{
|
||||
$classRouteData = array(
|
||||
'name' => 'route1',
|
||||
'path' => '/',
|
||||
'schemes' => array('https'),
|
||||
'methods' => array('GET'),
|
||||
);
|
||||
|
||||
$this->reader
|
||||
->expects($this->exactly(1))
|
||||
->method('getClassAnnotations')
|
||||
->will($this->returnValue(array($this->getAnnotatedRoute($classRouteData))))
|
||||
;
|
||||
$this->reader
|
||||
->expects($this->once())
|
||||
->method('getMethodAnnotations')
|
||||
->will($this->returnValue(array()))
|
||||
;
|
||||
|
||||
$routeCollection = $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass');
|
||||
$route = $routeCollection->get($classRouteData['name']);
|
||||
|
||||
$this->assertSame($classRouteData['path'], $route->getPath(), '->load preserves class route path');
|
||||
$this->assertEquals($classRouteData['schemes'], $route->getSchemes(), '->load preserves class route schemes');
|
||||
$this->assertEquals($classRouteData['methods'], $route->getMethods(), '->load preserves class route methods');
|
||||
}
|
||||
|
||||
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'),
|
||||
);
|
||||
|
||||
$this->reader
|
||||
->expects($this->exactly(1))
|
||||
->method('getClassAnnotations')
|
||||
->will($this->returnValue(array($this->getAnnotatedRoute($classRouteData1), $this->getAnnotatedRoute($classRouteData2))))
|
||||
;
|
||||
$this->reader
|
||||
->expects($this->once())
|
||||
->method('getMethodAnnotations')
|
||||
->will($this->returnValue(array()))
|
||||
;
|
||||
|
||||
$routeCollection = $this->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 testInvokableClassWithMethodRouteLoad()
|
||||
{
|
||||
$classRouteData = array(
|
||||
'name' => 'route1',
|
||||
'path' => '/prefix',
|
||||
'schemes' => array('https'),
|
||||
'methods' => array('GET'),
|
||||
);
|
||||
|
||||
$methodRouteData = array(
|
||||
'name' => 'route2',
|
||||
'path' => '/path',
|
||||
'schemes' => array('http'),
|
||||
'methods' => array('POST', 'PUT'),
|
||||
);
|
||||
|
||||
$this->reader
|
||||
->expects($this->once())
|
||||
->method('getClassAnnotation')
|
||||
->will($this->returnValue($this->getAnnotatedRoute($classRouteData)))
|
||||
;
|
||||
$this->reader
|
||||
->expects($this->once())
|
||||
->method('getMethodAnnotations')
|
||||
->will($this->returnValue(array($this->getAnnotatedRoute($methodRouteData))))
|
||||
;
|
||||
|
||||
$routeCollection = $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass');
|
||||
$route = $routeCollection->get($classRouteData['name']);
|
||||
|
||||
$this->assertNull($route, '->load ignores class route');
|
||||
|
||||
$route = $routeCollection->get($classRouteData['name'].$methodRouteData['name']);
|
||||
|
||||
$this->assertSame($classRouteData['path'].$methodRouteData['path'], $route->getPath(), '->load concatenates class and method route path');
|
||||
$this->assertEquals(array_merge($classRouteData['schemes'], $methodRouteData['schemes']), $route->getSchemes(), '->load merges class and method route schemes');
|
||||
|
@@ -11,8 +11,8 @@
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
|
||||
|
||||
class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
|
||||
{
|
||||
@@ -29,7 +29,7 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
|
||||
|
||||
public function testLoad()
|
||||
{
|
||||
$this->reader->expects($this->exactly(2))->method('getClassAnnotation');
|
||||
$this->reader->expects($this->exactly(3))->method('getClassAnnotation');
|
||||
|
||||
$this->reader
|
||||
->expects($this->any())
|
||||
@@ -37,6 +37,35 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
|
||||
->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');
|
||||
}
|
||||
|
||||
@@ -50,4 +79,31 @@ class AnnotationDirectoryLoaderTest extends AbstractAnnotationLoaderTest
|
||||
$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);
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
@@ -11,9 +11,9 @@
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Routing\Loader\AnnotationFileLoader;
|
||||
|
||||
class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
|
||||
{
|
||||
@@ -45,6 +45,15 @@ class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
|
||||
$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');
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.6
|
||||
*/
|
||||
@@ -58,6 +67,17 @@ class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
|
||||
$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';
|
||||
|
@@ -11,11 +11,12 @@
|
||||
|
||||
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 \PHPUnit_Framework_TestCase
|
||||
class ClosureLoaderTest extends TestCase
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
|
@@ -11,11 +11,11 @@
|
||||
|
||||
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\Loader\AnnotationFileLoader;
|
||||
use Symfony\Component\Config\Loader\LoaderResolver;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
class DirectoryLoaderTest extends AbstractAnnotationLoaderTest
|
||||
|
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();
|
||||
}
|
||||
}
|
@@ -11,11 +11,12 @@
|
||||
|
||||
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 \PHPUnit_Framework_TestCase
|
||||
class ObjectRouteLoaderTest extends TestCase
|
||||
{
|
||||
public function testLoadCallsServiceAndReturnsCollection()
|
||||
{
|
||||
|
@@ -11,14 +11,18 @@
|
||||
|
||||
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 \PHPUnit_Framework_TestCase
|
||||
class PhpFileLoaderTest extends TestCase
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new PhpFileLoader($this->getMock('Symfony\Component\Config\FileLocator'));
|
||||
$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');
|
||||
@@ -79,4 +83,51 @@ class PhpFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
(string) $fileResource
|
||||
);
|
||||
}
|
||||
|
||||
public function testRoutingConfigurator()
|
||||
{
|
||||
$locator = new FileLocator(array(__DIR__.'/../Fixtures'));
|
||||
$loader = new PhpFileLoader($locator);
|
||||
$routeCollection = $loader->load('php_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_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('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.php')));
|
||||
|
||||
$this->assertEquals($expectedCollection, $routeCollection);
|
||||
}
|
||||
|
||||
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'));
|
||||
}
|
||||
}
|
||||
|
@@ -11,15 +11,16 @@
|
||||
|
||||
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 \PHPUnit_Framework_TestCase
|
||||
class XmlFileLoaderTest extends TestCase
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new XmlFileLoader($this->getMock('Symfony\Component\Config\FileLocator'));
|
||||
$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');
|
||||
@@ -60,6 +61,7 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$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()
|
||||
@@ -129,4 +131,255 @@ class XmlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$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'));
|
||||
}
|
||||
}
|
||||
|
@@ -11,15 +11,16 @@
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Config\FileLocator;
|
||||
use Symfony\Component\Routing\Loader\YamlFileLoader;
|
||||
use Symfony\Component\Config\Resource\FileResource;
|
||||
use Symfony\Component\Routing\Loader\YamlFileLoader;
|
||||
|
||||
class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
class YamlFileLoaderTest extends TestCase
|
||||
{
|
||||
public function testSupports()
|
||||
{
|
||||
$loader = new YamlFileLoader($this->getMock('Symfony\Component\Config\FileLocator'));
|
||||
$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');
|
||||
@@ -107,4 +108,99 @@ class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
|
||||
$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'));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user