ApacheMatcherDumperTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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\Route;
  12. use Symfony\Component\Routing\RouteCollection;
  13. use Symfony\Component\Routing\Matcher\Dumper\ApacheMatcherDumper;
  14. class ApacheMatcherDumperTest extends \PHPUnit_Framework_TestCase
  15. {
  16. static protected $fixturesPath;
  17. static public function setUpBeforeClass()
  18. {
  19. self::$fixturesPath = realpath(__DIR__.'/../../Fixtures/');
  20. }
  21. public function testDump()
  22. {
  23. $collection = new RouteCollection();
  24. // defaults and requirements
  25. $collection->add('foo', new Route(
  26. '/foo/{bar}',
  27. array('def' => 'test'),
  28. array('bar' => 'baz|symfony')
  29. ));
  30. // method requirement
  31. $collection->add('bar', new Route(
  32. '/bar/{foo}',
  33. array(),
  34. array('_method' => 'GET|head')
  35. ));
  36. // method requirement (again)
  37. $collection->add('baragain', new Route(
  38. '/baragain/{foo}',
  39. array(),
  40. array('_method' => 'get|post')
  41. ));
  42. // simple
  43. $collection->add('baz', new Route(
  44. '/test/baz'
  45. ));
  46. // simple with extension
  47. $collection->add('baz2', new Route(
  48. '/test/baz.html'
  49. ));
  50. // trailing slash
  51. $collection->add('baz3', new Route(
  52. '/test/baz3/'
  53. ));
  54. // trailing slash with variable
  55. $collection->add('baz4', new Route(
  56. '/test/{foo}/'
  57. ));
  58. // trailing slash and method
  59. $collection->add('baz5', new Route(
  60. '/test/{foo}/',
  61. array(),
  62. array('_method' => 'post')
  63. ));
  64. // complex
  65. $collection->add('baz6', new Route(
  66. '/test/baz',
  67. array('foo' => 'bar baz')
  68. ));
  69. $dumper = new ApacheMatcherDumper($collection);
  70. $this->assertStringEqualsFile(self::$fixturesPath.'/dumper/url_matcher1.apache', $dumper->dump(), '->dump() dumps basic routes to the correct apache format.');
  71. }
  72. }