RouteTest.php 1.4 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\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. * @dataProvider getValidParameters
  24. */
  25. public function testRouteParameters($parameter, $value, $getter)
  26. {
  27. $route = new Route([$parameter => $value]);
  28. $this->assertEquals($route->$getter(), $value);
  29. }
  30. public function getValidParameters()
  31. {
  32. return [
  33. ['value', '/Blog', 'getPath'],
  34. ['requirements', ['locale' => 'en'], 'getRequirements'],
  35. ['options', ['compiler_class' => 'RouteCompiler'], 'getOptions'],
  36. ['name', 'blog_index', 'getName'],
  37. ['defaults', ['_controller' => 'MyBlogBundle:Blog:index'], 'getDefaults'],
  38. ['schemes', ['https'], 'getSchemes'],
  39. ['methods', ['GET', 'POST'], 'getMethods'],
  40. ['host', '{locale}.example.com', 'getHost'],
  41. ['condition', 'context.getMethod() == "GET"', 'getCondition'],
  42. ];
  43. }
  44. }