Passed
Branch release/v2.0.0 (c6ab93)
by Anatoly
04:19
created
tests/RouteCollectionTest.php 1 patch
Indentation   +327 added lines, -327 removed lines patch added patch discarded remove patch
@@ -21,331 +21,331 @@
 block discarded – undo
21 21
 class RouteCollectionTest extends TestCase
22 22
 {
23 23
 
24
-    /**
25
-     * @return void
26
-     */
27
-    public function testConstructor() : void
28
-    {
29
-        $collection = new RouteCollection();
30
-
31
-        $this->assertInstanceOf(RouteCollectionInterface::class, $collection);
32
-    }
33
-
34
-    /**
35
-     * @return void
36
-     */
37
-    public function testGetDefaultPrefix() : void
38
-    {
39
-        $collection = new RouteCollection();
40
-
41
-        $this->assertNull($collection->getPrefix());
42
-    }
43
-
44
-    /**
45
-     * @return void
46
-     */
47
-    public function testGetDefaultMiddlewares() : void
48
-    {
49
-        $collection = new RouteCollection();
50
-
51
-        $this->assertSame([], $collection->getMiddlewares());
52
-    }
53
-
54
-    /**
55
-     * @return void
56
-     */
57
-    public function testGetDefaultRoutes() : void
58
-    {
59
-        $collection = new RouteCollection();
60
-
61
-        $this->assertSame([], $collection->getRoutes());
62
-    }
63
-
64
-    /**
65
-     * @return void
66
-     */
67
-    public function testSetPrefix() : void
68
-    {
69
-        $collection = new RouteCollection();
70
-
71
-        $this->assertSame($collection, $collection->setPrefix('/foo'));
72
-        $this->assertSame('/foo', $collection->getPrefix());
73
-
74
-        // override prefix...
75
-        $collection->setPrefix('/bar');
76
-        $this->assertSame('/bar', $collection->getPrefix());
77
-
78
-        // https://github.com/sunrise-php/http-router/issues/26
79
-        $collection->setPrefix('/baz/');
80
-        $this->assertSame('/baz', $collection->getPrefix());
81
-    }
82
-
83
-    /**
84
-     * @return void
85
-     */
86
-    public function testAddMiddlewares() : void
87
-    {
88
-        $middlewares = [
89
-            new Fixture\BlankMiddleware(),
90
-            new Fixture\BlankMiddleware(),
91
-        ];
92
-
93
-        $collection = new RouteCollection();
94
-
95
-        $this->assertSame($collection, $collection->addMiddlewares(...$middlewares));
96
-        $this->assertSame($middlewares, $collection->getMiddlewares());
97
-
98
-        // extending...
99
-        $middlewares[] = new Fixture\BlankMiddleware();
100
-        $collection->addMiddlewares(end($middlewares));
101
-        $this->assertSame($middlewares, $collection->getMiddlewares());
102
-    }
103
-
104
-    /**
105
-     * @return void
106
-     */
107
-    public function testAddRoutes() : void
108
-    {
109
-        $routes = [
110
-            new Fixture\TestRoute(),
111
-            new Fixture\TestRoute(),
112
-        ];
113
-
114
-        $collection = new RouteCollection();
115
-
116
-        $this->assertSame($collection, $collection->addRoutes(...$routes));
117
-        $this->assertSame($routes, $collection->getRoutes());
118
-
119
-        // extending...
120
-        $routes[] = new Fixture\TestRoute();
121
-        $collection->addRoutes(end($routes));
122
-        $this->assertSame($routes, $collection->getRoutes());
123
-    }
124
-
125
-    /**
126
-     * @return void
127
-     */
128
-    public function testMakeRoute() : void
129
-    {
130
-        $routeName = Fixture\TestRoute::getTestRouteName();
131
-        $routePath = Fixture\TestRoute::getTestRoutePath();
132
-        $routeMethods = Fixture\TestRoute::getTestRouteMethods();
133
-        $routeRequestHandler = Fixture\TestRoute::getTestRouteRequestHandler();
134
-
135
-        $collection = new RouteCollection();
136
-
137
-        $route = $collection->route(
138
-            $routeName,
139
-            $routePath,
140
-            $routeMethods,
141
-            $routeRequestHandler
142
-        );
143
-
144
-        $this->assertInstanceOf(RouteInterface::class, $route);
145
-        $this->assertSame($routeName, $route->getName());
146
-        $this->assertSame($routePath, $route->getPath());
147
-        $this->assertSame($routeMethods, $route->getMethods());
148
-        $this->assertSame($routeRequestHandler, $route->getRequestHandler());
149
-        $this->assertSame([], $route->getMiddlewares());
150
-        $this->assertSame([], $route->getAttributes());
151
-        $this->assertSame([$route], $collection->getRoutes());
152
-    }
153
-
154
-    /**
155
-     * @return void
156
-     */
157
-    public function testMakeRouteWithOptionalParams() : void
158
-    {
159
-        $routeName = Fixture\TestRoute::getTestRouteName();
160
-        $routePath = Fixture\TestRoute::getTestRoutePath();
161
-        $routeMethods = Fixture\TestRoute::getTestRouteMethods();
162
-        $routeRequestHandler = Fixture\TestRoute::getTestRouteRequestHandler();
163
-        $routeMiddlewares = Fixture\TestRoute::getTestRouteMiddlewares();
164
-        $routeAttributes = Fixture\TestRoute::getTestRouteAttributes();
165
-
166
-        $collection = new RouteCollection();
167
-
168
-        $route = $collection->route(
169
-            $routeName,
170
-            $routePath,
171
-            $routeMethods,
172
-            $routeRequestHandler,
173
-            $routeMiddlewares,
174
-            $routeAttributes
175
-        );
176
-
177
-        $this->assertInstanceOf(RouteInterface::class, $route);
178
-        $this->assertSame($routeName, $route->getName());
179
-        $this->assertSame($routePath, $route->getPath());
180
-        $this->assertSame($routeMethods, $route->getMethods());
181
-        $this->assertSame($routeRequestHandler, $route->getRequestHandler());
182
-        $this->assertSame($routeMiddlewares, $route->getMiddlewares());
183
-        $this->assertSame($routeAttributes, $route->getAttributes());
184
-        $this->assertSame([$route], $collection->getRoutes());
185
-    }
186
-
187
-    /**
188
-     * @return void
189
-     */
190
-    public function testMakeRouteWithTransferringPrefix() : void
191
-    {
192
-        $collection = new RouteCollection();
193
-        $collection->setPrefix('/api');
194
-
195
-        $route = $collection->route('foo', '/foo', ['GET'], new Fixture\BlankRequestHandler());
196
-        $this->assertSame('/api/foo', $route->getPath());
197
-    }
198
-
199
-    /**
200
-     * @return void
201
-     */
202
-    public function testMakeRouteWithTransferringMiddlewares() : void
203
-    {
204
-        $middlewares = [new Fixture\BlankMiddleware()];
205
-
206
-        $collection = new RouteCollection();
207
-        $collection->addMiddlewares(...$middlewares);
208
-
209
-        $route = $collection->route('foo', '/foo', ['GET'], new Fixture\BlankRequestHandler());
210
-        $this->assertSame($middlewares, $route->getMiddlewares());
211
-
212
-        // merging...
213
-        $middlewares[] = new Fixture\BlankMiddleware();
214
-        $route = $collection->route('foo', '/foo', ['GET'], new Fixture\BlankRequestHandler(), [end($middlewares)]);
215
-        $this->assertSame($middlewares, $route->getMiddlewares());
216
-    }
217
-
218
-    /**
219
-     * @return void
220
-     *
221
-     * @dataProvider makeVerbableRoutesDataProvider
222
-     */
223
-    public function testMakeVerbableRoutes(string $calledMethod, string $expectedHttpMethod) : void
224
-    {
225
-        $routeName = Fixture\TestRoute::getTestRouteName();
226
-        $routePath = Fixture\TestRoute::getTestRoutePath();
227
-        $routeRequestHandler = Fixture\TestRoute::getTestRouteRequestHandler();
228
-
229
-        $collection = new RouteCollection();
230
-
231
-        $route = $collection->{$calledMethod}(
232
-            $routeName,
233
-            $routePath,
234
-            $routeRequestHandler
235
-        );
236
-
237
-        $this->assertInstanceOf(RouteInterface::class, $route);
238
-        $this->assertSame($routeName, $route->getName());
239
-        $this->assertSame($routePath, $route->getPath());
240
-        $this->assertSame([$expectedHttpMethod], $route->getMethods());
241
-        $this->assertSame($routeRequestHandler, $route->getRequestHandler());
242
-        $this->assertSame([], $route->getMiddlewares());
243
-        $this->assertSame([], $route->getAttributes());
244
-        $this->assertSame([$route], $collection->getRoutes());
245
-    }
246
-
247
-    /**
248
-     * @return void
249
-     *
250
-     * @dataProvider makeVerbableRoutesDataProvider
251
-     */
252
-    public function testMakeVerbableRoutesWithOptionalParams(string $calledMethod, string $expectedHttpMethod) : void
253
-    {
254
-        $routeName = Fixture\TestRoute::getTestRouteName();
255
-        $routePath = Fixture\TestRoute::getTestRoutePath();
256
-        $routeRequestHandler = Fixture\TestRoute::getTestRouteRequestHandler();
257
-        $routeMiddlewares = Fixture\TestRoute::getTestRouteMiddlewares();
258
-        $routeAttributes = Fixture\TestRoute::getTestRouteAttributes();
259
-
260
-        $collection = new RouteCollection();
261
-
262
-        $route = $collection->{$calledMethod}(
263
-            $routeName,
264
-            $routePath,
265
-            $routeRequestHandler,
266
-            $routeMiddlewares,
267
-            $routeAttributes
268
-        );
269
-
270
-        $this->assertInstanceOf(RouteInterface::class, $route);
271
-        $this->assertSame($routeName, $route->getName());
272
-        $this->assertSame($routePath, $route->getPath());
273
-        $this->assertSame([$expectedHttpMethod], $route->getMethods());
274
-        $this->assertSame($routeRequestHandler, $route->getRequestHandler());
275
-        $this->assertSame($routeMiddlewares, $route->getMiddlewares());
276
-        $this->assertSame($routeAttributes, $route->getAttributes());
277
-        $this->assertSame([$route], $collection->getRoutes());
278
-    }
279
-
280
-    /**
281
-     * @return void
282
-     *
283
-     * @dataProvider makeVerbableRoutesDataProvider
284
-     */
285
-    public function testMakeVerbableRoutesWithTransferringPrefix(string $calledMethod) : void
286
-    {
287
-        $collection = new RouteCollection();
288
-        $collection->setPrefix('/api');
289
-
290
-        $route = $collection->{$calledMethod}('foo', '/foo', new Fixture\BlankRequestHandler());
291
-        $this->assertSame('/api/foo', $route->getPath());
292
-    }
293
-
294
-    /**
295
-     * @return void
296
-     *
297
-     * @dataProvider makeVerbableRoutesDataProvider
298
-     */
299
-    public function testMakeVerbableRoutesWithTransferringMiddlewares(string $calledMethod) : void
300
-    {
301
-        $middlewares = [new Fixture\BlankMiddleware()];
302
-
303
-        $collection = new RouteCollection();
304
-        $collection->addMiddlewares(...$middlewares);
305
-
306
-        $route = $collection->{$calledMethod}('foo', '/foo', new Fixture\BlankRequestHandler());
307
-        $this->assertSame($middlewares, $route->getMiddlewares());
308
-
309
-        // merging...
310
-        $middlewares[] = new Fixture\BlankMiddleware();
311
-        $route = $collection->{$calledMethod}('foo', '/foo', new Fixture\BlankRequestHandler(), [end($middlewares)]);
312
-        $this->assertSame($middlewares, $route->getMiddlewares());
313
-    }
314
-
315
-    /**
316
-     * @return array
317
-     */
318
-    public function makeVerbableRoutesDataProvider() : array
319
-    {
320
-        return [
321
-            [
322
-                'head',
323
-                'HEAD',
324
-            ],
325
-            [
326
-                'get',
327
-                'GET',
328
-            ],
329
-            [
330
-                'post',
331
-                'POST',
332
-            ],
333
-            [
334
-                'put',
335
-                'PUT',
336
-            ],
337
-            [
338
-                'patch',
339
-                'PATCH',
340
-            ],
341
-            [
342
-                'delete',
343
-                'DELETE',
344
-            ],
345
-            [
346
-                'purge',
347
-                'PURGE',
348
-            ],
349
-        ];
350
-    }
24
+	/**
25
+	 * @return void
26
+	 */
27
+	public function testConstructor() : void
28
+	{
29
+		$collection = new RouteCollection();
30
+
31
+		$this->assertInstanceOf(RouteCollectionInterface::class, $collection);
32
+	}
33
+
34
+	/**
35
+	 * @return void
36
+	 */
37
+	public function testGetDefaultPrefix() : void
38
+	{
39
+		$collection = new RouteCollection();
40
+
41
+		$this->assertNull($collection->getPrefix());
42
+	}
43
+
44
+	/**
45
+	 * @return void
46
+	 */
47
+	public function testGetDefaultMiddlewares() : void
48
+	{
49
+		$collection = new RouteCollection();
50
+
51
+		$this->assertSame([], $collection->getMiddlewares());
52
+	}
53
+
54
+	/**
55
+	 * @return void
56
+	 */
57
+	public function testGetDefaultRoutes() : void
58
+	{
59
+		$collection = new RouteCollection();
60
+
61
+		$this->assertSame([], $collection->getRoutes());
62
+	}
63
+
64
+	/**
65
+	 * @return void
66
+	 */
67
+	public function testSetPrefix() : void
68
+	{
69
+		$collection = new RouteCollection();
70
+
71
+		$this->assertSame($collection, $collection->setPrefix('/foo'));
72
+		$this->assertSame('/foo', $collection->getPrefix());
73
+
74
+		// override prefix...
75
+		$collection->setPrefix('/bar');
76
+		$this->assertSame('/bar', $collection->getPrefix());
77
+
78
+		// https://github.com/sunrise-php/http-router/issues/26
79
+		$collection->setPrefix('/baz/');
80
+		$this->assertSame('/baz', $collection->getPrefix());
81
+	}
82
+
83
+	/**
84
+	 * @return void
85
+	 */
86
+	public function testAddMiddlewares() : void
87
+	{
88
+		$middlewares = [
89
+			new Fixture\BlankMiddleware(),
90
+			new Fixture\BlankMiddleware(),
91
+		];
92
+
93
+		$collection = new RouteCollection();
94
+
95
+		$this->assertSame($collection, $collection->addMiddlewares(...$middlewares));
96
+		$this->assertSame($middlewares, $collection->getMiddlewares());
97
+
98
+		// extending...
99
+		$middlewares[] = new Fixture\BlankMiddleware();
100
+		$collection->addMiddlewares(end($middlewares));
101
+		$this->assertSame($middlewares, $collection->getMiddlewares());
102
+	}
103
+
104
+	/**
105
+	 * @return void
106
+	 */
107
+	public function testAddRoutes() : void
108
+	{
109
+		$routes = [
110
+			new Fixture\TestRoute(),
111
+			new Fixture\TestRoute(),
112
+		];
113
+
114
+		$collection = new RouteCollection();
115
+
116
+		$this->assertSame($collection, $collection->addRoutes(...$routes));
117
+		$this->assertSame($routes, $collection->getRoutes());
118
+
119
+		// extending...
120
+		$routes[] = new Fixture\TestRoute();
121
+		$collection->addRoutes(end($routes));
122
+		$this->assertSame($routes, $collection->getRoutes());
123
+	}
124
+
125
+	/**
126
+	 * @return void
127
+	 */
128
+	public function testMakeRoute() : void
129
+	{
130
+		$routeName = Fixture\TestRoute::getTestRouteName();
131
+		$routePath = Fixture\TestRoute::getTestRoutePath();
132
+		$routeMethods = Fixture\TestRoute::getTestRouteMethods();
133
+		$routeRequestHandler = Fixture\TestRoute::getTestRouteRequestHandler();
134
+
135
+		$collection = new RouteCollection();
136
+
137
+		$route = $collection->route(
138
+			$routeName,
139
+			$routePath,
140
+			$routeMethods,
141
+			$routeRequestHandler
142
+		);
143
+
144
+		$this->assertInstanceOf(RouteInterface::class, $route);
145
+		$this->assertSame($routeName, $route->getName());
146
+		$this->assertSame($routePath, $route->getPath());
147
+		$this->assertSame($routeMethods, $route->getMethods());
148
+		$this->assertSame($routeRequestHandler, $route->getRequestHandler());
149
+		$this->assertSame([], $route->getMiddlewares());
150
+		$this->assertSame([], $route->getAttributes());
151
+		$this->assertSame([$route], $collection->getRoutes());
152
+	}
153
+
154
+	/**
155
+	 * @return void
156
+	 */
157
+	public function testMakeRouteWithOptionalParams() : void
158
+	{
159
+		$routeName = Fixture\TestRoute::getTestRouteName();
160
+		$routePath = Fixture\TestRoute::getTestRoutePath();
161
+		$routeMethods = Fixture\TestRoute::getTestRouteMethods();
162
+		$routeRequestHandler = Fixture\TestRoute::getTestRouteRequestHandler();
163
+		$routeMiddlewares = Fixture\TestRoute::getTestRouteMiddlewares();
164
+		$routeAttributes = Fixture\TestRoute::getTestRouteAttributes();
165
+
166
+		$collection = new RouteCollection();
167
+
168
+		$route = $collection->route(
169
+			$routeName,
170
+			$routePath,
171
+			$routeMethods,
172
+			$routeRequestHandler,
173
+			$routeMiddlewares,
174
+			$routeAttributes
175
+		);
176
+
177
+		$this->assertInstanceOf(RouteInterface::class, $route);
178
+		$this->assertSame($routeName, $route->getName());
179
+		$this->assertSame($routePath, $route->getPath());
180
+		$this->assertSame($routeMethods, $route->getMethods());
181
+		$this->assertSame($routeRequestHandler, $route->getRequestHandler());
182
+		$this->assertSame($routeMiddlewares, $route->getMiddlewares());
183
+		$this->assertSame($routeAttributes, $route->getAttributes());
184
+		$this->assertSame([$route], $collection->getRoutes());
185
+	}
186
+
187
+	/**
188
+	 * @return void
189
+	 */
190
+	public function testMakeRouteWithTransferringPrefix() : void
191
+	{
192
+		$collection = new RouteCollection();
193
+		$collection->setPrefix('/api');
194
+
195
+		$route = $collection->route('foo', '/foo', ['GET'], new Fixture\BlankRequestHandler());
196
+		$this->assertSame('/api/foo', $route->getPath());
197
+	}
198
+
199
+	/**
200
+	 * @return void
201
+	 */
202
+	public function testMakeRouteWithTransferringMiddlewares() : void
203
+	{
204
+		$middlewares = [new Fixture\BlankMiddleware()];
205
+
206
+		$collection = new RouteCollection();
207
+		$collection->addMiddlewares(...$middlewares);
208
+
209
+		$route = $collection->route('foo', '/foo', ['GET'], new Fixture\BlankRequestHandler());
210
+		$this->assertSame($middlewares, $route->getMiddlewares());
211
+
212
+		// merging...
213
+		$middlewares[] = new Fixture\BlankMiddleware();
214
+		$route = $collection->route('foo', '/foo', ['GET'], new Fixture\BlankRequestHandler(), [end($middlewares)]);
215
+		$this->assertSame($middlewares, $route->getMiddlewares());
216
+	}
217
+
218
+	/**
219
+	 * @return void
220
+	 *
221
+	 * @dataProvider makeVerbableRoutesDataProvider
222
+	 */
223
+	public function testMakeVerbableRoutes(string $calledMethod, string $expectedHttpMethod) : void
224
+	{
225
+		$routeName = Fixture\TestRoute::getTestRouteName();
226
+		$routePath = Fixture\TestRoute::getTestRoutePath();
227
+		$routeRequestHandler = Fixture\TestRoute::getTestRouteRequestHandler();
228
+
229
+		$collection = new RouteCollection();
230
+
231
+		$route = $collection->{$calledMethod}(
232
+			$routeName,
233
+			$routePath,
234
+			$routeRequestHandler
235
+		);
236
+
237
+		$this->assertInstanceOf(RouteInterface::class, $route);
238
+		$this->assertSame($routeName, $route->getName());
239
+		$this->assertSame($routePath, $route->getPath());
240
+		$this->assertSame([$expectedHttpMethod], $route->getMethods());
241
+		$this->assertSame($routeRequestHandler, $route->getRequestHandler());
242
+		$this->assertSame([], $route->getMiddlewares());
243
+		$this->assertSame([], $route->getAttributes());
244
+		$this->assertSame([$route], $collection->getRoutes());
245
+	}
246
+
247
+	/**
248
+	 * @return void
249
+	 *
250
+	 * @dataProvider makeVerbableRoutesDataProvider
251
+	 */
252
+	public function testMakeVerbableRoutesWithOptionalParams(string $calledMethod, string $expectedHttpMethod) : void
253
+	{
254
+		$routeName = Fixture\TestRoute::getTestRouteName();
255
+		$routePath = Fixture\TestRoute::getTestRoutePath();
256
+		$routeRequestHandler = Fixture\TestRoute::getTestRouteRequestHandler();
257
+		$routeMiddlewares = Fixture\TestRoute::getTestRouteMiddlewares();
258
+		$routeAttributes = Fixture\TestRoute::getTestRouteAttributes();
259
+
260
+		$collection = new RouteCollection();
261
+
262
+		$route = $collection->{$calledMethod}(
263
+			$routeName,
264
+			$routePath,
265
+			$routeRequestHandler,
266
+			$routeMiddlewares,
267
+			$routeAttributes
268
+		);
269
+
270
+		$this->assertInstanceOf(RouteInterface::class, $route);
271
+		$this->assertSame($routeName, $route->getName());
272
+		$this->assertSame($routePath, $route->getPath());
273
+		$this->assertSame([$expectedHttpMethod], $route->getMethods());
274
+		$this->assertSame($routeRequestHandler, $route->getRequestHandler());
275
+		$this->assertSame($routeMiddlewares, $route->getMiddlewares());
276
+		$this->assertSame($routeAttributes, $route->getAttributes());
277
+		$this->assertSame([$route], $collection->getRoutes());
278
+	}
279
+
280
+	/**
281
+	 * @return void
282
+	 *
283
+	 * @dataProvider makeVerbableRoutesDataProvider
284
+	 */
285
+	public function testMakeVerbableRoutesWithTransferringPrefix(string $calledMethod) : void
286
+	{
287
+		$collection = new RouteCollection();
288
+		$collection->setPrefix('/api');
289
+
290
+		$route = $collection->{$calledMethod}('foo', '/foo', new Fixture\BlankRequestHandler());
291
+		$this->assertSame('/api/foo', $route->getPath());
292
+	}
293
+
294
+	/**
295
+	 * @return void
296
+	 *
297
+	 * @dataProvider makeVerbableRoutesDataProvider
298
+	 */
299
+	public function testMakeVerbableRoutesWithTransferringMiddlewares(string $calledMethod) : void
300
+	{
301
+		$middlewares = [new Fixture\BlankMiddleware()];
302
+
303
+		$collection = new RouteCollection();
304
+		$collection->addMiddlewares(...$middlewares);
305
+
306
+		$route = $collection->{$calledMethod}('foo', '/foo', new Fixture\BlankRequestHandler());
307
+		$this->assertSame($middlewares, $route->getMiddlewares());
308
+
309
+		// merging...
310
+		$middlewares[] = new Fixture\BlankMiddleware();
311
+		$route = $collection->{$calledMethod}('foo', '/foo', new Fixture\BlankRequestHandler(), [end($middlewares)]);
312
+		$this->assertSame($middlewares, $route->getMiddlewares());
313
+	}
314
+
315
+	/**
316
+	 * @return array
317
+	 */
318
+	public function makeVerbableRoutesDataProvider() : array
319
+	{
320
+		return [
321
+			[
322
+				'head',
323
+				'HEAD',
324
+			],
325
+			[
326
+				'get',
327
+				'GET',
328
+			],
329
+			[
330
+				'post',
331
+				'POST',
332
+			],
333
+			[
334
+				'put',
335
+				'PUT',
336
+			],
337
+			[
338
+				'patch',
339
+				'PATCH',
340
+			],
341
+			[
342
+				'delete',
343
+				'DELETE',
344
+			],
345
+			[
346
+				'purge',
347
+				'PURGE',
348
+			],
349
+		];
350
+	}
351 351
 }
