ClosureLoaderTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. $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. }