RouteTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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\Annotation;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. class RouteTest extends TestCase
  14. {
  15. /**
  16. * @expectedException \BadMethodCallException
  17. */
  18. public function testInvalidRouteParameter()
  19. {
  20. $route = new Route(['foo' => 'bar']);
  21. }
  22. /**
  23. * @expectedException \BadMethodCallException
  24. */
  25. public function testTryingToSetLocalesDirectly()
  26. {
  27. $route = new Route(['locales' => ['nl' => 'bar']]);
  28. }
  29. /**
  30. * @dataProvider getValidParameters
  31. */
  32. public function testRouteParameters($parameter, $value, $getter)
  33. {
  34. $route = new Route([$parameter => $value]);
  35. $this->assertEquals($route->$getter(), $value);
  36. }
  37. public function getValidParameters()
  38. {
  39. return [
  40. ['value', '/Blog', 'getPath'],
  41. ['requirements', ['locale' => 'en'], 'getRequirements'],
  42. ['options', ['compiler_class' => 'RouteCompiler'], 'getOptions'],
  43. ['name', 'blog_index', 'getName'],
  44. ['defaults', ['_controller' => 'MyBlogBundle:Blog:index'], 'getDefaults'],
  45. ['schemes', ['https'], 'getSchemes'],
  46. ['methods', ['GET', 'POST'], 'getMethods'],
  47. ['host', '{locale}.example.com', 'getHost'],
  48. ['condition', 'context.getMethod() == "GET"', 'getCondition'],
  49. ['value', ['nl' => '/hier', 'en' => '/here'], 'getLocalizedPaths'],
  50. ];
  51. }
  52. }