Please login to merge, or discard this patch.
tests/Exception/RouteNotFoundExceptionTest.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -16,14 +16,14 @@
 block discarded – undo
16 16
 class RouteNotFoundExceptionTest extends TestCase
17 17
 {
18 18
 
19
-    /**
20
-     * @return void
21
-     */
22
-    public function testConstructor() : void
23
-    {
24
-        $exception = new RouteNotFoundException();
19
+	/**
20
+	 * @return void
21
+	 */
22
+	public function testConstructor() : void
23
+	{
24
+		$exception = new RouteNotFoundException();
25 25
 
26
-        $this->assertInstanceOf(RuntimeException::class, $exception);
27
-        $this->assertInstanceOf(ExceptionInterface::class, $exception);
28
-    }
26
+		$this->assertInstanceOf(RuntimeException::class, $exception);
27
+		$this->assertInstanceOf(ExceptionInterface::class, $exception);
28
+	}
29 29
 }
Please login to merge, or discard this patch.
tests/Exception/MethodNotAllowedExceptionTest.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -16,24 +16,24 @@
 block discarded – undo
16 16
 class MethodNotAllowedExceptionTest extends TestCase
17 17
 {
18 18
 
19
-    /**
20
-     * @return void
21
-     */
22
-    public function testConstructor() : void
23
-    {
24
-        $exception = new MethodNotAllowedException([]);
19
+	/**
20
+	 * @return void
21
+	 */
22
+	public function testConstructor() : void
23
+	{
24
+		$exception = new MethodNotAllowedException([]);
25 25
 
26
-        $this->assertInstanceOf(RuntimeException::class, $exception);
27
-        $this->assertInstanceOf(ExceptionInterface::class, $exception);
28
-    }
26
+		$this->assertInstanceOf(RuntimeException::class, $exception);
27
+		$this->assertInstanceOf(ExceptionInterface::class, $exception);
28
+	}
29 29
 
30
-    /**
31
-     * @return void
32
-     */
33
-    public function testGetAllowedMethods() : void
34
-    {
35
-        $exception = new MethodNotAllowedException(['foo']);
30
+	/**
31
+	 * @return void
32
+	 */
33
+	public function testGetAllowedMethods() : void
34
+	{
35
+		$exception = new MethodNotAllowedException(['foo']);
36 36
 
37
-        $this->assertSame(['foo'], $exception->getAllowedMethods());
38
-    }
37
+		$this->assertSame(['foo'], $exception->getAllowedMethods());
38
+	}
39 39
 }
