]> git.immae.eu Git - github/wallabag/wallabag.git/blame - vendor/symfony/routing/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php
gitignore vendor
[github/wallabag/wallabag.git] / vendor / symfony / routing / Symfony / Component / Routing / Tests / Loader / YamlFileLoaderTest.php
CommitLineData
4f5b44bd
NL
1<?php
2
3/*
4 * This file is part of the Symfony package.
5 *
6 * (c) Fabien Potencier <fabien@symfony.com>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12namespace Symfony\Component\Routing\Tests\Loader;
13
14use Symfony\Component\Config\FileLocator;
15use Symfony\Component\Routing\Loader\YamlFileLoader;
16use Symfony\Component\Config\Resource\FileResource;
17
18class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase
19{
20 protected function setUp()
21 {
22 if (!class_exists('Symfony\Component\Config\FileLocator')) {
23 $this->markTestSkipped('The "Config" component is not available');
24 }
25
26 if (!class_exists('Symfony\Component\Yaml\Yaml')) {
27 $this->markTestSkipped('The "Yaml" component is not available');
28 }
29 }
30
31 public function testSupports()
32 {
33 $loader = new YamlFileLoader($this->getMock('Symfony\Component\Config\FileLocator'));
34
35 $this->assertTrue($loader->supports('foo.yml'), '->supports() returns true if the resource is loadable');
36 $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
37
38 $this->assertTrue($loader->supports('foo.yml', 'yaml'), '->supports() checks the resource type if specified');
39 $this->assertFalse($loader->supports('foo.yml', 'foo'), '->supports() checks the resource type if specified');
40 }
41
42 public function testLoadDoesNothingIfEmpty()
43 {
44 $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
45 $collection = $loader->load('empty.yml');
46
47 $this->assertEquals(array(), $collection->all());
48 $this->assertEquals(array(new FileResource(realpath(__DIR__.'/../Fixtures/empty.yml'))), $collection->getResources());
49 }
50
51 /**
52 * @expectedException \InvalidArgumentException
53 * @dataProvider getPathsToInvalidFiles
54 */
55 public function testLoadThrowsExceptionWithInvalidFile($filePath)
56 {
57 $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
58 $loader->load($filePath);
59 }
60
61 public function getPathsToInvalidFiles()
62 {
63 return array(array('nonvalid.yml'), array('nonvalid2.yml'), array('incomplete.yml'), array('nonvalidkeys.yml'), array('nonesense_resource_plus_path.yml'), array('nonesense_type_without_resource.yml'));
64 }
65
66 public function testLoadSpecialRouteName()
67 {
68 $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
69 $routeCollection = $loader->load('special_route_name.yml');
70 $route = $routeCollection->get('#$péß^a|');
71
72 $this->assertInstanceOf('Symfony\Component\Routing\Route', $route);
73 $this->assertSame('/true', $route->getPath());
74 }
75
76 public function testLoadWithRoute()
77 {
78 $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
79 $routeCollection = $loader->load('validpattern.yml');
80 $routes = $routeCollection->all();
81
82 $this->assertCount(2, $routes, 'Two routes are loaded');
83 $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
84
85 foreach ($routes as $route) {
86 $this->assertSame('/blog/{slug}', $route->getPath());
87 $this->assertSame('{locale}.example.com', $route->getHost());
88 $this->assertSame('MyBundle:Blog:show', $route->getDefault('_controller'));
89 $this->assertSame('\w+', $route->getRequirement('locale'));
90 $this->assertSame('RouteCompiler', $route->getOption('compiler_class'));
91 $this->assertEquals(array('GET', 'POST', 'PUT', 'OPTIONS'), $route->getMethods());
92 $this->assertEquals(array('https'), $route->getSchemes());
93 }
94 }
95
96 public function testLoadWithResource()
97 {
98 $loader = new YamlFileLoader(new FileLocator(array(__DIR__.'/../Fixtures')));
99 $routeCollection = $loader->load('validresource.yml');
100 $routes = $routeCollection->all();
101
102 $this->assertCount(2, $routes, 'Two routes are loaded');
103 $this->assertContainsOnly('Symfony\Component\Routing\Route', $routes);
104
105 foreach ($routes as $route) {
106 $this->assertSame('/{foo}/blog/{slug}', $route->getPath());
107 $this->assertSame('123', $route->getDefault('foo'));
108 $this->assertSame('\d+', $route->getRequirement('foo'));
109 $this->assertSame('bar', $route->getOption('foo'));
110 $this->assertSame('', $route->getHost());
111 }
112 }
113}