ClosureLoaderTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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\Config\Loader\LoaderResolver;
  12. use Symfony\Component\Routing\Loader\ClosureLoader;
  13. use Symfony\Component\Routing\Route;
  14. use Symfony\Component\Routing\RouteCollection;
  15. class ClosureLoaderTest extends \PHPUnit_Framework_TestCase
  16. {
  17. /**
  18. * @covers Symfony\Component\Routing\Loader\ClosureLoader::supports
  19. */
  20. public function testSupports()
  21. {
  22. $loader = new ClosureLoader();
  23. $closure = function () {};
  24. $this->assertTrue($loader->supports($closure), '->supports() returns true if the resource is loadable');
  25. $this->assertFalse($loader->supports('foo.foo'), '->supports() returns true if the resource is loadable');
  26. $this->assertTrue($loader->supports($closure, 'closure'), '->supports() checks the resource type if specified');
  27. $this->assertFalse($loader->supports($closure, 'foo'), '->supports() checks the resource type if specified');
  28. }
  29. /**
  30. * @covers Symfony\Component\Routing\Loader\ClosureLoader::load
  31. */
  32. public function testLoad()
  33. {
  34. $loader = new ClosureLoader();
  35. $route = new Route('/');
  36. $routes = $loader->load(function () use ($route)
  37. {
  38. $routes = new RouteCollection();
  39. $routes->add('foo', $route);
  40. return $routes;
  41. });
  42. $this->assertEquals($route, $routes->get('foo'), '->load() loads a \Closure resource');
  43. }
  44. }