Please login to merge, or discard this patch.
tests/RouteTest.php 1 patch
Indentation   +234 added lines, -234 removed lines patch added patch discarded remove patch
@@ -16,238 +16,238 @@
 block discarded – undo
16 16
 class RouteTest extends TestCase
17 17
 {
18 18
 
19
-    /**
20
-     * @return void
21
-     */
22
-    public function testConstructor() : void
23
-    {
24
-        $routeName = Fixture\TestRoute::getTestRouteName();
25
-        $routePath = Fixture\TestRoute::getTestRoutePath();
26
-        $routeMethods = Fixture\TestRoute::getTestRouteMethods();
27
-        $routeRequestHandler = Fixture\TestRoute::getTestRouteRequestHandler();
28
-
29
-        $route = new Route(
30
-            $routeName,
31
-            $routePath,
32
-            $routeMethods,
33
-            $routeRequestHandler
34
-        );
35
-
36
-        $this->assertInstanceOf(RouteInterface::class, $route);
37
-        $this->assertSame($routeName, $route->getName());
38
-        $this->assertSame($routePath, $route->getPath());
39
-        $this->assertSame($routeMethods, $route->getMethods());
40
-        $this->assertSame($routeRequestHandler, $route->getRequestHandler());
41
-        $this->assertSame([], $route->getMiddlewares());
42
-        $this->assertSame([], $route->getAttributes());
43
-    }
44
-
45
-    /**
46
-     * @return void
47
-     */
48
-    public function testConstructorWithOptionalParams() : void
49
-    {
50
-        $routeName = Fixture\TestRoute::getTestRouteName();
51
-        $routePath = Fixture\TestRoute::getTestRoutePath();
52
-        $routeMethods = Fixture\TestRoute::getTestRouteMethods();
53
-        $routeRequestHandler = Fixture\TestRoute::getTestRouteRequestHandler();
54
-        $routeMiddlewares = Fixture\TestRoute::getTestRouteMiddlewares();
55
-        $routeAttributes = Fixture\TestRoute::getTestRouteAttributes();
56
-
57
-        $route = new Route(
58
-            $routeName,
59
-            $routePath,
60
-            $routeMethods,
61
-            $routeRequestHandler,
62
-            $routeMiddlewares,
63
-            $routeAttributes
64
-        );
65
-
66
-        $this->assertSame($routeName, $route->getName());
67
-        $this->assertSame($routePath, $route->getPath());
68
-        $this->assertSame($routeMethods, $route->getMethods());
69
-        $this->assertSame($routeRequestHandler, $route->getRequestHandler());
70
-        $this->assertSame($routeMiddlewares, $route->getMiddlewares());
71
-        $this->assertSame($routeAttributes, $route->getAttributes());
72
-    }
73
-
74
-    /**
75
-     * @return void
76
-     */
77
-    public function testSetName() : void
78
-    {
79
-        $route = new Fixture\TestRoute();
80
-        $newRouteName = Fixture\TestRoute::getTestRouteName();
81
-
82
-        $this->assertNotSame($route->getName(), $newRouteName);
83
-        $this->assertSame($route, $route->setName($newRouteName));
84
-        $this->assertSame($newRouteName, $route->getName());
85
-    }
86
-
87
-    /**
88
-     * @return void
89
-     */
90
-    public function testSetPath() : void
91
-    {
92
-        $route = new Fixture\TestRoute();
93
-        $newRoutePath = Fixture\TestRoute::getTestRoutePath();
94
-
95
-        $this->assertNotSame($route->getPath(), $newRoutePath);
96
-        $this->assertSame($route, $route->setPath($newRoutePath));
97
-        $this->assertSame($newRoutePath, $route->getPath());
98
-    }
99
-
100
-    /**
101
-     * @return void
102
-     */
103
-    public function testSetMethods() : void
104
-    {
105
-        $route = new Fixture\TestRoute();
106
-        $newRouteMethods = Fixture\TestRoute::getTestRouteMethods();
107
-
108
-        $this->assertNotSame($route->getMethods(), $newRouteMethods);
109
-        $this->assertSame($route, $route->setMethods(...$newRouteMethods));
110
-        $this->assertSame($newRouteMethods, $route->getMethods());
111
-    }
112
-
113
-    /**
114
-     * @return void
115
-     */
116
-    public function testSetLowercasedMethods() : void
117
-    {
118
-        $route = new Fixture\TestRoute();
119
-        $route->setMethods('foo', 'bar');
120
-
121
-        $this->assertSame(['FOO', 'BAR'], $route->getMethods());
122
-    }
123
-
124
-    /**
125
-     * @return void
126
-     */
127
-    public function testSetRequestHandler() : void
128
-    {
129
-        $route = new Fixture\TestRoute();
130
-        $newRouteRequestHandler = Fixture\TestRoute::getTestRouteRequestHandler();
131
-
132
-        $this->assertNotSame($route->getRequestHandler(), $newRouteRequestHandler);
133
-        $this->assertSame($route, $route->setRequestHandler($newRouteRequestHandler));
134
-        $this->assertSame($newRouteRequestHandler, $route->getRequestHandler());
135
-    }
136
-
137
-    /**
138
-     * @return void
139
-     */
140
-    public function testSetMiddlewares() : void
141
-    {
142
-        $route = new Fixture\TestRoute();
143
-        $newRouteMiddlewares = Fixture\TestRoute::getTestRouteMiddlewares();
144
-
145
-        $this->assertNotSame($route->getMiddlewares(), $newRouteMiddlewares);
146
-        $this->assertSame($route, $route->setMiddlewares(...$newRouteMiddlewares));
147
-        $this->assertSame($newRouteMiddlewares, $route->getMiddlewares());
148
-    }
149
-
150
-    /**
151
-     * @return void
152
-     */
153
-    public function testSetAttributes() : void
154
-    {
155
-        $route = new Fixture\TestRoute();
156
-        $newRouteAttributes = Fixture\TestRoute::getTestRouteAttributes();
157
-
158
-        $this->assertNotSame($route->getAttributes(), $newRouteAttributes);
159
-        $this->assertSame($route, $route->setAttributes($newRouteAttributes));
160
-        $this->assertSame($newRouteAttributes, $route->getAttributes());
161
-    }
162
-
163
-    /**
164
-     * @return void
165
-     */
166
-    public function testWithAddedAttributes() : void
167
-    {
168
-        $route = new Fixture\TestRoute();
169
-        $extraAttributes = Fixture\TestRoute::getTestRouteAttributes();
170
-        $expectedAttributes = $route->getAttributes() + $extraAttributes;
171
-        $routeClone = $route->withAddedAttributes($extraAttributes);
172
-
173
-        $this->assertInstanceOf(RouteInterface::class, $routeClone);
174
-        $this->assertNotSame($route, $routeClone);
175
-        $this->assertSame($expectedAttributes, $routeClone->getAttributes());
176
-    }
177
-
178
-    /**
179
-     * @return void
180
-     */
181
-    public function testBuildPath() : void
182
-    {
183
-        $route = new Fixture\TestRoute();
184
-
185
-        $route->setPath('/foo/{bar}');
186
-        $this->assertSame('/foo/bar', $route->buildPath(['bar' => 'bar']));
187
-
188
-        $route->setPath('/foo/{bar<\w+>}');
189
-        $this->assertSame('/foo/bar', $route->buildPath(['bar' => 'bar'], true));
190
-
191
-        $route->setPath('/foo/{bar<\d+>}');
192
-        $this->assertSame('/foo/100', $route->buildPath(['bar' => 100], true));
193
-
194
-        $route = $route->withAddedAttributes(['bar' => 'bar']);
195
-        $this->assertSame('/foo/100', $route->buildPath(['bar' => 100], true));
196
-
197
-        $route = $route->withAddedAttributes(['bar' => 100]);
198
-        $this->assertSame('/foo/100', $route->buildPath([], true));
199
-    }
200
-
201
-    /**
202
-     * @return void
203
-     */
204
-    public function testBuildPathWithMissingAttribute() : void
205
-    {
206
-        $route = new Fixture\TestRoute();
207
-        $route->setPath('/foo/{bar}/{baz}/quux');
208
-
209
-        $this->expectException(InvalidArgumentException::class);
210
-        $this->expectExceptionMessage('[' . $route->getPath() . '] missing attribute "baz".');
211
-
212
-        $route->buildPath([
213
-            'bar' => 'bar',
214
-        ]);
215
-    }
216
-
217
-    /**
218
-     * @return void
219
-     */
220
-    public function testBuildPathWithInvalidAttributeValue() : void
221
-    {
222
-        $route = new Fixture\TestRoute();
223
-        $route->setPath('/foo/{bar<\w+>}/{baz<\d+>}/quux');
224
-
225
-        $this->expectException(InvalidArgumentException::class);
226
-        $this->expectExceptionMessage('[' . $route->getPath() . '] "baz" must match "\d+".');
227
-
228
-        $route->buildPath([
229
-            'bar' => 'bar',
230
-            'baz' => 'baz',
231
-        ], true);
232
-    }
233
-
234
-    /**
235
-      * @return void
236
-      */
237
-    public function testBuildRegex() : void
238
-    {
239
-        $route = new Fixture\TestRoute();
240
-
241
-        $route->setPath('/');
242
-        $this->assertSame('#^/$#uD', $route->buildRegex());
243
-
244
-        $route->setPath('/{foo}');
245
-        $this->assertSame('#^/(?<foo>[^/]+)$#uD', $route->buildRegex());
246
-
247
-        $route->setPath('/{foo}(/{bar})');
248
-        $this->assertSame('#^/(?<foo>[^/]+)(?:/(?<bar>[^/]+))?$#uD', $route->buildRegex());
249
-
250
-        $route->setPath('/{foo}(/{bar})/{baz<\w+>}');
251
-        $this->assertSame('#^/(?<foo>[^/]+)(?:/(?<bar>[^/]+))?/(?<baz>\w+)$#uD', $route->buildRegex());
252
-    }
19
+	/**
20
+	 * @return void
21
+	 */
22
+	public function testConstructor() : void
23
+	{
24
+		$routeName = Fixture\TestRoute::getTestRouteName();
25
+		$routePath = Fixture\TestRoute::getTestRoutePath();
26
+		$routeMethods = Fixture\TestRoute::getTestRouteMethods();
27
+		$routeRequestHandler = Fixture\TestRoute::getTestRouteRequestHandler();
28
+
29
+		$route = new Route(
30
+			$routeName,
31
+			$routePath,
32
+			$routeMethods,
33
+			$routeRequestHandler
34
+		);
35
+
36
+		$this->assertInstanceOf(RouteInterface::class, $route);
37
+		$this->assertSame($routeName, $route->getName());
38
+		$this->assertSame($routePath, $route->getPath());
39
+		$this->assertSame($routeMethods, $route->getMethods());
40
+		$this->assertSame($routeRequestHandler, $route->getRequestHandler());
41
+		$this->assertSame([], $route->getMiddlewares());
42
+		$this->assertSame([], $route->getAttributes());
43
+	}
44
+
45
+	/**
46
+	 * @return void
47
+	 */
48
+	public function testConstructorWithOptionalParams() : void
49
+	{
50
+		$routeName = Fixture\TestRoute::getTestRouteName();
51
+		$routePath = Fixture\TestRoute::getTestRoutePath();
52
+		$routeMethods = Fixture\TestRoute::getTestRouteMethods();
53
+		$routeRequestHandler = Fixture\TestRoute::getTestRouteRequestHandler();
54
+		$routeMiddlewares = Fixture\TestRoute::getTestRouteMiddlewares();
55
+		$routeAttributes = Fixture\TestRoute::getTestRouteAttributes();
56
+
57
+		$route = new Route(
58
+			$routeName,
59
+			$routePath,
60
+			$routeMethods,
61
+			$routeRequestHandler,
62
+			$routeMiddlewares,
63
+			$routeAttributes
64
+		);
65
+
66
+		$this->assertSame($routeName, $route->getName());
67
+		$this->assertSame($routePath, $route->getPath());
68
+		$this->assertSame($routeMethods, $route->getMethods());
69
+		$this->assertSame($routeRequestHandler, $route->getRequestHandler());
70
+		$this->assertSame($routeMiddlewares, $route->getMiddlewares());
71
+		$this->assertSame($routeAttributes, $route->getAttributes());
72
+	}
73
+
74
+	/**
75
+	 * @return void
76
+	 */
77
+	public function testSetName() : void
78
+	{
79
+		$route = new Fixture\TestRoute();
80
+		$newRouteName = Fixture\TestRoute::getTestRouteName();
81
+
82
+		$this->assertNotSame($route->getName(), $newRouteName);
83
+		$this->assertSame($route, $route->setName($newRouteName));
84
+		$this->assertSame($newRouteName, $route->getName());
85
+	}
86
+
87
+	/**
88
+	 * @return void
89
+	 */
90
+	public function testSetPath() : void
91
+	{
92
+		$route = new Fixture\TestRoute();
93
+		$newRoutePath = Fixture\TestRoute::getTestRoutePath();
94
+
95
+		$this->assertNotSame($route->getPath(), $newRoutePath);
96
+		$this->assertSame($route, $route->setPath($newRoutePath));
97
+		$this->assertSame($newRoutePath, $route->getPath());
98
+	}
99
+
100
+	/**
101
+	 * @return void
102
+	 */
103
+	public function testSetMethods() : void
104
+	{
105
+		$route = new Fixture\TestRoute();
106
+		$newRouteMethods = Fixture\TestRoute::getTestRouteMethods();
107
+
108
+		$this->assertNotSame($route->getMethods(), $newRouteMethods);
109
+		$this->assertSame($route, $route->setMethods(...$newRouteMethods));
110
+		$this->assertSame($newRouteMethods, $route->getMethods());
111
+	}
112
+
113
+	/**
114
+	 * @return void
115
+	 */
116
+	public function testSetLowercasedMethods() : void
117
+	{
118
+		$route = new Fixture\TestRoute();
119
+		$route->setMethods('foo', 'bar');
120
+
121
+		$this->assertSame(['FOO', 'BAR'], $route->getMethods());
122
+	}
123
+
124
+	/**
125
+	 * @return void
126
+	 */
127
+	public function testSetRequestHandler() : void
128
+	{
129
+		$route = new Fixture\TestRoute();
130
+		$newRouteRequestHandler = Fixture\TestRoute::getTestRouteRequestHandler();
131
+
132
+		$this->assertNotSame($route->getRequestHandler(), $newRouteRequestHandler);
133
+		$this->assertSame($route, $route->setRequestHandler($newRouteRequestHandler));
134
+		$this->assertSame($newRouteRequestHandler, $route->getRequestHandler());
135
+	}
136
+
137
+	/**
138
+	 * @return void
139
+	 */
140
+	public function testSetMiddlewares() : void
141
+	{
142
+		$route = new Fixture\TestRoute();
143
+		$newRouteMiddlewares = Fixture\TestRoute::getTestRouteMiddlewares();
144
+
145
+		$this->assertNotSame($route->getMiddlewares(), $newRouteMiddlewares);
146
+		$this->assertSame($route, $route->setMiddlewares(...$newRouteMiddlewares));
147
+		$this->assertSame($newRouteMiddlewares, $route->getMiddlewares());
148
+	}
149
+
150
+	/**
151
+	 * @return void
152
+	 */
153
+	public function testSetAttributes() : void
154
+	{
155
+		$route = new Fixture\TestRoute();
156
+		$newRouteAttributes = Fixture\TestRoute::getTestRouteAttributes();
157
+
158
+		$this->assertNotSame($route->getAttributes(), $newRouteAttributes);
159
+		$this->assertSame($route, $route->setAttributes($newRouteAttributes));
160
+		$this->assertSame($newRouteAttributes, $route->getAttributes());
161
+	}
162
+
163
+	/**
164
+	 * @return void
165
+	 */
166
+	public function testWithAddedAttributes() : void
167
+	{
168
+		$route = new Fixture\TestRoute();
169
+		$extraAttributes = Fixture\TestRoute::getTestRouteAttributes();
170
+		$expectedAttributes = $route->getAttributes() + $extraAttributes;
171
+		$routeClone = $route->withAddedAttributes($extraAttributes);
172
+
173
+		$this->assertInstanceOf(RouteInterface::class, $routeClone);
174
+		$this->assertNotSame($route, $routeClone);
175
+		$this->assertSame($expectedAttributes, $routeClone->getAttributes());
176
+	}
177
+
178
+	/**
179
+	 * @return void
180
+	 */
181
+	public function testBuildPath() : void
182
+	{
183
+		$route = new Fixture\TestRoute();
184
+
185
+		$route->setPath('/foo/{bar}');
186
+		$this->assertSame('/foo/bar', $route->buildPath(['bar' => 'bar']));
187
+
188
+		$route->setPath('/foo/{bar<\w+>}');
189
+		$this->assertSame('/foo/bar', $route->buildPath(['bar' => 'bar'], true));
190
+
191
+		$route->setPath('/foo/{bar<\d+>}');
192
+		$this->assertSame('/foo/100', $route->buildPath(['bar' => 100], true));
193
+
194
+		$route = $route->withAddedAttributes(['bar' => 'bar']);
195
+		$this->assertSame('/foo/100', $route->buildPath(['bar' => 100], true));
196
+
197
+		$route = $route->withAddedAttributes(['bar' => 100]);
198
+		$this->assertSame('/foo/100', $route->buildPath([], true));
199
+	}
200
+
201
+	/**
202
+	 * @return void
203
+	 */
204
+	public function testBuildPathWithMissingAttribute() : void
205
+	{
206
+		$route = new Fixture\TestRoute();
207
+		$route->setPath('/foo/{bar}/{baz}/quux');
208
+
209
+		$this->expectException(InvalidArgumentException::class);
210
+		$this->expectExceptionMessage('[' . $route->getPath() . '] missing attribute "baz".');
211
+
212
+		$route->buildPath([
213
+			'bar' => 'bar',
214
+		]);
215
+	}
216
+
217
+	/**
218
+	 * @return void
219
+	 */
220
+	public function testBuildPathWithInvalidAttributeValue() : void
221
+	{
222
+		$route = new Fixture\TestRoute();
223
+		$route->setPath('/foo/{bar<\w+>}/{baz<\d+>}/quux');
224
+
225
+		$this->expectException(InvalidArgumentException::class);
226
+		$this->expectExceptionMessage('[' . $route->getPath() . '] "baz" must match "\d+".');
227
+
228
+		$route->buildPath([
229
+			'bar' => 'bar',
230
+			'baz' => 'baz',
231
+		], true);
232
+	}
233
+
234
+	/**
235
+	 * @return void
236
+	 */
237
+	public function testBuildRegex() : void
238
+	{
239
+		$route = new Fixture\TestRoute();
240
+
241
+		$route->setPath('/');
242
+		$this->assertSame('#^/$#uD', $route->buildRegex());
243
+
244
+		$route->setPath('/{foo}');
245
+		$this->assertSame('#^/(?<foo>[^/]+)$#uD', $route->buildRegex());
246
+
247
+		$route->setPath('/{foo}(/{bar})');
248
+		$this->assertSame('#^/(?<foo>[^/]+)(?:/(?<bar>[^/]+))?$#uD', $route->buildRegex());
249
+
250
+		$route->setPath('/{foo}(/{bar})/{baz<\w+>}');
251
+		$this->assertSame('#^/(?<foo>[^/]+)(?:/(?<bar>[^/]+))?/(?<baz>\w+)$#uD', $route->buildRegex());
252
+	}
253 253
 }
