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());
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user