@@ -16,62 +16,62 @@ |
||
16 | 16 | class BlankRequestHandler implements RequestHandlerInterface |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var bool |
|
21 | - */ |
|
22 | - private $isRunned = false; |
|
19 | + /** |
|
20 | + * @var bool |
|
21 | + */ |
|
22 | + private $isRunned = false; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @var array |
|
26 | - */ |
|
27 | - private $attributes = []; |
|
24 | + /** |
|
25 | + * @var array |
|
26 | + */ |
|
27 | + private $attributes = []; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @return bool |
|
31 | - */ |
|
32 | - public function isRunned() : bool |
|
33 | - { |
|
34 | - return $this->isRunned; |
|
35 | - } |
|
29 | + /** |
|
30 | + * @return bool |
|
31 | + */ |
|
32 | + public function isRunned() : bool |
|
33 | + { |
|
34 | + return $this->isRunned; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * @return array |
|
39 | - */ |
|
40 | - public function getAttributes() : array |
|
41 | - { |
|
42 | - return $this->attributes; |
|
43 | - } |
|
37 | + /** |
|
38 | + * @return array |
|
39 | + */ |
|
40 | + public function getAttributes() : array |
|
41 | + { |
|
42 | + return $this->attributes; |
|
43 | + } |
|
44 | 44 | |
45 | - /** |
|
46 | - * @param mixed $key |
|
47 | - * |
|
48 | - * @return mixed |
|
49 | - */ |
|
50 | - public function getAttribute($key) |
|
51 | - { |
|
52 | - return $this->attributes[$key] ?? null; |
|
53 | - } |
|
45 | + /** |
|
46 | + * @param mixed $key |
|
47 | + * |
|
48 | + * @return mixed |
|
49 | + */ |
|
50 | + public function getAttribute($key) |
|
51 | + { |
|
52 | + return $this->attributes[$key] ?? null; |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * {@inheritDoc} |
|
57 | - */ |
|
58 | - public function handle(ServerRequestInterface $request) : ResponseInterface |
|
59 | - { |
|
60 | - $this->isRunned = true; |
|
61 | - $this->attributes = $request->getAttributes(); |
|
55 | + /** |
|
56 | + * {@inheritDoc} |
|
57 | + */ |
|
58 | + public function handle(ServerRequestInterface $request) : ResponseInterface |
|
59 | + { |
|
60 | + $this->isRunned = true; |
|
61 | + $this->attributes = $request->getAttributes(); |
|
62 | 62 | |
63 | - return (new ResponseFactory)->createResponse(); |
|
64 | - } |
|
63 | + return (new ResponseFactory)->createResponse(); |
|
64 | + } |
|
65 | 65 | |
66 | - /** |
|
67 | - * @param ServerRequestInterface $request |
|
68 | - * |
|
69 | - * @return ResponseInterface |
|
70 | - * |
|
71 | - * @link https://www.php.net/manual/ru/language.oop5.magic.php#object.invoke |
|
72 | - */ |
|
73 | - public function __invoke(ServerRequestInterface $request) : ResponseInterface |
|
74 | - { |
|
75 | - return $this->handle($request); |
|
76 | - } |
|
66 | + /** |
|
67 | + * @param ServerRequestInterface $request |
|
68 | + * |
|
69 | + * @return ResponseInterface |
|
70 | + * |
|
71 | + * @link https://www.php.net/manual/ru/language.oop5.magic.php#object.invoke |
|
72 | + */ |
|
73 | + public function __invoke(ServerRequestInterface $request) : ResponseInterface |
|
74 | + { |
|
75 | + return $this->handle($request); |
|
76 | + } |
|
77 | 77 | } |
@@ -21,91 +21,91 @@ |
||
21 | 21 | class TestRoute extends BaseRoute |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var int |
|
26 | - */ |
|
27 | - public const WITH_BROKEN_MIDDLEWARE = 1; |
|
24 | + /** |
|
25 | + * @var int |
|
26 | + */ |
|
27 | + public const WITH_BROKEN_MIDDLEWARE = 1; |
|
28 | 28 | |
29 | - /** |
|
30 | - * Constructor of the class |
|
31 | - * |
|
32 | - * @param int $flags |
|
33 | - */ |
|
34 | - public function __construct(int $flags = 0) |
|
35 | - { |
|
36 | - parent::__construct( |
|
37 | - self::getTestRouteName($flags), |
|
38 | - self::getTestRoutePath($flags), |
|
39 | - self::getTestRouteMethods($flags), |
|
40 | - self::getTestRouteRequestHandler($flags), |
|
41 | - self::getTestRouteMiddlewares($flags), |
|
42 | - self::getTestRouteAttributes($flags) |
|
43 | - ); |
|
44 | - } |
|
29 | + /** |
|
30 | + * Constructor of the class |
|
31 | + * |
|
32 | + * @param int $flags |
|
33 | + */ |
|
34 | + public function __construct(int $flags = 0) |
|
35 | + { |
|
36 | + parent::__construct( |
|
37 | + self::getTestRouteName($flags), |
|
38 | + self::getTestRoutePath($flags), |
|
39 | + self::getTestRouteMethods($flags), |
|
40 | + self::getTestRouteRequestHandler($flags), |
|
41 | + self::getTestRouteMiddlewares($flags), |
|
42 | + self::getTestRouteAttributes($flags) |
|
43 | + ); |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @return string |
|
48 | - */ |
|
49 | - public static function getTestRouteName(int $flags = 0) : string |
|
50 | - { |
|
51 | - return uniqid() . '.' . uniqid() . '.' . uniqid(); |
|
52 | - } |
|
46 | + /** |
|
47 | + * @return string |
|
48 | + */ |
|
49 | + public static function getTestRouteName(int $flags = 0) : string |
|
50 | + { |
|
51 | + return uniqid() . '.' . uniqid() . '.' . uniqid(); |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - public static function getTestRoutePath(int $flags = 0) : string |
|
58 | - { |
|
59 | - return '/' . uniqid() . '/' . uniqid() . '/' . uniqid(); |
|
60 | - } |
|
54 | + /** |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + public static function getTestRoutePath(int $flags = 0) : string |
|
58 | + { |
|
59 | + return '/' . uniqid() . '/' . uniqid() . '/' . uniqid(); |
|
60 | + } |
|
61 | 61 | |
62 | - /** |
|
63 | - * @return string[] |
|
64 | - */ |
|
65 | - public static function getTestRouteMethods(int $flags = 0) : array |
|
66 | - { |
|
67 | - return [ |
|
68 | - strtoupper(uniqid()), |
|
69 | - strtoupper(uniqid()), |
|
70 | - strtoupper(uniqid()), |
|
71 | - ]; |
|
72 | - } |
|
62 | + /** |
|
63 | + * @return string[] |
|
64 | + */ |
|
65 | + public static function getTestRouteMethods(int $flags = 0) : array |
|
66 | + { |
|
67 | + return [ |
|
68 | + strtoupper(uniqid()), |
|
69 | + strtoupper(uniqid()), |
|
70 | + strtoupper(uniqid()), |
|
71 | + ]; |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return RequestHandlerInterface |
|
76 | - */ |
|
77 | - public static function getTestRouteRequestHandler(int $flags = 0) : RequestHandlerInterface |
|
78 | - { |
|
79 | - return new BlankRequestHandler(); |
|
80 | - } |
|
74 | + /** |
|
75 | + * @return RequestHandlerInterface |
|
76 | + */ |
|
77 | + public static function getTestRouteRequestHandler(int $flags = 0) : RequestHandlerInterface |
|
78 | + { |
|
79 | + return new BlankRequestHandler(); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * @return MiddlewareInterface[] |
|
84 | - */ |
|
85 | - public static function getTestRouteMiddlewares(int $flags = 0) : array |
|
86 | - { |
|
87 | - $middlewares = [new BlankMiddleware()]; |
|
82 | + /** |
|
83 | + * @return MiddlewareInterface[] |
|
84 | + */ |
|
85 | + public static function getTestRouteMiddlewares(int $flags = 0) : array |
|
86 | + { |
|
87 | + $middlewares = [new BlankMiddleware()]; |
|
88 | 88 | |
89 | - if ($flags & self::WITH_BROKEN_MIDDLEWARE) { |
|
90 | - $middlewares[] = new BlankMiddleware(true); |
|
91 | - } else { |
|
92 | - $middlewares[] = new BlankMiddleware(); |
|
93 | - } |
|
89 | + if ($flags & self::WITH_BROKEN_MIDDLEWARE) { |
|
90 | + $middlewares[] = new BlankMiddleware(true); |
|
91 | + } else { |
|
92 | + $middlewares[] = new BlankMiddleware(); |
|
93 | + } |
|
94 | 94 | |
95 | - $middlewares[] = new BlankMiddleware(); |
|
95 | + $middlewares[] = new BlankMiddleware(); |
|
96 | 96 | |
97 | - return $middlewares; |
|
98 | - } |
|
97 | + return $middlewares; |
|
98 | + } |
|
99 | 99 | |
100 | - /** |
|
101 | - * @return array |
|
102 | - */ |
|
103 | - public static function getTestRouteAttributes(int $flags = 0) : array |
|
104 | - { |
|
105 | - return [ |
|
106 | - uniqid() => uniqid(), |
|
107 | - uniqid() => uniqid(), |
|
108 | - uniqid() => uniqid(), |
|
109 | - ]; |
|
110 | - } |
|
100 | + /** |
|
101 | + * @return array |
|
102 | + */ |
|
103 | + public static function getTestRouteAttributes(int $flags = 0) : array |
|
104 | + { |
|
105 | + return [ |
|
106 | + uniqid() => uniqid(), |
|
107 | + uniqid() => uniqid(), |
|
108 | + uniqid() => uniqid(), |
|
109 | + ]; |
|
110 | + } |
|
111 | 111 | } |
@@ -17,51 +17,51 @@ |
||
17 | 17 | class BlankMiddleware implements MiddlewareInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var bool |
|
22 | - */ |
|
23 | - private $isBroken; |
|
20 | + /** |
|
21 | + * @var bool |
|
22 | + */ |
|
23 | + private $isBroken; |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var bool |
|
27 | - */ |
|
28 | - private $isRunned = false; |
|
25 | + /** |
|
26 | + * @var bool |
|
27 | + */ |
|
28 | + private $isRunned = false; |
|
29 | 29 | |
30 | - /** |
|
31 | - * @param bool $isBroken |
|
32 | - */ |
|
33 | - public function __construct(bool $isBroken = false) |
|
34 | - { |
|
35 | - $this->isBroken = $isBroken; |
|
36 | - } |
|
30 | + /** |
|
31 | + * @param bool $isBroken |
|
32 | + */ |
|
33 | + public function __construct(bool $isBroken = false) |
|
34 | + { |
|
35 | + $this->isBroken = $isBroken; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * @return bool |
|
40 | - */ |
|
41 | - public function isBroken() : bool |
|
42 | - { |
|
43 | - return $this->isBroken; |
|
44 | - } |
|
38 | + /** |
|
39 | + * @return bool |
|
40 | + */ |
|
41 | + public function isBroken() : bool |
|
42 | + { |
|
43 | + return $this->isBroken; |
|
44 | + } |
|
45 | 45 | |
46 | - /** |
|
47 | - * @return bool |
|
48 | - */ |
|
49 | - public function isRunned() : bool |
|
50 | - { |
|
51 | - return $this->isRunned; |
|
52 | - } |
|
46 | + /** |
|
47 | + * @return bool |
|
48 | + */ |
|
49 | + public function isRunned() : bool |
|
50 | + { |
|
51 | + return $this->isRunned; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * {@inheritDoc} |
|
56 | - */ |
|
57 | - public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface |
|
58 | - { |
|
59 | - $this->isRunned = true; |
|
54 | + /** |
|
55 | + * {@inheritDoc} |
|
56 | + */ |
|
57 | + public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface |
|
58 | + { |
|
59 | + $this->isRunned = true; |
|
60 | 60 | |
61 | - if ($this->isBroken) { |
|
62 | - return (new ResponseFactory)->createResponse(); |
|
63 | - } |
|
61 | + if ($this->isBroken) { |
|
62 | + return (new ResponseFactory)->createResponse(); |
|
63 | + } |
|
64 | 64 | |
65 | - return $handler->handle($request); |
|
66 | - } |
|
65 | + return $handler->handle($request); |
|
66 | + } |
|
67 | 67 | } |
@@ -17,28 +17,28 @@ |
||
17 | 17 | class CallableRequestHandlerTest extends TestCase |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @return void |
|
22 | - */ |
|
23 | - public function testConstructor() : void |
|
24 | - { |
|
25 | - $callback = new Fixture\BlankRequestHandler(); |
|
26 | - $requestHandler = new CallableRequestHandler($callback); |
|
27 | - |
|
28 | - $this->assertInstanceOf(RequestHandlerInterface::class, $requestHandler); |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public function testHandle() : void |
|
35 | - { |
|
36 | - $callback = new Fixture\BlankRequestHandler(); |
|
37 | - $requestHandler = new CallableRequestHandler($callback); |
|
38 | - |
|
39 | - $request = (new ServerRequestFactory)->createServerRequest('GET', '/'); |
|
40 | - $requestHandler->handle($request); |
|
41 | - |
|
42 | - $this->assertTrue($callback->isRunned()); |
|
43 | - } |
|
20 | + /** |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + public function testConstructor() : void |
|
24 | + { |
|
25 | + $callback = new Fixture\BlankRequestHandler(); |
|
26 | + $requestHandler = new CallableRequestHandler($callback); |
|
27 | + |
|
28 | + $this->assertInstanceOf(RequestHandlerInterface::class, $requestHandler); |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public function testHandle() : void |
|
35 | + { |
|
36 | + $callback = new Fixture\BlankRequestHandler(); |
|
37 | + $requestHandler = new CallableRequestHandler($callback); |
|
38 | + |
|
39 | + $request = (new ServerRequestFactory)->createServerRequest('GET', '/'); |
|
40 | + $requestHandler->handle($request); |
|
41 | + |
|
42 | + $this->assertTrue($callback->isRunned()); |
|
43 | + } |
|
44 | 44 | } |
@@ -17,76 +17,76 @@ |
||
17 | 17 | class QueueableRequestHandlerTest extends TestCase |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @return void |
|
22 | - */ |
|
23 | - public function testConstructor() : void |
|
24 | - { |
|
25 | - $endpoint = new Fixture\BlankRequestHandler(); |
|
26 | - $requestHandler = new QueueableRequestHandler($endpoint); |
|
27 | - |
|
28 | - $this->assertInstanceOf(RequestHandlerInterface::class, $requestHandler); |
|
29 | - } |
|
30 | - |
|
31 | - /** |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public function testHandle() : void |
|
35 | - { |
|
36 | - $endpoint = new Fixture\BlankRequestHandler(); |
|
37 | - $requestHandler = new QueueableRequestHandler($endpoint); |
|
38 | - |
|
39 | - $request = (new ServerRequestFactory)->createServerRequest('GET', '/'); |
|
40 | - $requestHandler->handle($request); |
|
41 | - |
|
42 | - $this->assertTrue($endpoint->isRunned()); |
|
43 | - } |
|
44 | - |
|
45 | - /** |
|
46 | - * @return void |
|
47 | - */ |
|
48 | - public function testHandleWithMiddlewares() : void |
|
49 | - { |
|
50 | - $middlewares = [ |
|
51 | - new Fixture\BlankMiddleware(), |
|
52 | - new Fixture\BlankMiddleware(), |
|
53 | - new Fixture\BlankMiddleware(), |
|
54 | - ]; |
|
55 | - |
|
56 | - $endpoint = new Fixture\BlankRequestHandler(); |
|
57 | - $requestHandler = new QueueableRequestHandler($endpoint); |
|
58 | - $requestHandler->add(...$middlewares); |
|
59 | - |
|
60 | - $request = (new ServerRequestFactory)->createServerRequest('GET', '/'); |
|
61 | - $requestHandler->handle($request); |
|
62 | - |
|
63 | - $this->assertTrue($middlewares[0]->isRunned()); |
|
64 | - $this->assertTrue($middlewares[1]->isRunned()); |
|
65 | - $this->assertTrue($middlewares[2]->isRunned()); |
|
66 | - $this->assertTrue($endpoint->isRunned()); |
|
67 | - } |
|
68 | - |
|
69 | - /** |
|
70 | - * @return void |
|
71 | - */ |
|
72 | - public function testHandleWithBrokenMiddleware() : void |
|
73 | - { |
|
74 | - $middlewares = [ |
|
75 | - new Fixture\BlankMiddleware(), |
|
76 | - new Fixture\BlankMiddleware(true), |
|
77 | - new Fixture\BlankMiddleware(), |
|
78 | - ]; |
|
79 | - |
|
80 | - $endpoint = new Fixture\BlankRequestHandler(); |
|
81 | - $requestHandler = new QueueableRequestHandler($endpoint); |
|
82 | - $requestHandler->add(...$middlewares); |
|
83 | - |
|
84 | - $request = (new ServerRequestFactory)->createServerRequest('GET', '/'); |
|
85 | - $requestHandler->handle($request); |
|
86 | - |
|
87 | - $this->assertTrue($middlewares[0]->isRunned()); |
|
88 | - $this->assertTrue($middlewares[1]->isRunned()); |
|
89 | - $this->assertFalse($middlewares[2]->isRunned()); |
|
90 | - $this->assertFalse($endpoint->isRunned()); |
|
91 | - } |
|
20 | + /** |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + public function testConstructor() : void |
|
24 | + { |
|
25 | + $endpoint = new Fixture\BlankRequestHandler(); |
|
26 | + $requestHandler = new QueueableRequestHandler($endpoint); |
|
27 | + |
|
28 | + $this->assertInstanceOf(RequestHandlerInterface::class, $requestHandler); |
|
29 | + } |
|
30 | + |
|
31 | + /** |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public function testHandle() : void |
|
35 | + { |
|
36 | + $endpoint = new Fixture\BlankRequestHandler(); |
|
37 | + $requestHandler = new QueueableRequestHandler($endpoint); |
|
38 | + |
|
39 | + $request = (new ServerRequestFactory)->createServerRequest('GET', '/'); |
|
40 | + $requestHandler->handle($request); |
|
41 | + |
|
42 | + $this->assertTrue($endpoint->isRunned()); |
|
43 | + } |
|
44 | + |
|
45 | + /** |
|
46 | + * @return void |
|
47 | + */ |
|
48 | + public function testHandleWithMiddlewares() : void |
|
49 | + { |
|
50 | + $middlewares = [ |
|
51 | + new Fixture\BlankMiddleware(), |
|
52 | + new Fixture\BlankMiddleware(), |
|
53 | + new Fixture\BlankMiddleware(), |
|
54 | + ]; |
|
55 | + |
|
56 | + $endpoint = new Fixture\BlankRequestHandler(); |
|
57 | + $requestHandler = new QueueableRequestHandler($endpoint); |
|
58 | + $requestHandler->add(...$middlewares); |
|
59 | + |
|
60 | + $request = (new ServerRequestFactory)->createServerRequest('GET', '/'); |
|
61 | + $requestHandler->handle($request); |
|
62 | + |
|
63 | + $this->assertTrue($middlewares[0]->isRunned()); |
|
64 | + $this->assertTrue($middlewares[1]->isRunned()); |
|
65 | + $this->assertTrue($middlewares[2]->isRunned()); |
|
66 | + $this->assertTrue($endpoint->isRunned()); |
|
67 | + } |
|
68 | + |
|
69 | + /** |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + public function testHandleWithBrokenMiddleware() : void |
|
73 | + { |
|
74 | + $middlewares = [ |
|
75 | + new Fixture\BlankMiddleware(), |
|
76 | + new Fixture\BlankMiddleware(true), |
|
77 | + new Fixture\BlankMiddleware(), |
|
78 | + ]; |
|
79 | + |
|
80 | + $endpoint = new Fixture\BlankRequestHandler(); |
|
81 | + $requestHandler = new QueueableRequestHandler($endpoint); |
|
82 | + $requestHandler->add(...$middlewares); |
|
83 | + |
|
84 | + $request = (new ServerRequestFactory)->createServerRequest('GET', '/'); |
|
85 | + $requestHandler->handle($request); |
|
86 | + |
|
87 | + $this->assertTrue($middlewares[0]->isRunned()); |
|
88 | + $this->assertTrue($middlewares[1]->isRunned()); |
|
89 | + $this->assertFalse($middlewares[2]->isRunned()); |
|
90 | + $this->assertFalse($endpoint->isRunned()); |
|
91 | + } |
|
92 | 92 | } |
@@ -17,54 +17,54 @@ |
||
17 | 17 | class RoutableRequestHandlerTest extends TestCase |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @return void |
|
22 | - */ |
|
23 | - public function testConstructor() : void |
|
24 | - { |
|
25 | - $testRoute = new Fixture\TestRoute(); |
|
26 | - $requestHandler = new RoutableRequestHandler($testRoute); |
|
20 | + /** |
|
21 | + * @return void |
|
22 | + */ |
|
23 | + public function testConstructor() : void |
|
24 | + { |
|
25 | + $testRoute = new Fixture\TestRoute(); |
|
26 | + $requestHandler = new RoutableRequestHandler($testRoute); |
|
27 | 27 | |
28 | - $this->assertInstanceOf(RequestHandlerInterface::class, $requestHandler); |
|
29 | - } |
|
28 | + $this->assertInstanceOf(RequestHandlerInterface::class, $requestHandler); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * @return void |
|
33 | - */ |
|
34 | - public function testHandle() : void |
|
35 | - { |
|
36 | - $testRoute = new Fixture\TestRoute(); |
|
37 | - $requestHandler = new RoutableRequestHandler($testRoute); |
|
31 | + /** |
|
32 | + * @return void |
|
33 | + */ |
|
34 | + public function testHandle() : void |
|
35 | + { |
|
36 | + $testRoute = new Fixture\TestRoute(); |
|
37 | + $requestHandler = new RoutableRequestHandler($testRoute); |
|
38 | 38 | |
39 | - $request = (new ServerRequestFactory)->createServerRequest('GET', '/'); |
|
40 | - $requestHandler->handle($request); |
|
39 | + $request = (new ServerRequestFactory)->createServerRequest('GET', '/'); |
|
40 | + $requestHandler->handle($request); |
|
41 | 41 | |
42 | - $this->assertTrue($testRoute->getMiddlewares()[0]->isRunned()); |
|
43 | - $this->assertTrue($testRoute->getMiddlewares()[1]->isRunned()); |
|
44 | - $this->assertTrue($testRoute->getMiddlewares()[2]->isRunned()); |
|
45 | - $this->assertTrue($testRoute->getRequestHandler()->isRunned()); |
|
42 | + $this->assertTrue($testRoute->getMiddlewares()[0]->isRunned()); |
|
43 | + $this->assertTrue($testRoute->getMiddlewares()[1]->isRunned()); |
|
44 | + $this->assertTrue($testRoute->getMiddlewares()[2]->isRunned()); |
|
45 | + $this->assertTrue($testRoute->getRequestHandler()->isRunned()); |
|
46 | 46 | |
47 | - $expectedAttributes = [RoutableRequestHandler::ATTR_NAME_FOR_ROUTE_NAME => $testRoute->getName()]; |
|
48 | - $expectedAttributes += $testRoute->getAttributes(); |
|
47 | + $expectedAttributes = [RoutableRequestHandler::ATTR_NAME_FOR_ROUTE_NAME => $testRoute->getName()]; |
|
48 | + $expectedAttributes += $testRoute->getAttributes(); |
|
49 | 49 | |
50 | - $this->assertSame($expectedAttributes, $testRoute->getRequestHandler()->getAttributes()); |
|
51 | - } |
|
50 | + $this->assertSame($expectedAttributes, $testRoute->getRequestHandler()->getAttributes()); |
|
51 | + } |
|
52 | 52 | |
53 | - /** |
|
54 | - * @return void |
|
55 | - */ |
|
56 | - public function testHandleWithBrokenMiddleware() : void |
|
57 | - { |
|
58 | - $testRoute = new Fixture\TestRoute(Fixture\TestRoute::WITH_BROKEN_MIDDLEWARE); |
|
59 | - $requestHandler = new RoutableRequestHandler($testRoute); |
|
53 | + /** |
|
54 | + * @return void |
|
55 | + */ |
|
56 | + public function testHandleWithBrokenMiddleware() : void |
|
57 | + { |
|
58 | + $testRoute = new Fixture\TestRoute(Fixture\TestRoute::WITH_BROKEN_MIDDLEWARE); |
|
59 | + $requestHandler = new RoutableRequestHandler($testRoute); |
|
60 | 60 | |
61 | - $request = (new ServerRequestFactory)->createServerRequest('GET', '/'); |
|
62 | - $requestHandler->handle($request); |
|
61 | + $request = (new ServerRequestFactory)->createServerRequest('GET', '/'); |
|
62 | + $requestHandler->handle($request); |
|
63 | 63 | |
64 | - $this->assertTrue($testRoute->getMiddlewares()[0]->isRunned()); |
|
65 | - $this->assertTrue($testRoute->getMiddlewares()[1]->isRunned()); |
|
66 | - $this->assertFalse($testRoute->getMiddlewares()[2]->isRunned()); |
|
67 | - $this->assertFalse($testRoute->getRequestHandler()->isRunned()); |
|
68 | - $this->assertSame([], $testRoute->getRequestHandler()->getAttributes()); |
|
69 | - } |
|
64 | + $this->assertTrue($testRoute->getMiddlewares()[0]->isRunned()); |
|
65 | + $this->assertTrue($testRoute->getMiddlewares()[1]->isRunned()); |
|
66 | + $this->assertFalse($testRoute->getMiddlewares()[2]->isRunned()); |
|
67 | + $this->assertFalse($testRoute->getRequestHandler()->isRunned()); |
|
68 | + $this->assertSame([], $testRoute->getRequestHandler()->getAttributes()); |
|
69 | + } |
|
70 | 70 | } |
@@ -21,331 +21,331 @@ |
||
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 | } |
@@ -16,14 +16,14 @@ |
||
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 | } |
@@ -16,24 +16,24 @@ |
||
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 | } |