CompiledRouteTest.php 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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;
  11. use Symfony\Component\Routing\CompiledRoute;
  12. use Symfony\Component\Routing\Route;
  13. class CompiledRouteTest extends \PHPUnit_Framework_TestCase
  14. {
  15. public function testAccessors()
  16. {
  17. $route = new Route('/{foo}', array('foo' => 'bar'), array('foo' => '\d+'), array('foo' => 'bar'));
  18. $compiled = new CompiledRoute($route, 'prefix', 'regex', array('tokens'), array('variables'));
  19. $this->assertEquals($route, $compiled->getRoute(), '__construct() takes a route as its first argument');
  20. $this->assertEquals('prefix', $compiled->getStaticPrefix(), '__construct() takes a static prefix as its second argument');
  21. $this->assertEquals('regex', $compiled->getRegex(), '__construct() takes a regexp as its third argument');
  22. $this->assertEquals(array('tokens'), $compiled->getTokens(), '__construct() takes an array of tokens as its fourth argument');
  23. $this->assertEquals(array('variables'), $compiled->getVariables(), '__construct() takes an array of variables as its fifth argument');
  24. }
  25. public function testgetPatterngetDefaultsgetOptionsgetRequirements()
  26. {
  27. $route = new Route('/{foo}', array('foo' => 'bar'), array('foo' => '\d+'), array('foo' => 'bar'));
  28. $compiled = new CompiledRoute($route, 'prefix', 'regex', array('tokens'), array('variables'));
  29. $this->assertEquals('/{foo}', $compiled->getPattern(), '->getPattern() returns the route pattern');
  30. $this->assertEquals(array('foo' => 'bar'), $compiled->getDefaults(), '->getDefaults() returns the route defaults');
  31. $this->assertEquals(array('foo' => '\d+'), $compiled->getRequirements(), '->getRequirements() returns the route requirements');
  32. $this->assertEquals(array_merge(array(
  33. 'compiler_class' => 'Symfony\\Component\\Routing\\RouteCompiler',
  34. ), array('foo' => 'bar')), $compiled->getOptions(), '->getOptions() returns the route options');
  35. }
  36. }