123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154 |
- <?php
- namespace FastRoute\RouteParser;
- use PHPUnit\Framework\TestCase;
- class StdTest extends TestCase
- {
- /** @dataProvider provideTestParse */
- public function testParse($routeString, $expectedRouteDatas)
- {
- $parser = new Std();
- $routeDatas = $parser->parse($routeString);
- $this->assertSame($expectedRouteDatas, $routeDatas);
- }
- /** @dataProvider provideTestParseError */
- public function testParseError($routeString, $expectedExceptionMessage)
- {
- $parser = new Std();
- $this->setExpectedException('FastRoute\\BadRouteException', $expectedExceptionMessage);
- $parser->parse($routeString);
- }
- public function provideTestParse()
- {
- return [
- [
- '/test',
- [
- ['/test'],
- ]
- ],
- [
- '/test/{param}',
- [
- ['/test/', ['param', '[^/]+']],
- ]
- ],
- [
- '/te{ param }st',
- [
- ['/te', ['param', '[^/]+'], 'st']
- ]
- ],
- [
- '/test/{param1}/test2/{param2}',
- [
- ['/test/', ['param1', '[^/]+'], '/test2/', ['param2', '[^/]+']]
- ]
- ],
- [
- '/test/{param:\d+}',
- [
- ['/test/', ['param', '\d+']]
- ]
- ],
- [
- '/test/{ param : \d{1,9} }',
- [
- ['/test/', ['param', '\d{1,9}']]
- ]
- ],
- [
- '/test[opt]',
- [
- ['/test'],
- ['/testopt'],
- ]
- ],
- [
- '/test[/{param}]',
- [
- ['/test'],
- ['/test/', ['param', '[^/]+']],
- ]
- ],
- [
- '/{param}[opt]',
- [
- ['/', ['param', '[^/]+']],
- ['/', ['param', '[^/]+'], 'opt']
- ]
- ],
- [
- '/test[/{name}[/{id:[0-9]+}]]',
- [
- ['/test'],
- ['/test/', ['name', '[^/]+']],
- ['/test/', ['name', '[^/]+'], '/', ['id', '[0-9]+']],
- ]
- ],
- [
- '',
- [
- [''],
- ]
- ],
- [
- '[test]',
- [
- [''],
- ['test'],
- ]
- ],
- [
- '/{foo-bar}',
- [
- ['/', ['foo-bar', '[^/]+']]
- ]
- ],
- [
- '/{_foo:.*}',
- [
- ['/', ['_foo', '.*']]
- ]
- ],
- ];
- }
- public function provideTestParseError()
- {
- return [
- [
- '/test[opt',
- "Number of opening '[' and closing ']' does not match"
- ],
- [
- '/test[opt[opt2]',
- "Number of opening '[' and closing ']' does not match"
- ],
- [
- '/testopt]',
- "Number of opening '[' and closing ']' does not match"
- ],
- [
- '/test[]',
- 'Empty optional part'
- ],
- [
- '/test[[opt]]',
- 'Empty optional part'
- ],
- [
- '[[test]]',
- 'Empty optional part'
- ],
- [
- '/test[/opt]/required',
- 'Optional segments can only occur at the end of a route'
- ],
- ];
- }
- }
|