ClosureLoaderTest.php 1.5 KB

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