5d963f86fb01b5ddc0a67e635b7a3699cbeb2c49
[yaffs-website] / routing / Tests / Loader / ClosureLoaderTest.php
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
12 namespace Symfony\Component\Routing\Tests\Loader;
13
14 use PHPUnit\Framework\TestCase;
15 use Symfony\Component\Routing\Loader\ClosureLoader;
16 use Symfony\Component\Routing\Route;
17 use Symfony\Component\Routing\RouteCollection;
18
19 class ClosureLoaderTest extends TestCase
20 {
21     public function testSupports()
22     {
23         $loader = new ClosureLoader();
24
25         $closure = function () {};
26
27         $this->assertTrue($loader->supports($closure), '->supports() returns true if the resource is loadable');
28         $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
29
30         $this->assertTrue($loader->supports($closure, 'closure'), '->supports() checks the resource type if specified');
31         $this->assertFalse($loader->supports($closure, 'foo'), '->supports() checks the resource type if specified');
32     }
33
34     public function testLoad()
35     {
36         $loader = new ClosureLoader();
37
38         $route = new Route('/');
39         $routes = $loader->load(function () use ($route) {
40             $routes = new RouteCollection();
41
42             $routes->add('foo', $route);
43
44             return $routes;
45         });
46
47         $this->assertEquals($route, $routes->get('foo'), '->load() loads a \Closure resource');
48     }
49 }