PhpMatcherDumperTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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\Matcher\Dumper\PhpMatcherDumper;
  12. use Symfony\Component\Routing\Route;
  13. use Symfony\Component\Routing\RouteCollection;
  14. class PhpMatcherDumperTest 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. // simple
  37. $collection->add('baz', new Route(
  38. '/test/baz'
  39. ));
  40. // simple with extension
  41. $collection->add('baz2', new Route(
  42. '/test/baz.html'
  43. ));
  44. // trailing slash
  45. $collection->add('baz3', new Route(
  46. '/test/baz3/'
  47. ));
  48. // trailing slash with variable
  49. $collection->add('baz4', new Route(
  50. '/test/{foo}/'
  51. ));
  52. // trailing slash and method
  53. $collection->add('baz5', new Route(
  54. '/test/{foo}/',
  55. array(),
  56. array('_method' => 'post')
  57. ));
  58. // complex name
  59. $collection->add('baz.baz6', new Route(
  60. '/test/{foo}/',
  61. array(),
  62. array('_method' => 'put')
  63. ));
  64. // defaults without variable
  65. $collection->add('foofoo', new Route(
  66. '/foofoo',
  67. array('def' => 'test')
  68. ));
  69. $dumper = new PhpMatcherDumper($collection);
  70. $this->assertStringEqualsFile(self::$fixturesPath.'/dumper/url_matcher1.php', $dumper->dump(), '->dump() dumps basic routes to the correct PHP file.');
  71. }
  72. }