Please login to merge, or discard this patch.
tests/RouterTest.php 1 patch
Indentation   +341 added lines, -341 removed lines patch added patch discarded remove patch
@@ -28,345 +28,345 @@
 block discarded – undo
28 28
 class RouterTest extends TestCase
29 29
 {
30 30
 
31
-    /**
32
-     * @return void
33
-     */
34
-    public function testConstructor() : void
35
-    {
36
-        $router = new Router();
37
-
38
-        $this->assertInstanceOf(RouteCollection::class, $router);
39
-        $this->assertInstanceOf(MiddlewareInterface::class, $router);
40
-        $this->assertInstanceOf(RequestHandlerInterface::class, $router);
41
-    }
42
-
43
-    /**
44
-     * @return void
45
-     */
46
-    public function testGetRoute() : void
47
-    {
48
-        $routes = [
49
-            new Fixture\TestRoute(),
50
-            new Fixture\TestRoute(),
51
-            new Fixture\TestRoute(),
52
-        ];
53
-
54
-        $router = new Router();
55
-        $router->addRoutes(...$routes);
56
-
57
-        $this->assertSame($routes[0], $router->getRoute($routes[0]->getName()));
58
-        $this->assertSame($routes[1], $router->getRoute($routes[1]->getName()));
59
-        $this->assertSame($routes[2], $router->getRoute($routes[2]->getName()));
60
-    }
61
-
62
-    /**
63
-     * @return void
64
-     */
65
-    public function testGetUndefinedRoute() : void
66
-    {
67
-        $router = new Router();
68
-
69
-        $this->expectException(RouteNotFoundException::class);
70
-        $router->getRoute('foo');
71
-    }
72
-
73
-    /**
74
-     * @return void
75
-     */
76
-    public function testMatch() : void
77
-    {
78
-        $routes = [
79
-            new Fixture\TestRoute(),
80
-            new Fixture\TestRoute(),
81
-            new Fixture\TestRoute(),
82
-            new Fixture\TestRoute(),
83
-            new Fixture\TestRoute(),
84
-        ];
85
-
86
-        $router = new Router();
87
-        $router->addRoutes(...$routes);
88
-
89
-        $request = (new ServerRequestFactory)
90
-            ->createServerRequest(
91
-                $routes[2]->getMethods()[1],
92
-                $routes[2]->getPath()
93
-            );
94
-
95
-        $foundRoute = $router->match($request);
96
-
97
-        $this->assertSame($routes[2]->getName(), $foundRoute->getName());
98
-    }
99
-
100
-    /**
101
-     * @return void
102
-     */
103
-    public function testMatchForUnallowedMethod() : void
104
-    {
105
-        $routes = [
106
-            new Fixture\TestRoute(),
107
-            new Fixture\TestRoute(),
108
-            new Fixture\TestRoute(),
109
-        ];
110
-
111
-        $router = new Router();
112
-        $router->addRoutes(...$routes);
113
-
114
-        $request = (new ServerRequestFactory)
115
-            ->createServerRequest('GET', '/');
116
-
117
-        $this->expectException(MethodNotAllowedException::class);
118
-
119
-        try {
120
-            $router->match($request);
121
-        } catch (MethodNotAllowedException $e) {
122
-            $allowedMethods = array_merge(
123
-                $routes[0]->getMethods(),
124
-                $routes[1]->getMethods(),
125
-                $routes[2]->getMethods()
126
-            );
127
-
128
-            $this->assertSame($allowedMethods, $e->getAllowedMethods());
129
-
130
-            throw $e;
131
-        }
132
-    }
133
-
134
-    /**
135
-     * @return void
136
-     */
137
-    public function testMatchForUndefinedRoute() : void
138
-    {
139
-        $routes = [
140
-            new Fixture\TestRoute(),
141
-            new Fixture\TestRoute(),
142
-            new Fixture\TestRoute(),
143
-        ];
144
-
145
-        $router = new Router();
146
-        $router->addRoutes(...$routes);
147
-
148
-        $request = (new ServerRequestFactory)
149
-            ->createServerRequest($routes[0]->getMethods()[0], '/');
150
-
151
-        $this->expectException(RouteNotFoundException::class);
152
-        $router->match($request);
153
-    }
154
-
155
-    /**
156
-     * @return void
157
-     */
158
-    public function testHandle() : void
159
-    {
160
-        $routes = [
161
-            new Fixture\TestRoute(),
162
-            new Fixture\TestRoute(),
163
-            new Fixture\TestRoute(),
164
-            new Fixture\TestRoute(),
165
-            new Fixture\TestRoute(),
166
-        ];
167
-
168
-        $router = new Router();
169
-        $router->addRoutes(...$routes);
170
-
171
-        $request = (new ServerRequestFactory)
172
-            ->createServerRequest(
173
-                $routes[2]->getMethods()[1],
174
-                $routes[2]->getPath()
175
-            );
176
-
177
-        $router->handle($request);
178
-
179
-        $this->assertTrue($routes[2]->getRequestHandler()->isRunned());
180
-    }
181
-
182
-    /**
183
-     * @return void
184
-     */
185
-    public function testHandleForUnallowedMethod() : void
186
-    {
187
-        $routes = [
188
-            new Fixture\TestRoute(),
189
-            new Fixture\TestRoute(),
190
-            new Fixture\TestRoute(),
191
-        ];
192
-
193
-        $router = new Router();
194
-        $router->addRoutes(...$routes);
195
-
196
-        $request = (new ServerRequestFactory)
197
-            ->createServerRequest('GET', '/');
198
-
199
-        $this->expectException(MethodNotAllowedException::class);
200
-
201
-        try {
202
-            $router->handle($request);
203
-        } catch (MethodNotAllowedException $e) {
204
-            $allowedMethods = array_merge(
205
-                $routes[0]->getMethods(),
206
-                $routes[1]->getMethods(),
207
-                $routes[2]->getMethods()
208
-            );
209
-
210
-            $this->assertSame($allowedMethods, $e->getAllowedMethods());
211
-
212
-            throw $e;
213
-        }
214
-    }
215
-
216
-    /**
217
-     * @return void
218
-     */
219
-    public function testHandleForUndefinedRoute() : void
220
-    {
221
-        $routes = [
222
-            new Fixture\TestRoute(),
223
-            new Fixture\TestRoute(),
224
-            new Fixture\TestRoute(),
225
-        ];
226
-
227
-        $router = new Router();
228
-        $router->addRoutes(...$routes);
229
-
230
-        $request = (new ServerRequestFactory)
231
-            ->createServerRequest($routes[0]->getMethods()[0], '/');
232
-
233
-        $this->expectException(RouteNotFoundException::class);
234
-        $router->handle($request);
235
-    }
236
-
237
-    /**
238
-     * @return void
239
-     */
240
-    public function testProcess() : void
241
-    {
242
-        $routes = [
243
-            new Fixture\TestRoute(),
244
-            new Fixture\TestRoute(),
245
-            new Fixture\TestRoute(),
246
-            new Fixture\TestRoute(),
247
-            new Fixture\TestRoute(),
248
-        ];
249
-
250
-        $router = new Router();
251
-        $router->addRoutes(...$routes);
252
-
253
-        $request = (new ServerRequestFactory)
254
-            ->createServerRequest(
255
-                $routes[2]->getMethods()[1],
256
-                $routes[2]->getPath()
257
-            );
258
-
259
-        $fallback = new Fixture\BlankRequestHandler();
260
-
261
-        $router->process($request, $fallback);
262
-
263
-        $this->assertTrue($routes[2]->getRequestHandler()->isRunned());
264
-        $this->assertFalse($fallback->isRunned());
265
-    }
266
-
267
-    /**
268
-     * @return void
269
-     */
270
-    public function testProcessForUnallowedMethod() : void
271
-    {
272
-        $routes = [
273
-            new Fixture\TestRoute(),
274
-            new Fixture\TestRoute(),
275
-            new Fixture\TestRoute(),
276
-        ];
277
-
278
-        $router = new Router();
279
-        $router->addRoutes(...$routes);
280
-
281
-        $request = (new ServerRequestFactory)
282
-            ->createServerRequest('GET', '/');
283
-
284
-        $fallback = new Fixture\BlankRequestHandler();
285
-
286
-        $router->process($request, $fallback);
287
-
288
-        $this->assertInstanceOf(
289
-            MethodNotAllowedException::class,
290
-            $fallback->getAttribute(Router::ATTR_NAME_FOR_ROUTING_ERROR)
291
-        );
292
-
293
-        $this->assertTrue($fallback->isRunned());
294
-    }
295
-
296
-    /**
297
-     * @return void
298
-     */
299
-    public function testProcessForUndefinedRoute() : void
300
-    {
301
-        $routes = [
302
-            new Fixture\TestRoute(),
303
-            new Fixture\TestRoute(),
304
-            new Fixture\TestRoute(),
305
-        ];
306
-
307
-        $router = new Router();
308
-        $router->addRoutes(...$routes);
309
-
310
-        $request = (new ServerRequestFactory)
311
-            ->createServerRequest($routes[0]->getMethods()[0], '/');
312
-
313
-        $fallback = new Fixture\BlankRequestHandler();
314
-
315
-        $router->process($request, $fallback);
316
-
317
-        $this->assertInstanceOf(
318
-            RouteNotFoundException::class,
319
-            $fallback->getAttribute(Router::ATTR_NAME_FOR_ROUTING_ERROR)
320
-        );
321
-
322
-        $this->assertTrue($fallback->isRunned());
323
-    }
324
-
325
-    /**
326
-     * @return void
327
-     */
328
-    public function testMatchPatterns() : void
329
-    {
330
-        $router = new Router();
331
-        $router->get('test', '/{foo<[0-9]+>}/{bar<[a-zA-Z]+>}(/{baz<.*?>})', new Fixture\BlankRequestHandler());
332
-
333
-        $route = $this->discoverRoute($router, 'GET', '/1990/Surgut/Tyumen');
334
-        $this->assertEquals($route->getAttributes(), [
335
-            'foo' => '1990',
336
-            'bar' => 'Surgut',
337
-            'baz' => 'Tyumen',
338
-        ]);
339
-
340
-        $route = $this->discoverRoute($router, 'GET', '/1990/Surgut/Tyumen/Moscow');
341
-        $this->assertEquals($route->getAttributes(), [
342
-            'foo' => '1990',
343
-            'bar' => 'Surgut',
344
-            'baz' => 'Tyumen/Moscow',
345
-        ]);
346
-
347
-        $route = $this->discoverRoute($router, 'GET', '/Oops/Surgut/Tyumen/Moscow');
348
-        $this->assertNull($route);
349
-
350
-        $route = $this->discoverRoute($router, 'GET', '/1990/2018/Moscow');
351
-        $this->assertNull($route);
352
-    }
353
-
354
-    /**
355
-     * @param Router $router
356
-     * @param string $method
357
-     * @param string $uri
358
-     *
359
-     * @return null|RouteInterface
360
-     */
361
-    private function discoverRoute(Router $router, string $method, string $uri) : ?RouteInterface
362
-    {
363
-        $request = (new ServerRequestFactory)
364
-        ->createServerRequest($method, $uri);
365
-
366
-        try {
367
-            return $router->match($request);
368
-        } catch (ExceptionInterface $e) {
369
-            return null;
370
-        }
371
-    }
31
+	/**
32
+	 * @return void
33
+	 */
34
+	public function testConstructor() : void
35
+	{
36
+		$router = new Router();
37
+
38
+		$this->assertInstanceOf(RouteCollection::class, $router);
39
+		$this->assertInstanceOf(MiddlewareInterface::class, $router);
40
+		$this->assertInstanceOf(RequestHandlerInterface::class, $router);
41
+	}
42
+
43
+	/**
44
+	 * @return void
45
+	 */
46
+	public function testGetRoute() : void
47
+	{
48
+		$routes = [
49
+			new Fixture\TestRoute(),
50
+			new Fixture\TestRoute(),
51
+			new Fixture\TestRoute(),
52
+		];
53
+
54
+		$router = new Router();
55
+		$router->addRoutes(...$routes);
56
+
57
+		$this->assertSame($routes[0], $router->getRoute($routes[0]->getName()));
58
+		$this->assertSame($routes[1], $router->getRoute($routes[1]->getName()));
59
+		$this->assertSame($routes[2], $router->getRoute($routes[2]->getName()));
60
+	}
61
+
62
+	/**
63
+	 * @return void
64
+	 */
65
+	public function testGetUndefinedRoute() : void
66
+	{
67
+		$router = new Router();
68
+
69
+		$this->expectException(RouteNotFoundException::class);
70
+		$router->getRoute('foo');
71
+	}
72
+
73
+	/**
74
+	 * @return void
75
+	 */
76
+	public function testMatch() : void
77
+	{
78
+		$routes = [
79
+			new Fixture\TestRoute(),
80
+			new Fixture\TestRoute(),
81
+			new Fixture\TestRoute(),
82
+			new Fixture\TestRoute(),
83
+			new Fixture\TestRoute(),
84
+		];
85
+
86
+		$router = new Router();
87
+		$router->addRoutes(...$routes);
88
+
89
+		$request = (new ServerRequestFactory)
90
+			->createServerRequest(
91
+				$routes[2]->getMethods()[1],
92
+				$routes[2]->getPath()
93
+			);
94
+
95
+		$foundRoute = $router->match($request);
96
+
97
+		$this->assertSame($routes[2]->getName(), $foundRoute->getName());
98
+	}
99
+
100
+	/**
101
+	 * @return void
102
+	 */
103
+	public function testMatchForUnallowedMethod() : void
104
+	{
105
+		$routes = [
106
+			new Fixture\TestRoute(),
107
+			new Fixture\TestRoute(),
108
+			new Fixture\TestRoute(),
109
+		];
110
+
111
+		$router = new Router();
112
+		$router->addRoutes(...$routes);
113
+
114
+		$request = (new ServerRequestFactory)
115
+			->createServerRequest('GET', '/');
116
+
117
+		$this->expectException(MethodNotAllowedException::class);
118
+
119
+		try {
120
+			$router->match($request);
121
+		} catch (MethodNotAllowedException $e) {
122
+			$allowedMethods = array_merge(
123
+				$routes[0]->getMethods(),
124
+				$routes[1]->getMethods(),
125
+				$routes[2]->getMethods()
126
+			);
127
+
128
+			$this->assertSame($allowedMethods, $e->getAllowedMethods());
129
+
130
+			throw $e;
131
+		}
132
+	}
133
+
134
+	/**
135
+	 * @return void
136
+	 */
137
+	public function testMatchForUndefinedRoute() : void
138
+	{
139
+		$routes = [
140
+			new Fixture\TestRoute(),
141
+			new Fixture\TestRoute(),
142
+			new Fixture\TestRoute(),
143
+		];
144
+
145
+		$router = new Router();
146
+		$router->addRoutes(...$routes);
147
+
148
+		$request = (new ServerRequestFactory)
149
+			->createServerRequest($routes[0]->getMethods()[0], '/');
150
+
151
+		$this->expectException(RouteNotFoundException::class);
152
+		$router->match($request);
153
+	}
154
+
155
+	/**
156
+	 * @return void
157
+	 */
158
+	public function testHandle() : void
159
+	{
160
+		$routes = [
161
+			new Fixture\TestRoute(),
162
+			new Fixture\TestRoute(),
163
+			new Fixture\TestRoute(),
164
+			new Fixture\TestRoute(),
165
+			new Fixture\TestRoute(),
166
+		];
167
+
168
+		$router = new Router();
169
+		$router->addRoutes(...$routes);
170
+
171
+		$request = (new ServerRequestFactory)
172
+			->createServerRequest(
173
+				$routes[2]->getMethods()[1],
174
+				$routes[2]->getPath()
175
+			);
176
+
177
+		$router->handle($request);
178
+
179
+		$this->assertTrue($routes[2]->getRequestHandler()->isRunned());
180
+	}
181
+
182
+	/**
183
+	 * @return void
184
+	 */
185
+	public function testHandleForUnallowedMethod() : void
186
+	{
187
+		$routes = [
188
+			new Fixture\TestRoute(),
189
+			new Fixture\TestRoute(),
190
+			new Fixture\TestRoute(),
191
+		];
192
+
193
+		$router = new Router();
194
+		$router->addRoutes(...$routes);
195
+
196
+		$request = (new ServerRequestFactory)
197
+			->createServerRequest('GET', '/');
198
+
199
+		$this->expectException(MethodNotAllowedException::class);
200
+
201
+		try {
202
+			$router->handle($request);
203
+		} catch (MethodNotAllowedException $e) {
204
+			$allowedMethods = array_merge(
205
+				$routes[0]->getMethods(),
206
+				$routes[1]->getMethods(),
207
+				$routes[2]->getMethods()
208
+			);
209
+
210
+			$this->assertSame($allowedMethods, $e->getAllowedMethods());
211
+
212
+			throw $e;
213
+		}
214
+	}
215
+
216
+	/**
217
+	 * @return void
218
+	 */
219
+	public function testHandleForUndefinedRoute() : void
220
+	{
221
+		$routes = [
222
+			new Fixture\TestRoute(),
223
+			new Fixture\TestRoute(),
224
+			new Fixture\TestRoute(),
225
+		];
226
+
227
+		$router = new Router();
228
+		$router->addRoutes(...$routes);
229
+
230
+		$request = (new ServerRequestFactory)
231
+			->createServerRequest($routes[0]->getMethods()[0], '/');
232
+
233
+		$this->expectException(RouteNotFoundException::class);
234
+		$router->handle($request);
235
+	}
236
+
237
+	/**
238
+	 * @return void
239
+	 */
240
+	public function testProcess() : void
241
+	{
242
+		$routes = [
243
+			new Fixture\TestRoute(),
244
+			new Fixture\TestRoute(),
245
+			new Fixture\TestRoute(),
246
+			new Fixture\TestRoute(),
247
+			new Fixture\TestRoute(),
248
+		];
249
+
250
+		$router = new Router();
251
+		$router->addRoutes(...$routes);
252
+
253
+		$request = (new ServerRequestFactory)
254
+			->createServerRequest(
255
+				$routes[2]->getMethods()[1],
256
+				$routes[2]->getPath()
257
+			);
258
+
259
+		$fallback = new Fixture\BlankRequestHandler();
260
+
261
+		$router->process($request, $fallback);
262
+
263
+		$this->assertTrue($routes[2]->getRequestHandler()->isRunned());
264
+		$this->assertFalse($fallback->isRunned());
265
+	}
266
+
267
+	/**
268
+	 * @return void
269
+	 */
270
+	public function testProcessForUnallowedMethod() : void
271
+	{
272
+		$routes = [
273
+			new Fixture\TestRoute(),
274
+			new Fixture\TestRoute(),
275
+			new Fixture\TestRoute(),
276
+		];
277
+
278
+		$router = new Router();
279
+		$router->addRoutes(...$routes);
280
+
281
+		$request = (new ServerRequestFactory)
282
+			->createServerRequest('GET', '/');
283
+
284
+		$fallback = new Fixture\BlankRequestHandler();
285
+
286
+		$router->process($request, $fallback);
287
+
288
+		$this->assertInstanceOf(
289
+			MethodNotAllowedException::class,
290
+			$fallback->getAttribute(Router::ATTR_NAME_FOR_ROUTING_ERROR)
291
+		);
292
+
293
+		$this->assertTrue($fallback->isRunned());
294
+	}
295
+
296
+	/**
297
+	 * @return void
298
+	 */
299
+	public function testProcessForUndefinedRoute() : void
300
+	{
301
+		$routes = [
302
+			new Fixture\TestRoute(),
303
+			new Fixture\TestRoute(),
304
+			new Fixture\TestRoute(),
305
+		];
306
+
307
+		$router = new Router();
308
+		$router->addRoutes(...$routes);
309
+
310
+		$request = (new ServerRequestFactory)
311
+			->createServerRequest($routes[0]->getMethods()[0], '/');
312
+
313
+		$fallback = new Fixture\BlankRequestHandler();
314
+
315
+		$router->process($request, $fallback);
316
+
317
+		$this->assertInstanceOf(
318
+			RouteNotFoundException::class,
319
+			$fallback->getAttribute(Router::ATTR_NAME_FOR_ROUTING_ERROR)
320
+		);
321
+
322
+		$this->assertTrue($fallback->isRunned());
323
+	}
324
+
325
+	/**
326
+	 * @return void
327
+	 */
328
+	public function testMatchPatterns() : void
329
+	{
330
+		$router = new Router();
331
+		$router->get('test', '/{foo<[0-9]+>}/{bar<[a-zA-Z]+>}(/{baz<.*?>})', new Fixture\BlankRequestHandler());
332
+
333
+		$route = $this->discoverRoute($router, 'GET', '/1990/Surgut/Tyumen');
334
+		$this->assertEquals($route->getAttributes(), [
335
+			'foo' => '1990',
336
+			'bar' => 'Surgut',
337
+			'baz' => 'Tyumen',
338
+		]);
339
+
340
+		$route = $this->discoverRoute($router, 'GET', '/1990/Surgut/Tyumen/Moscow');
341
+		$this->assertEquals($route->getAttributes(), [
342
+			'foo' => '1990',
343
+			'bar' => 'Surgut',
344
+			'baz' => 'Tyumen/Moscow',
345
+		]);
346
+
347
+		$route = $this->discoverRoute($router, 'GET', '/Oops/Surgut/Tyumen/Moscow');
348
+		$this->assertNull($route);
349
+
350
+		$route = $this->discoverRoute($router, 'GET', '/1990/2018/Moscow');
351
+		$this->assertNull($route);
352
+	}
353
+
354
+	/**
355
+	 * @param Router $router
356
+	 * @param string $method
357
+	 * @param string $uri
358
+	 *
359
+	 * @return null|RouteInterface
360
+	 */
361
+	private function discoverRoute(Router $router, string $method, string $uri) : ?RouteInterface
362
+	{
363
+		$request = (new ServerRequestFactory)
364
+		->createServerRequest($method, $uri);
365
+
366
+		try {
367
+			return $router->match($request);
368
+		} catch (ExceptionInterface $e) {
369
+			return null;
370
+		}
371
+	}
372 372
 }
