Laravel 5.6 updates
Travis config update Removed HHVM script as Laravel no longer support HHVM after releasing 5.3
This commit is contained in:
@@ -11,35 +11,46 @@
|
||||
|
||||
namespace Symfony\Component\Routing\Tests\Loader;
|
||||
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
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
|
||||
{
|
||||
protected $loader;
|
||||
private $reader;
|
||||
/**
|
||||
* @var AnnotationClassLoader
|
||||
*/
|
||||
private $loader;
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->reader = $this->getReader();
|
||||
$this->loader = $this->getClassLoader($this->reader);
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testLoadMissingClass()
|
||||
{
|
||||
$this->loader->load('MissingClass');
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testLoadAbstractClass()
|
||||
{
|
||||
$this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\AbstractClass');
|
||||
$reader = new AnnotationReader();
|
||||
$this->loader = new class($reader) extends AnnotationClassLoader {
|
||||
protected function configureRoute(Route $route, \ReflectionClass $class, \ReflectionMethod $method, $annot)
|
||||
{
|
||||
}
|
||||
};
|
||||
AnnotationRegistry::registerLoader('class_exists');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,144 +80,92 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
||||
$this->assertFalse($this->loader->supports('class', 'foo'), '->supports() checks the resource type if specified');
|
||||
}
|
||||
|
||||
public function getLoadTests()
|
||||
public function testSimplePathRoute()
|
||||
{
|
||||
return array(
|
||||
array(
|
||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
|
||||
array('name' => 'route1', 'path' => '/path'),
|
||||
array('arg2' => 'defaultValue2', 'arg3' => 'defaultValue3'),
|
||||
),
|
||||
array(
|
||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
|
||||
array('defaults' => array('arg2' => 'foo'), 'requirements' => array('arg3' => '\w+')),
|
||||
array('arg2' => 'defaultValue2', 'arg3' => 'defaultValue3'),
|
||||
),
|
||||
array(
|
||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
|
||||
array('options' => array('foo' => 'bar')),
|
||||
array('arg2' => 'defaultValue2', 'arg3' => 'defaultValue3'),
|
||||
),
|
||||
array(
|
||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
|
||||
array('schemes' => array('https'), 'methods' => array('GET')),
|
||||
array('arg2' => 'defaultValue2', 'arg3' => 'defaultValue3'),
|
||||
),
|
||||
array(
|
||||
'Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BarClass',
|
||||
array('condition' => 'context.getMethod() == "GET"'),
|
||||
array('arg2' => 'defaultValue2', 'arg3' => 'defaultValue3'),
|
||||
),
|
||||
);
|
||||
$routes = $this->loader->load(ActionPathController::class);
|
||||
$this->assertCount(1, $routes);
|
||||
$this->assertEquals('/path', $routes->get('action')->getPath());
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getLoadTests
|
||||
*/
|
||||
public function testLoad($className, $routeData = array(), $methodArgs = array())
|
||||
public function testInvokableControllerLoader()
|
||||
{
|
||||
$routeData = array_replace(array(
|
||||
'name' => 'route',
|
||||
'path' => '/',
|
||||
'requirements' => array(),
|
||||
'options' => array(),
|
||||
'defaults' => array(),
|
||||
'schemes' => array(),
|
||||
'methods' => array(),
|
||||
'condition' => '',
|
||||
), $routeData);
|
||||
|
||||
$this->reader
|
||||
->expects($this->once())
|
||||
->method('getMethodAnnotations')
|
||||
->will($this->returnValue(array($this->getAnnotatedRoute($routeData))))
|
||||
;
|
||||
|
||||
$routeCollection = $this->loader->load($className);
|
||||
$route = $routeCollection->get($routeData['name']);
|
||||
|
||||
$this->assertSame($routeData['path'], $route->getPath(), '->load preserves path annotation');
|
||||
$this->assertCount(
|
||||
\count($routeData['requirements']),
|
||||
array_intersect_assoc($routeData['requirements'], $route->getRequirements()),
|
||||
'->load preserves requirements annotation'
|
||||
);
|
||||
$this->assertCount(
|
||||
\count($routeData['options']),
|
||||
array_intersect_assoc($routeData['options'], $route->getOptions()),
|
||||
'->load preserves options annotation'
|
||||
);
|
||||
$this->assertCount(
|
||||
\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');
|
||||
$this->assertSame($routeData['condition'], $route->getCondition(), '->load preserves condition annotation');
|
||||
$routes = $this->loader->load(InvokableController::class);
|
||||
$this->assertCount(1, $routes);
|
||||
$this->assertEquals('/here', $routes->get('lol')->getPath());
|
||||
}
|
||||
|
||||
public function testClassRouteLoad()
|
||||
public function testInvokableLocalizedControllerLoading()
|
||||
{
|
||||
$classRouteData = array(
|
||||
'name' => 'prefix_',
|
||||
'path' => '/prefix',
|
||||
'schemes' => array('https'),
|
||||
'methods' => array('GET'),
|
||||
);
|
||||
|
||||
$methodRouteData = array(
|
||||
'name' => 'route1',
|
||||
'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\BarClass');
|
||||
$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');
|
||||
$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 testInvokableClassRouteLoad()
|
||||
public function testLocalizedPathRoutes()
|
||||
{
|
||||
$classRouteData = array(
|
||||
'name' => 'route1',
|
||||
'path' => '/',
|
||||
'schemes' => array('https'),
|
||||
'methods' => array('GET'),
|
||||
);
|
||||
$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());
|
||||
}
|
||||
|
||||
$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()))
|
||||
;
|
||||
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());
|
||||
}
|
||||
|
||||
$routeCollection = $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass');
|
||||
$route = $routeCollection->get($classRouteData['name']);
|
||||
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'));
|
||||
}
|
||||
|
||||
$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 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()
|
||||
@@ -225,18 +184,24 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
||||
'methods' => array('GET'),
|
||||
);
|
||||
|
||||
$this->reader
|
||||
$reader = $this->getReader();
|
||||
$reader
|
||||
->expects($this->exactly(1))
|
||||
->method('getClassAnnotations')
|
||||
->will($this->returnValue(array($this->getAnnotatedRoute($classRouteData1), $this->getAnnotatedRoute($classRouteData2))))
|
||||
->will($this->returnValue(array(new RouteAnnotation($classRouteData1), new RouteAnnotation($classRouteData2))))
|
||||
;
|
||||
$this->reader
|
||||
$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 = $this->loader->load('Symfony\Component\Routing\Tests\Fixtures\AnnotatedClasses\BazClass');
|
||||
$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');
|
||||
@@ -250,47 +215,56 @@ class AnnotationClassLoaderTest extends AbstractAnnotationLoaderTest
|
||||
$this->assertEquals($classRouteData2['methods'], $route->getMethods(), '->load preserves class route methods');
|
||||
}
|
||||
|
||||
public function testInvokableClassWithMethodRouteLoad()
|
||||
public function testMissingPrefixLocale()
|
||||
{
|
||||
$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');
|
||||
$this->assertEquals(array_merge($classRouteData['methods'], $methodRouteData['methods']), $route->getMethods(), '->load merges class and method route methods');
|
||||
$this->expectException(\LogicException::class);
|
||||
$this->loader->load(LocalizedPrefixMissingLocaleActionController::class);
|
||||
}
|
||||
|
||||
private function getAnnotatedRoute($data)
|
||||
public function testMissingRouteLocale()
|
||||
{
|
||||
return new Route($data);
|
||||
$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());
|
||||
}
|
||||
}
|
||||
|
@@ -35,9 +35,6 @@ class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
|
||||
$this->loader->load(__DIR__.'/../Fixtures/AnnotatedClasses/FooClass.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.4
|
||||
*/
|
||||
public function testLoadTraitWithClassConstant()
|
||||
{
|
||||
$this->reader->expects($this->never())->method('getClassAnnotation');
|
||||
@@ -54,9 +51,6 @@ class AnnotationFileLoaderTest extends AbstractAnnotationLoaderTest
|
||||
$this->loader->load(__DIR__.'/../Fixtures/OtherAnnotatedClasses/NoStartTagClass.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* @requires PHP 5.6
|
||||
*/
|
||||
public function testLoadVariadic()
|
||||
{
|
||||
$route = new Route(array('path' => '/path/to/{id}'));
|
||||
|
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;
|
||||
}
|
||||
}
|
@@ -18,7 +18,11 @@ use Symfony\Component\Routing\RouteCollection;
|
||||
|
||||
class ObjectRouteLoaderTest extends TestCase
|
||||
{
|
||||
public function testLoadCallsServiceAndReturnsCollection()
|
||||
/**
|
||||
* @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();
|
||||
|
||||
@@ -40,6 +44,28 @@ class ObjectRouteLoaderTest extends TestCase
|
||||
$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
|
||||
@@ -54,7 +80,6 @@ class ObjectRouteLoaderTest extends TestCase
|
||||
{
|
||||
return array(
|
||||
array('Foo'),
|
||||
array('Bar::baz'),
|
||||
array('Foo:Bar:baz'),
|
||||
);
|
||||
}
|
||||
@@ -66,7 +91,7 @@ class ObjectRouteLoaderTest extends TestCase
|
||||
{
|
||||
$loader = new ObjectRouteLoaderForTest();
|
||||
$loader->loaderMap = array('my_service' => 'NOT_AN_OBJECT');
|
||||
$loader->load('my_service:method');
|
||||
$loader->load('my_service::method');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,7 +101,7 @@ class ObjectRouteLoaderTest extends TestCase
|
||||
{
|
||||
$loader = new ObjectRouteLoaderForTest();
|
||||
$loader->loaderMap = array('my_service' => new \stdClass());
|
||||
$loader->load('my_service:method');
|
||||
$loader->load('my_service::method');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -93,7 +118,7 @@ class ObjectRouteLoaderTest extends TestCase
|
||||
|
||||
$loader = new ObjectRouteLoaderForTest();
|
||||
$loader->loaderMap = array('my_service' => $service);
|
||||
$loader->load('my_service:loadRoutes');
|
||||
$loader->load('my_service::loadRoutes');
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -88,7 +88,8 @@ class PhpFileLoaderTest extends TestCase
|
||||
{
|
||||
$locator = new FileLocator(array(__DIR__.'/../Fixtures'));
|
||||
$loader = new PhpFileLoader($locator);
|
||||
$routeCollection = $loader->load('php_dsl.php');
|
||||
$routeCollectionClosure = $loader->load('php_dsl.php');
|
||||
$routeCollectionObject = $loader->load('php_object_dsl.php');
|
||||
|
||||
$expectedCollection = new RouteCollection();
|
||||
|
||||
@@ -99,6 +100,9 @@ class PhpFileLoaderTest extends TestCase
|
||||
$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+'))
|
||||
);
|
||||
@@ -106,6 +110,11 @@ class PhpFileLoaderTest extends TestCase
|
||||
->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'))
|
||||
@@ -113,9 +122,16 @@ class PhpFileLoaderTest extends TestCase
|
||||
);
|
||||
|
||||
$expectedCollection->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_dsl_sub.php')));
|
||||
$expectedCollection->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_dsl.php')));
|
||||
$expectedCollection->addResource(new FileResource(realpath(__DIR__.'/../Fixtures/php_dsl_sub_root.php')));
|
||||
|
||||
$this->assertEquals($expectedCollection, $routeCollection);
|
||||
$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()
|
||||
@@ -130,4 +146,24 @@ class PhpFileLoaderTest extends TestCase
|
||||
$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);
|
||||
}
|
||||
}
|
||||
|
@@ -83,6 +83,45 @@ class XmlFileLoaderTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
@@ -382,4 +421,24 @@ class XmlFileLoaderTest extends TestCase
|
||||
$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());
|
||||
}
|
||||
}
|
||||
|
@@ -203,4 +203,105 @@ class YamlFileLoaderTest extends TestCase
|
||||
$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