ClosureLoaderTest.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Tests\Component\Routing\Loader;
  11. use Symfony\Component\Routing\Loader\ClosureLoader;
  12. use Symfony\Component\Routing\Route;
  13. use Symfony\Component\Routing\RouteCollection;
  14. class ClosureLoaderTest extends \PHPUnit_Framework_TestCase
  15. {
  16. /**
  17. * @covers Symfony\Component\Routing\Loader\ClosureLoader::supports
  18. */
  19. public function testSupports()
  20. {
  21. $loader = new ClosureLoader();
  22. $closure = function () {};
  23. $this->assertTrue($loader->supports($closure), '->supports() returns true if the resource is loadable');
  24. $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
  25. $this->assertTrue($loader->supports($closure, 'closure'), '->supports() checks the resource type if specified');
  26. $this->assertFalse($loader->supports($closure, 'foo'), '->supports() checks the resource type if specified');
  27. }
  28. /**
  29. * @covers Symfony\Component\Routing\Loader\ClosureLoader::load
  30. */
  31. public function testLoad()
  32. {
  33. $loader = new ClosureLoader();
  34. $route = new Route('/');
  35. $routes = $loader->load(function () use ($route)
  36. {
  37. $routes = new RouteCollection();
  38. $routes->add('foo', $route);
  39. return $routes;
  40. });
  41. $this->assertEquals($route, $routes->get('foo'), '->load() loads a \Closure resource');
  42. }
  43. }