Please login to merge, or discard this patch.
src/RouteInterface.php 1 patch
Indentation   +123 added lines, -123 removed lines patch added patch discarded remove patch
@@ -23,127 +23,127 @@
 block discarded – undo
23 23
 interface RouteInterface
24 24
 {
25 25
 
26
-    /**
27
-     * Gets the route name
28
-     *
29
-     * @return string
30
-     */
31
-    public function getName() : string;
32
-
33
-    /**
34
-     * Gets the route path
35
-     *
36
-     * @return string
37
-     */
38
-    public function getPath() : string;
39
-
40
-    /**
41
-     * Gets the route methods
42
-     *
43
-     * @return string[]
44
-     */
45
-    public function getMethods() : array;
46
-
47
-    /**
48
-     * Gets the route request handler
49
-     *
50
-     * @return RequestHandlerInterface
51
-     */
52
-    public function getRequestHandler() : RequestHandlerInterface;
53
-
54
-    /**
55
-     * Gets the route middlewares
56
-     *
57
-     * @return MiddlewareInterface[]
58
-     */
59
-    public function getMiddlewares() : array;
60
-
61
-    /**
62
-     * Gets the route attributes
63
-     *
64
-     * @return array
65
-     */
66
-    public function getAttributes() : array;
67
-
68
-    /**
69
-     * Sets the given name to the route
70
-     *
71
-     * @param string $name
72
-     *
73
-     * @return RouteInterface
74
-     */
75
-    public function setName(string $name) : RouteInterface;
76
-
77
-    /**
78
-     * Sets the given path to the route
79
-     *
80
-     * @param string $path
81
-     *
82
-     * @return RouteInterface
83
-     */
84
-    public function setPath(string $path) : RouteInterface;
85
-
86
-    /**
87
-     * Sets the given method(s) to the route
88
-     *
89
-     * @param string ...$methods
90
-     *
91
-     * @return RouteInterface
92
-     */
93
-    public function setMethods(string ...$methods) : RouteInterface;
94
-
95
-    /**
96
-     * Sets the given request handler to the route
97
-     *
98
-     * @param RequestHandlerInterface $requestHandler
99
-     *
100
-     * @return RouteInterface
101
-     */
102
-    public function setRequestHandler(RequestHandlerInterface $requestHandler) : RouteInterface;
103
-
104
-    /**
105
-     * Sets the given middleware(s) to the route
106
-     *
107
-     * @param MiddlewareInterface ...$middlewares
108
-     *
109
-     * @return RouteInterface
110
-     */
111
-    public function setMiddlewares(MiddlewareInterface ...$middlewares) : RouteInterface;
112
-
113
-    /**
114
-     * Sets the given attributes to the route
115
-     *
116
-     * @param array $attributes
117
-     *
118
-     * @return RouteInterface
119
-     */
120
-    public function setAttributes(array $attributes) : RouteInterface;
121
-
122
-    /**
123
-     * Returns the route clone with the given attributes
124
-     *
125
-     * This method MUST NOT change the state of the object.
126
-     *
127
-     * @param array $attributes
128
-     *
129
-     * @return RouteInterface
130
-     */
131
-    public function withAddedAttributes(array $attributes) : RouteInterface;
132
-
133
-    /**
134
-     * Builds the route path
135
-     *
136
-     * @param array $attributes
137
-     * @param bool $strict
138
-     *
139
-     * @return string
140
-     */
141
-    public function buildPath(array $attributes, bool $strict) : string;
142
-
143
-    /**
144
-     * Builds the route regex
145
-     *
146
-     * @return string
147
-     */
148
-    public function buildRegex() : string;
26
+	/**
27
+	 * Gets the route name
28
+	 *
29
+	 * @return string
30
+	 */
31
+	public function getName() : string;
32
+
33
+	/**
34
+	 * Gets the route path
35
+	 *
36
+	 * @return string
37
+	 */
38
+	public function getPath() : string;
39
+
40
+	/**
41
+	 * Gets the route methods
42
+	 *
43
+	 * @return string[]
44
+	 */
45
+	public function getMethods() : array;
46
+
47
+	/**
48
+	 * Gets the route request handler
49
+	 *
50
+	 * @return RequestHandlerInterface
51
+	 */
52
+	public function getRequestHandler() : RequestHandlerInterface;
53
+
54
+	/**
55
+	 * Gets the route middlewares
56
+	 *
57
+	 * @return MiddlewareInterface[]
58
+	 */
59
+	public function getMiddlewares() : array;
60
+
61
+	/**
62
+	 * Gets the route attributes
63
+	 *
64
+	 * @return array
65
+	 */
66
+	public function getAttributes() : array;
67
+
68
+	/**
69
+	 * Sets the given name to the route
70
+	 *
71
+	 * @param string $name
72
+	 *
73
+	 * @return RouteInterface
74
+	 */
75
+	public function setName(string $name) : RouteInterface;
76
+
77
+	/**
78
+	 * Sets the given path to the route
79
+	 *
80
+	 * @param string $path
81
+	 *
82
+	 * @return RouteInterface
83
+	 */
84
+	public function setPath(string $path) : RouteInterface;
85
+
86
+	/**
87
+	 * Sets the given method(s) to the route
88
+	 *
89
+	 * @param string ...$methods
90
+	 *
91
+	 * @return RouteInterface
92
+	 */
93
+	public function setMethods(string ...$methods) : RouteInterface;
94
+
95
+	/**
96
+	 * Sets the given request handler to the route
97
+	 *
98
+	 * @param RequestHandlerInterface $requestHandler
99
+	 *
100
+	 * @return RouteInterface
101
+	 */
102
+	public function setRequestHandler(RequestHandlerInterface $requestHandler) : RouteInterface;
103
+
104
+	/**
105
+	 * Sets the given middleware(s) to the route
106
+	 *
107
+	 * @param MiddlewareInterface ...$middlewares
108
+	 *
109
+	 * @return RouteInterface
110
+	 */
111
+	public function setMiddlewares(MiddlewareInterface ...$middlewares) : RouteInterface;
112
+
113
+	/**
114
+	 * Sets the given attributes to the route
115
+	 *
116
+	 * @param array $attributes
117
+	 *
118
+	 * @return RouteInterface
119
+	 */
120
+	public function setAttributes(array $attributes) : RouteInterface;
121
+
122
+	/**
123
+	 * Returns the route clone with the given attributes
124
+	 *
125
+	 * This method MUST NOT change the state of the object.
126
+	 *
127
+	 * @param array $attributes
128
+	 *
129
+	 * @return RouteInterface
130
+	 */
131
+	public function withAddedAttributes(array $attributes) : RouteInterface;
132
+
133
+	/**
134
+	 * Builds the route path
135
+	 *
136
+	 * @param array $attributes
137
+	 * @param bool $strict
138
+	 *
139
+	 * @return string
140
+	 */
141
+	public function buildPath(array $attributes, bool $strict) : string;
142
+
143
+	/**
144
+	 * Builds the route regex
145
+	 *
146
+	 * @return string
147
+	 */
148
+	public function buildRegex() : string;
149 149
 }
