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\Component\Routing\Tests\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. protected function setUp()
  17. {
  18. if (!class_exists('Symfony\Component\Config\FileLocator')) {
  19. $this->markTestSkipped('The "Config" component is not available');
  20. }
  21. }
  22. public function testSupports()
  23. {
  24. $loader = new ClosureLoader();
  25. $closure = function () {};
  26. $this->assertTrue($loader->supports($closure), '->supports() returns true if the resource is loadable');
  27. $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
  28. $this->assertTrue($loader->supports($closure, 'closure'), '->supports() checks the resource type if specified');
  29. $this->assertFalse($loader->supports($closure, 'foo'), '->supports() checks the resource type if specified');
  30. }
  31. public function testLoad()
  32. {
  33. $loader = new ClosureLoader();
  34. $route = new Route('/');
  35. $routes = $loader->load(function () use ($route) {
  36. $routes = new RouteCollection();
  37. $routes->add('foo', $route);
  38. return $routes;
  39. });
  40. $this->assertEquals($route, $routes->get('foo'), '->load() loads a \Closure resource');
  41. }
  42. }