1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace Sunrise\Http\Router\Tests\Fixture; |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* Import classes |
7
|
|
|
*/ |
8
|
|
|
use Psr\Http\Server\MiddlewareInterface; |
9
|
|
|
use Psr\Http\Server\RequestHandlerInterface; |
10
|
|
|
use Sunrise\Http\Router\Route as BaseRoute; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Import functions |
14
|
|
|
*/ |
15
|
|
|
use function uniqid; |
16
|
|
|
use function strtoupper; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* TestRoute |
20
|
|
|
*/ |
21
|
|
|
class TestRoute extends BaseRoute |
22
|
|
|
{ |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var int |
26
|
|
|
*/ |
27
|
|
|
public const WITH_BROKEN_MIDDLEWARE = 1; |
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
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @return string |
48
|
|
|
*/ |
49
|
|
|
public static function getTestRouteName(int $flags = 0) : string |
50
|
|
|
{ |
51
|
|
|
return uniqid() . '.' . uniqid() . '.' . uniqid(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return string |
56
|
|
|
*/ |
57
|
|
|
public static function getTestRoutePath(int $flags = 0) : string |
58
|
|
|
{ |
59
|
|
|
return '/' . uniqid() . '/' . uniqid() . '/' . uniqid(); |
60
|
|
|
} |
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
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return RequestHandlerInterface |
76
|
|
|
*/ |
77
|
|
|
public static function getTestRouteRequestHandler(int $flags = 0) : RequestHandlerInterface |
78
|
|
|
{ |
79
|
|
|
return new BlankRequestHandler(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @return MiddlewareInterface[] |
84
|
|
|
*/ |
85
|
|
|
public static function getTestRouteMiddlewares(int $flags = 0) : array |
86
|
|
|
{ |
87
|
|
|
$middlewares = [new BlankMiddleware()]; |
88
|
|
|
|
89
|
|
|
if ($flags & self::WITH_BROKEN_MIDDLEWARE) { |
90
|
|
|
$middlewares[] = new BlankMiddleware(true); |
91
|
|
|
} else { |
92
|
|
|
$middlewares[] = new BlankMiddleware(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
$middlewares[] = new BlankMiddleware(); |
96
|
|
|
|
97
|
|
|
return $middlewares; |
98
|
|
|
} |
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
|
|
|
} |
111
|
|
|
} |
112
|
|
|
|