Please login to merge, or discard this patch.
src/Annotation/AnnotationRouteLoader.php 1 patch
Indentation   +129 added lines, -129 removed lines patch added patch discarded remove patch
@@ -35,133 +35,133 @@
 block discarded – undo
35 35
 class AnnotationRouteLoader
36 36
 {
37 37
 
38
-    /**
39
-     * @var SimpleAnnotationReader
40
-     */
41
-    private $annotationReader;
42
-
43
-    /**
44
-     * @var SplPriorityQueue
45
-     */
46
-    private $discoveredAnnotations;
47
-
48
-    /**
49
-     * Constructor of the class
50
-     */
51
-    public function __construct()
52
-    {
53
-        $this->annotationReader = new SimpleAnnotationReader();
54
-        $this->annotationReader->addNamespace(__NAMESPACE__);
55
-
56
-        $this->discoveredAnnotations = new SplPriorityQueue();
57
-    }
58
-
59
-    /**
60
-     * Builds discovered routes
61
-     *
62
-     * @param null|callable $objectCreator
63
-     *
64
-     * @return array
65
-     */
66
-    public function buildRoutes(callable $objectCreator = null) : array
67
-    {
68
-        $routes = [];
69
-        foreach ($this->discoveredAnnotations as $annotation) {
70
-            $requestHandlerClass = $annotation->source->getName();
71
-            $requestHandler = $objectCreator ? $objectCreator($requestHandlerClass) : new $requestHandlerClass;
72
-
73
-            $middlewares = [];
74
-            foreach ($annotation->middlewares as $middlewareClass) {
75
-                $middlewares[] = $objectCreator ? $objectCreator($middlewareClass) : new $middlewareClass;
76
-            }
77
-
78
-            $routes[] = new BaseRoute(
79
-                $annotation->name,
80
-                $annotation->path,
81
-                $annotation->methods,
82
-                $requestHandler,
83
-                $middlewares,
84
-                $annotation->attributes
85
-            );
86
-        }
87
-
88
-        return $routes;
89
-    }
90
-
91
-    /**
92
-     * Discovers routes in the given destination
93
-     *
94
-     * @param string $destination
95
-     *
96
-     * @return void
97
-     */
98
-    public function discover(string $destination) : void
99
-    {
100
-        $annotations = $this->findAnnotations($destination, Route::class);
101
-
102
-        foreach ($annotations as $annotation) {
103
-            $this->discoveredAnnotations->insert($annotation, $annotation->priority);
104
-        }
105
-    }
106
-
107
-    /**
108
-     * Finds annotations in the given destination
109
-     *
110
-     * @param string $destination
111
-     * @param string $name
112
-     *
113
-     * @return array
114
-     */
115
-    private function findAnnotations(string $destination, string $name) : array
116
-    {
117
-        $classes = $this->findClasses($destination);
118
-        $annotations = [];
119
-
120
-        foreach ($classes as $class) {
121
-            $class = new ReflectionClass($class);
122
-            $annotation = $this->annotationReader->getClassAnnotation($class, $name);
123
-
124
-            if ($annotation instanceof $name) {
125
-                $annotation->source = $class;
126
-                $annotations[] = $annotation;
127
-            }
128
-        }
129
-
130
-        return $annotations;
131
-    }
132
-
133
-    /**
134
-     * Finds classes in the given destination
135
-     *
136
-     * @param string $destination
137
-     *
138
-     * @return array
139
-     */
140
-    private function findClasses(string $destination) : array
141
-    {
142
-        $files = $this->findFiles($destination);
143
-        $classes = get_declared_classes();
144
-
145
-        foreach ($files as $file) {
146
-            require_once $file->getRealPath();
147
-        }
148
-
149
-        return array_diff(get_declared_classes(), $classes);
150
-    }
151
-
152
-    /**
153
-     * Finds files in the given destination
154
-     *
155
-     * @param string $destination
156
-     *
157
-     * @return array
158
-     */
159
-    private function findFiles(string $destination) : array
160
-    {
161
-        $directory = new RecursiveDirectoryIterator($destination);
162
-        $iterator = new RecursiveIteratorIterator($directory);
163
-        $files = new RegexIterator($iterator, '/\.php$/');
164
-
165
-        return iterator_to_array($files);
166
-    }
38
+	/**
39
+	 * @var SimpleAnnotationReader
40
+	 */
41
+	private $annotationReader;
42
+
43
+	/**
44
+	 * @var SplPriorityQueue
45
+	 */
46
+	private $discoveredAnnotations;
47
+
48
+	/**
49
+	 * Constructor of the class
50
+	 */
51
+	public function __construct()
52
+	{
53
+		$this->annotationReader = new SimpleAnnotationReader();
54
+		$this->annotationReader->addNamespace(__NAMESPACE__);
55
+
56
+		$this->discoveredAnnotations = new SplPriorityQueue();
57
+	}
58
+
59
+	/**
60
+	 * Builds discovered routes
61
+	 *
62
+	 * @param null|callable $objectCreator
63
+	 *
64
+	 * @return array
65
+	 */
66
+	public function buildRoutes(callable $objectCreator = null) : array
67
+	{
68
+		$routes = [];
69
+		foreach ($this->discoveredAnnotations as $annotation) {
70
+			$requestHandlerClass = $annotation->source->getName();
71
+			$requestHandler = $objectCreator ? $objectCreator($requestHandlerClass) : new $requestHandlerClass;
72
+
73
+			$middlewares = [];
74
+			foreach ($annotation->middlewares as $middlewareClass) {
75
+				$middlewares[] = $objectCreator ? $objectCreator($middlewareClass) : new $middlewareClass;
76
+			}
77
+
78
+			$routes[] = new BaseRoute(
79
+				$annotation->name,
80
+				$annotation->path,
81
+				$annotation->methods,
82
+				$requestHandler,
83
+				$middlewares,
84
+				$annotation->attributes
85
+			);
86
+		}
87
+
88
+		return $routes;
89
+	}
90
+
91
+	/**
92
+	 * Discovers routes in the given destination
93
+	 *
94
+	 * @param string $destination
95
+	 *
96
+	 * @return void
97
+	 */
98
+	public function discover(string $destination) : void
99
+	{
100
+		$annotations = $this->findAnnotations($destination, Route::class);
101
+
102
+		foreach ($annotations as $annotation) {
103
+			$this->discoveredAnnotations->insert($annotation, $annotation->priority);
104
+		}
105
+	}
106
+
107
+	/**
108
+	 * Finds annotations in the given destination
109
+	 *
110
+	 * @param string $destination
111
+	 * @param string $name
112
+	 *
113
+	 * @return array
114
+	 */
115
+	private function findAnnotations(string $destination, string $name) : array
116
+	{
117
+		$classes = $this->findClasses($destination);
118
+		$annotations = [];
119
+
120
+		foreach ($classes as $class) {
121
+			$class = new ReflectionClass($class);
122
+			$annotation = $this->annotationReader->getClassAnnotation($class, $name);
123
+
124
+			if ($annotation instanceof $name) {
125
+				$annotation->source = $class;
126
+				$annotations[] = $annotation;
127
+			}
128
+		}
129
+
130
+		return $annotations;
131
+	}
132
+
133
+	/**
134
+	 * Finds classes in the given destination
135
+	 *
136
+	 * @param string $destination
137
+	 *
138
+	 * @return array
139
+	 */
140
+	private function findClasses(string $destination) : array
141
+	{
142
+		$files = $this->findFiles($destination);
143
+		$classes = get_declared_classes();
144
+
145
+		foreach ($files as $file) {
146
+			require_once $file->getRealPath();
147
+		}
148
+
149
+		return array_diff(get_declared_classes(), $classes);
150
+	}
151
+
152
+	/**
153
+	 * Finds files in the given destination
154
+	 *
155
+	 * @param string $destination
156
+	 *
157
+	 * @return array
158
+	 */
159
+	private function findFiles(string $destination) : array
160
+	{
161
+		$directory = new RecursiveDirectoryIterator($destination);
162
+		$iterator = new RecursiveIteratorIterator($directory);
163
+		$files = new RegexIterator($iterator, '/\.php$/');
164
+
165
+		return iterator_to_array($files);
166
+	}
167 167
 }
