1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10:
11:
12: namespace Symfony\Component\Routing\Tests\Loader;
13:
14: use PHPUnit\Framework\TestCase;
15: use Symfony\Component\Config\FileLocator;
16: use Symfony\Component\Routing\Loader\PhpFileLoader;
17:
18: class PhpFileLoaderTest extends TestCase
19: {
20: public function testSupports()
21: {
22: $loader = new PhpFileLoader($this->getMockBuilder('Symfony\Component\Config\FileLocator')->getMock());
23:
24: $this->assertTrue($loader->supports('foo.php'), '->supports() returns true if the resource is loadable');
25: $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
26:
27: $this->assertTrue($loader->supports('foo.php', 'php'), '->supports() checks the resource type if specified');
28: $this->assertFalse($loader->supports('foo.php', 'foo'), '->supports() checks the resource type if specified');
29: }
30:
31: public function testLoadWithRoute()
32: {
33: $loader = new PhpFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
34: $routeCollection = $loader->load('validpattern.php');
35: $routes = $routeCollection->all();
36:
37: $this->assertCount(1, $routes, 'One route is loaded');
38: $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
39:
40: foreach ($routes as $route) {
41: $this->assertSame('/blog/{slug}', $route->getPath());
42: $this->assertSame('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
43: $this->assertSame('{locale}.example.com', $route->getHost());
44: $this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
45: $this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
46: $this->assertEquals(array('https'), $route->getSchemes());
47: }
48: }
49:
50: public function testLoadWithImport()
51: {
52: $loader = new PhpFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
53: $routeCollection = $loader->load('validresource.php');
54: $routes = $routeCollection->all();
55:
56: $this->assertCount(1, $routes, 'One route is loaded');
57: $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
58:
59: foreach ($routes as $route) {
60: $this->assertSame('/prefix/blog/{slug}', $route->getPath());
61: $this->assertSame('MyBlogBundle:Blog:show', $route->getDefault('_controller'));
62: $this->assertSame('{locale}.example.com', $route->getHost());
63: $this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
64: $this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
65: $this->assertEquals(array('https'), $route->getSchemes());
66: }
67: }
68:
69: public function testThatDefiningVariableInConfigFileHasNoSideEffects()
70: {
71: $locator = new FileLocator(array(__DIR__.'/../Fixtures'));
72: $loader = new PhpFileLoader($locator);
73: $routeCollection = $loader->load('with_define_path_variable.php');
74: $resources = $routeCollection->getResources();
75: $this->assertCount(1, $resources);
76: $this->assertContainsOnly('Symfony\Component\Config\Resource\ResourceInterface', $resources);
77: $fileResource = reset($resources);
78: $this->assertSame(
79: realpath($locator->locate('with_define_path_variable.php')),
80: (string) $fileResource
81: );
82: }
83: }
84: