4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Routing\Tests\Loader;
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Config\FileLocator;
16 use Symfony\Component\Routing\Loader\PhpFileLoader;
18 class PhpFileLoaderTest extends TestCase
20 public function testSupports()
22 $loader = new PhpFileLoader($this->getMockBuilder('Symfony\Component\Config\FileLocator')->getMock());
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');
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');
31 public function testLoadWithRoute()
33 $loader = new PhpFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
34 $routeCollection = $loader->load('validpattern.php');
35 $routes = $routeCollection->all();
37 $this->assertCount(1, $routes, 'One route is loaded');
38 $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
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());
50 public function testLoadWithImport()
52 $loader = new PhpFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
53 $routeCollection = $loader->load('validresource.php');
54 $routes = $routeCollection->all();
56 $this->assertCount(1, $routes, 'One route is loaded');
57 $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
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());
69 public function testThatDefiningVariableInConfigFileHasNoSideEffects()
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);
79 realpath($locator->locate('with_define_path_variable.php')),
80 (string) $fileResource