Please login to merge, or discard this patch.
src/Annotation/Route.php 1 patch
Indentation   +89 added lines, -89 removed lines patch added patch discarded remove patch
@@ -33,93 +33,93 @@
 block discarded – undo
33 33
 final class Route
34 34
 {
35 35
 
36
-    /**
37
-     * @var object
38
-     */
39
-    public $source;
40
-
41
-    /**
42
-     * @var string
43
-     */
44
-    public $name;
45
-
46
-    /**
47
-     * @var string
48
-     */
49
-    public $path;
50
-
51
-    /**
52
-     * @var array
53
-     */
54
-    public $methods;
55
-
56
-    /**
57
-     * @var array
58
-     */
59
-    public $middlewares = [];
60
-
61
-    /**
62
-     * @var array
63
-     */
64
-    public $attributes = [];
65
-
66
-    /**
67
-     * @var int
68
-     */
69
-    public $priority = 0;
70
-
71
-    /**
72
-     * @param array $params
73
-     *
74
-     * @throws InvalidArgumentException
75
-     */
76
-    public function __construct(array $params)
77
-    {
78
-        if (empty($params['name']) || !is_string($params['name'])) {
79
-            throw new InvalidArgumentException('@Route.name must be not an empty string.');
80
-        }
81
-        if (empty($params['path']) || !is_string($params['path'])) {
82
-            throw new InvalidArgumentException('@Route.path must be not an empty string.');
83
-        }
84
-        if (empty($params['methods']) || !is_array($params['methods'])) {
85
-            throw new InvalidArgumentException('@Route.methods must be not an empty array.');
86
-        }
87
-        if (isset($params['middlewares']) && !is_array($params['middlewares'])) {
88
-            throw new InvalidArgumentException('@Route.middlewares must be an array.');
89
-        }
90
-        if (isset($params['attributes']) && !is_array($params['attributes'])) {
91
-            throw new InvalidArgumentException('@Route.attributes must be an array.');
92
-        }
93
-        if (isset($params['priority']) && !is_int($params['priority'])) {
94
-            throw new InvalidArgumentException('@Route.priority must be an integer.');
95
-        }
96
-
97
-        foreach ($params['methods'] as $v) {
98
-            if (!is_string($v)) {
99
-                throw new InvalidArgumentException('@Route.methods must contain only strings.');
100
-            }
101
-        }
102
-
103
-        if (isset($params['middlewares'])) {
104
-            foreach ($params['middlewares'] as $v) {
105
-                if (!is_string($v) || !class_exists($v) || !is_subclass_of($v, MiddlewareInterface::class)) {
106
-                    throw new InvalidArgumentException('@Route.middlewares must contain only middlewares.');
107
-                }
108
-            }
109
-        }
110
-
111
-        $this->name = $params['name'];
112
-        $this->path = $params['path'];
113
-        $this->methods = $params['methods'];
114
-
115
-        if (isset($params['middlewares'])) {
116
-            $this->middlewares = $params['middlewares'];
117
-        }
118
-        if (isset($params['attributes'])) {
119
-            $this->attributes = $params['attributes'];
120
-        }
121
-        if (isset($params['priority'])) {
122
-            $this->priority = $params['priority'];
123
-        }
124
-    }
36
+	/**
37
+	 * @var object
38
+	 */
39
+	public $source;
40
+
41
+	/**
42
+	 * @var string
43
+	 */
44
+	public $name;
45
+
46
+	/**
47
+	 * @var string
48
+	 */
49
+	public $path;
50
+
51
+	/**
52
+	 * @var array
53
+	 */
54
+	public $methods;
55
+
56
+	/**
57
+	 * @var array
58
+	 */
59
+	public $middlewares = [];
60
+
61
+	/**
62
+	 * @var array
63
+	 */
64
+	public $attributes = [];
65
+
66
+	/**
67
+	 * @var int
68
+	 */
69
+	public $priority = 0;
70
+
71
+	/**
72
+	 * @param array $params
73
+	 *
74
+	 * @throws InvalidArgumentException
75
+	 */
76
+	public function __construct(array $params)
77
+	{
78
+		if (empty($params['name']) || !is_string($params['name'])) {
79
+			throw new InvalidArgumentException('@Route.name must be not an empty string.');
80
+		}
81
+		if (empty($params['path']) || !is_string($params['path'])) {
82
+			throw new InvalidArgumentException('@Route.path must be not an empty string.');
83
+		}
84
+		if (empty($params['methods']) || !is_array($params['methods'])) {
85
+			throw new InvalidArgumentException('@Route.methods must be not an empty array.');
86
+		}
87
+		if (isset($params['middlewares']) && !is_array($params['middlewares'])) {
88
+			throw new InvalidArgumentException('@Route.middlewares must be an array.');
89
+		}
90
+		if (isset($params['attributes']) && !is_array($params['attributes'])) {
91
+			throw new InvalidArgumentException('@Route.attributes must be an array.');
92
+		}
93
+		if (isset($params['priority']) && !is_int($params['priority'])) {
94
+			throw new InvalidArgumentException('@Route.priority must be an integer.');
95
+		}
96
+
97
+		foreach ($params['methods'] as $v) {
98
+			if (!is_string($v)) {
99
+				throw new InvalidArgumentException('@Route.methods must contain only strings.');
100
+			}
101
+		}
102
+
103
+		if (isset($params['middlewares'])) {
104
+			foreach ($params['middlewares'] as $v) {
105
+				if (!is_string($v) || !class_exists($v) || !is_subclass_of($v, MiddlewareInterface::class)) {
106
+					throw new InvalidArgumentException('@Route.middlewares must contain only middlewares.');
107
+				}
108
+			}
109
+		}
110
+
111
+		$this->name = $params['name'];
112
+		$this->path = $params['path'];
113
+		$this->methods = $params['methods'];
114
+
115
+		if (isset($params['middlewares'])) {
116
+			$this->middlewares = $params['middlewares'];
117
+		}
118
+		if (isset($params['attributes'])) {
119
+			$this->attributes = $params['attributes'];
120
+		}
121
+		if (isset($params['priority'])) {
122
+			$this->priority = $params['priority'];
123
+		}
124
+	}
125 125
 }
