|
7 | 7 | use Psr\Http\Message\ServerRequestInterface; |
8 | 8 |
|
9 | 9 | \describe('Creating URI from server headers', function () { |
10 | | - \test('header', function (array $server, string $expectUri) { |
| 10 | + \test('header', function (array $srvArgs, string $expectUri) { |
11 | 11 | $exist = $_SERVER; |
12 | | - $_SERVER = $server; |
| 12 | + $_SERVER = $srvArgs; |
13 | 13 |
|
14 | 14 | $httpFactory = new HttpFactory(); |
15 | 15 | $sr = (new ServerRequestWizard( |
|
27 | 27 | }) |
28 | 28 | ->with([ |
29 | 29 | 'empty' => [ |
30 | | - 'server' => [], |
31 | | - 'expectUri' => '', |
| 30 | + [], |
| 31 | + '', |
32 | 32 | ], |
33 | 33 | 'with QUERY_STRING different REQUEST_URI' => [ |
34 | | - 'server' => [ |
| 34 | + [ |
35 | 35 | 'SERVER_NAME' => '127.0.0.1', |
36 | 36 | 'SERVER_PORT' => '8080', |
37 | 37 | 'REQUEST_URI' => '/index.php?list=ok', |
|
40 | 40 | 'QUERY_STRING' => 'sort=false', |
41 | 41 | 'HTTP_HOST' => 'hello.st:8080', |
42 | 42 | ], |
43 | | - 'expect' => 'http://hello.st:8080/index.php?list=ok', |
| 43 | + 'http://hello.st:8080/index.php?list=ok', |
44 | 44 | ], |
45 | 45 | 'has HTTP_X_FORWARDED_PROTO' => [ |
46 | | - 'server' => [ |
| 46 | + [ |
47 | 47 | 'HTTP_X_FORWARDED_PROTO' => 'https', |
48 | 48 | 'SERVER_NAME' => '127.0.0.1', |
49 | 49 | 'SERVER_PORT' => '8080', |
|
52 | 52 | 'PHP_SELF' => '/index.php', |
53 | 53 | 'QUERY_STRING' => 'list=ok', |
54 | 54 | ], |
55 | | - 'expect' => 'https://127.0.0.1:8080/', |
| 55 | + 'https://127.0.0.1:8080/', |
56 | 56 | ], |
57 | 57 | 'has HTTPS' => [ |
58 | | - 'server' => [ |
| 58 | + [ |
59 | 59 | 'SERVER_NAME' => '127.0.0.1', |
60 | 60 | 'SERVER_PORT' => '8080', |
61 | 61 | 'REQUEST_URI' => '/', |
|
64 | 64 | 'QUERY_STRING' => 'list=ok', |
65 | 65 | 'HTTPS' => 'on', |
66 | 66 | ], |
67 | | - 'expect' => 'https://127.0.0.1:8080/', |
| 67 | + 'https://127.0.0.1:8080/', |
68 | 68 | ], |
69 | 69 | 'has HTTPS off' => [ |
70 | | - 'server' => [ |
| 70 | + [ |
71 | 71 | 'SERVER_NAME' => '127.0.0.1', |
72 | 72 | 'SERVER_PORT' => '8080', |
73 | 73 | 'REQUEST_URI' => '/', |
|
76 | 76 | 'QUERY_STRING' => 'list=ok', |
77 | 77 | 'HTTPS' => '1', |
78 | 78 | ], |
79 | | - 'expect' => 'https://127.0.0.1:8080/', |
| 79 | + 'https://127.0.0.1:8080/', |
80 | 80 | ], |
81 | 81 | 'not has HTTP_HOST' => [ |
82 | | - 'server' => [ |
| 82 | + [ |
83 | 83 | 'SERVER_NAME' => '127.0.0.1', |
84 | 84 | 'SERVER_PORT' => '8080', |
85 | 85 | 'REQUEST_URI' => '/index.php?list=ok', |
86 | 86 | 'REQUEST_METHOD' => 'GET', |
87 | 87 | 'PHP_SELF' => '/index.php', |
88 | 88 | 'QUERY_STRING' => 'list=ok', |
89 | 89 | ], |
90 | | - 'expect' => 'http://127.0.0.1:8080/index.php?list=ok', |
| 90 | + 'http://127.0.0.1:8080/index.php?list=ok', |
91 | 91 | ], |
92 | 92 | 'without HTTP_HOST and SERVER_NAME' => [ |
93 | | - 'server' => [ |
| 93 | + [ |
94 | 94 | 'SERVER_PORT' => '8080', |
95 | 95 | 'REQUEST_URI' => '/index.php?list=ok', |
96 | 96 | 'REQUEST_METHOD' => 'GET', |
97 | 97 | 'PHP_SELF' => '/index.php', |
98 | 98 | 'QUERY_STRING' => 'list=ok', |
99 | 99 | ], |
100 | | - 'expect' => '', |
| 100 | + '', |
101 | 101 | ], |
102 | 102 | 'without HTTP_HOST header but has non standard port SERVER_PORT' => [ |
103 | | - 'server' => [ |
| 103 | + [ |
104 | 104 | 'SERVER_NAME' => '[::1]', |
105 | 105 | 'SERVER_PORT' => '8080', |
106 | 106 | 'REQUEST_URI' => '/index.php?list=ok', |
107 | 107 | 'REQUEST_METHOD' => 'GET', |
108 | 108 | 'PHP_SELF' => '/index.php', |
109 | 109 | 'QUERY_STRING' => 'list=ok', |
110 | 110 | ], |
111 | | - 'expect' => 'http://[::1]:8080/index.php?list=ok', |
| 111 | + 'http://[::1]:8080/index.php?list=ok', |
112 | 112 | ], |
113 | 113 | 'without REQUEST_URI' => [ |
114 | | - 'server' => [ |
| 114 | + [ |
115 | 115 | 'SERVER_NAME' => '127.0.0.1', |
116 | 116 | 'SERVER_PORT' => '8080', |
117 | 117 | 'REQUEST_METHOD' => 'GET', |
118 | 118 | 'ORIG_PATH_INFO' => '/index.php', |
119 | 119 | 'QUERY_STRING' => 'list=ok', |
120 | 120 | 'HTTP_HOST' => 'hello.st:8080', |
121 | 121 | ], |
122 | | - 'expect' => 'http://hello.st:8080/index.php?list=ok', |
| 122 | + 'http://hello.st:8080/index.php?list=ok', |
123 | 123 | ], |
124 | 124 | 'without REQUEST_URI and QUERY_STRING is "0"' => [ |
125 | | - 'server' => [ |
| 125 | + [ |
126 | 126 | 'SERVER_NAME' => '127.0.0.1', |
127 | 127 | 'SERVER_PORT' => '80', |
128 | 128 | 'REQUEST_METHOD' => 'GET', |
129 | 129 | 'ORIG_PATH_INFO' => '/index.php', |
130 | 130 | 'QUERY_STRING' => '0', |
131 | 131 | ], |
132 | | - 'expect' => 'http://127.0.0.1/index.php?0', |
| 132 | + 'http://127.0.0.1/index.php?0', |
133 | 133 | ], |
134 | 134 | 'without REQUEST_URI and ORIG_PATH_INFO but has QUERY_STRING' => [ |
135 | | - 'server' => [ |
| 135 | + [ |
136 | 136 | 'SERVER_NAME' => '127.0.0.1', |
137 | 137 | 'SERVER_PORT' => '80', |
138 | 138 | 'REQUEST_METHOD' => 'GET', |
139 | 139 | 'QUERY_STRING' => 'list=ok', |
140 | 140 | ], |
141 | | - 'expect' => 'http://127.0.0.1/?list=ok', |
| 141 | + 'http://127.0.0.1/?list=ok', |
142 | 142 | ], |
143 | 143 | ]) |
144 | 144 | ; |
|
0 commit comments