ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
StdTest.php
Go to the documentation of this file.
1 <?php
2 
3 namespace FastRoute\RouteParser;
4 
6 
7 class StdTest extends TestCase
8 {
10  public function testParse($routeString, $expectedRouteDatas)
11  {
12  $parser = new Std();
13  $routeDatas = $parser->parse($routeString);
14  $this->assertSame($expectedRouteDatas, $routeDatas);
15  }
16 
18  public function testParseError($routeString, $expectedExceptionMessage)
19  {
20  $parser = new Std();
21  $this->setExpectedException('FastRoute\\BadRouteException', $expectedExceptionMessage);
22  $parser->parse($routeString);
23  }
24 
25  public function provideTestParse()
26  {
27  return [
28  [
29  '/test',
30  [
31  ['/test'],
32  ]
33  ],
34  [
35  '/test/{param}',
36  [
37  ['/test/', ['param', '[^/]+']],
38  ]
39  ],
40  [
41  '/te{ param }st',
42  [
43  ['/te', ['param', '[^/]+'], 'st']
44  ]
45  ],
46  [
47  '/test/{param1}/test2/{param2}',
48  [
49  ['/test/', ['param1', '[^/]+'], '/test2/', ['param2', '[^/]+']]
50  ]
51  ],
52  [
53  '/test/{param:\d+}',
54  [
55  ['/test/', ['param', '\d+']]
56  ]
57  ],
58  [
59  '/test/{ param : \d{1,9} }',
60  [
61  ['/test/', ['param', '\d{1,9}']]
62  ]
63  ],
64  [
65  '/test[opt]',
66  [
67  ['/test'],
68  ['/testopt'],
69  ]
70  ],
71  [
72  '/test[/{param}]',
73  [
74  ['/test'],
75  ['/test/', ['param', '[^/]+']],
76  ]
77  ],
78  [
79  '/{param}[opt]',
80  [
81  ['/', ['param', '[^/]+']],
82  ['/', ['param', '[^/]+'], 'opt']
83  ]
84  ],
85  [
86  '/test[/{name}[/{id:[0-9]+}]]',
87  [
88  ['/test'],
89  ['/test/', ['name', '[^/]+']],
90  ['/test/', ['name', '[^/]+'], '/', ['id', '[0-9]+']],
91  ]
92  ],
93  [
94  '',
95  [
96  [''],
97  ]
98  ],
99  [
100  '[test]',
101  [
102  [''],
103  ['test'],
104  ]
105  ],
106  [
107  '/{foo-bar}',
108  [
109  ['/', ['foo-bar', '[^/]+']]
110  ]
111  ],
112  [
113  '/{_foo:.*}',
114  [
115  ['/', ['_foo', '.*']]
116  ]
117  ],
118  ];
119  }
120 
121  public function provideTestParseError()
122  {
123  return [
124  [
125  '/test[opt',
126  "Number of opening '[' and closing ']' does not match"
127  ],
128  [
129  '/test[opt[opt2]',
130  "Number of opening '[' and closing ']' does not match"
131  ],
132  [
133  '/testopt]',
134  "Number of opening '[' and closing ']' does not match"
135  ],
136  [
137  '/test[]',
138  'Empty optional part'
139  ],
140  [
141  '/test[[opt]]',
142  'Empty optional part'
143  ],
144  [
145  '[[test]]',
146  'Empty optional part'
147  ],
148  [
149  '/test[/opt]/required',
150  'Optional segments can only occur at the end of a route'
151  ],
152  ];
153  }
154 }
testParseError($routeString, $expectedExceptionMessage)
provideTestParseError
Definition: StdTest.php:18
$parser
Definition: BPMN2Parser.php:23
testParse($routeString, $expectedRouteDatas)
provideTestParse
Definition: StdTest.php:10