Please login to merge, or discard this patch.
src/RequestHandler/RoutableRequestHandler.php 1 patch
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -25,45 +25,45 @@
 block discarded – undo
25 25
 class RoutableRequestHandler implements RequestHandlerInterface
26 26
 {
27 27
 
28
-    /**
29
-     * Server Request attribute name for a route name
30
-     *
31
-     * @var string
32
-     */
33
-    public const ATTR_NAME_FOR_ROUTE_NAME = '@route-name';
28
+	/**
29
+	 * Server Request attribute name for a route name
30
+	 *
31
+	 * @var string
32
+	 */
33
+	public const ATTR_NAME_FOR_ROUTE_NAME = '@route-name';
34 34
 
35
-    /**
36
-     * The request handler route
37
-     *
38
-     * @var RouteInterface
39
-     */
40
-    private $route;
35
+	/**
36
+	 * The request handler route
37
+	 *
38
+	 * @var RouteInterface
39
+	 */
40
+	private $route;
41 41
 
42
-    /**
43
-     * Constructor of the class
44
-     *
45
-     * @param RouteInterface $route
46
-     */
47
-    public function __construct(RouteInterface $route)
48
-    {
49
-        $this->route = $route;
50
-    }
42
+	/**
43
+	 * Constructor of the class
44
+	 *
45
+	 * @param RouteInterface $route
46
+	 */
47
+	public function __construct(RouteInterface $route)
48
+	{
49
+		$this->route = $route;
50
+	}
51 51
 
52
-    /**
53
-     * {@inheritDoc}
54
-     */
55
-    public function handle(ServerRequestInterface $request) : ResponseInterface
56
-    {
57
-        $request = $request->withAttribute(self::ATTR_NAME_FOR_ROUTE_NAME, $this->route->getName());
52
+	/**
53
+	 * {@inheritDoc}
54
+	 */
55
+	public function handle(ServerRequestInterface $request) : ResponseInterface
56
+	{
57
+		$request = $request->withAttribute(self::ATTR_NAME_FOR_ROUTE_NAME, $this->route->getName());
58 58
 
59
-        foreach ($this->route->getAttributes() as $key => $value) {
60
-            $request = $request->withAttribute($key, $value);
61
-        }
59
+		foreach ($this->route->getAttributes() as $key => $value) {
60
+			$request = $request->withAttribute($key, $value);
61
+		}
62 62
 
63
-        $handler = new QueueableRequestHandler($this->route->getRequestHandler());
63
+		$handler = new QueueableRequestHandler($this->route->getRequestHandler());
64 64
 
65
-        $handler->add(...$this->route->getMiddlewares());
65
+		$handler->add(...$this->route->getMiddlewares());
66 66
 
67
-        return $handler->handle($request);
68
-    }
67
+		return $handler->handle($request);
68
+	}
69 69
 }
Please login to merge, or discard this patch.