ApacheUrlMatcherTest.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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\Matcher;
  11. use Symfony\Component\Routing\RouteCollection;
  12. use Symfony\Component\Routing\RequestContext;
  13. use Symfony\Component\Routing\Matcher\ApacheUrlMatcher;
  14. class ApacheUrlMatcherTest extends \PHPUnit_Framework_TestCase
  15. {
  16. /**
  17. * @dataProvider getMatchData
  18. */
  19. public function testMatch($name, $pathinfo, $server, $expect)
  20. {
  21. $collection = new RouteCollection();
  22. $context = new RequestContext();
  23. $matcher = new ApacheUrlMatcher($collection, $context);
  24. $_SERVER = $server;
  25. $result = $matcher->match($pathinfo, $server);
  26. $this->assertSame(var_export($expect, true), var_export($result, true));
  27. }
  28. public function getMatchData()
  29. {
  30. return array(
  31. array(
  32. 'Simple route',
  33. '/hello/world',
  34. array(
  35. '_ROUTING__route' => 'hello',
  36. '_ROUTING__controller' => 'AcmeBundle:Default:index',
  37. '_ROUTING_name' => 'world',
  38. ),
  39. array(
  40. '_route' => 'hello',
  41. '_controller' => 'AcmeBundle:Default:index',
  42. 'name' => 'world',
  43. ),
  44. ),
  45. array(
  46. 'Route with params and defaults',
  47. '/hello/hugo',
  48. array(
  49. '_ROUTING__route' => 'hello',
  50. '_ROUTING__controller' => 'AcmeBundle:Default:index',
  51. '_ROUTING_name' => 'hugo',
  52. '_ROUTING_DEFAULTS_name' => 'world',
  53. ),
  54. array(
  55. 'name' => 'hugo',
  56. '_route' => 'hello',
  57. '_controller' => 'AcmeBundle:Default:index',
  58. ),
  59. ),
  60. array(
  61. 'Route with defaults only',
  62. '/hello',
  63. array(
  64. '_ROUTING__route' => 'hello',
  65. '_ROUTING__controller' => 'AcmeBundle:Default:index',
  66. '_ROUTING_DEFAULTS_name' => 'world',
  67. ),
  68. array(
  69. 'name' => 'world',
  70. '_route' => 'hello',
  71. '_controller' => 'AcmeBundle:Default:index',
  72. ),
  73. ),
  74. array(
  75. 'REDIRECT_ envs',
  76. '/hello/world',
  77. array(
  78. 'REDIRECT__ROUTING__route' => 'hello',
  79. 'REDIRECT__ROUTING__controller' => 'AcmeBundle:Default:index',
  80. 'REDIRECT__ROUTING_name' => 'world',
  81. ),
  82. array(
  83. '_route' => 'hello',
  84. '_controller' => 'AcmeBundle:Default:index',
  85. 'name' => 'world',
  86. ),
  87. ),
  88. );
  89. }
  90. }