These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | namespace Redaxscript\Tests\Bootstrap; |
||
3 | |||
4 | use Redaxscript\Bootstrap; |
||
5 | use Redaxscript\Tests\TestCaseAbstract; |
||
6 | |||
7 | /** |
||
8 | * CommonTest |
||
9 | * |
||
10 | * @since 3.1.0 |
||
11 | * |
||
12 | * @package Redaxscript |
||
13 | * @category Tests |
||
14 | * @author Henry Ruhs |
||
15 | * |
||
16 | * @covers Redaxscript\Bootstrap\Common |
||
17 | * @covers Redaxscript\Bootstrap\BootstrapAbstract |
||
18 | * |
||
19 | * @runTestsInSeparateProcesses |
||
20 | */ |
||
21 | |||
22 | class CommonTest extends TestCaseAbstract |
||
23 | { |
||
24 | /** |
||
25 | * testServer |
||
26 | * |
||
27 | * @since 3.2.3 |
||
28 | * |
||
29 | * @param string $userAgent |
||
30 | * @param array $expectArray |
||
31 | * |
||
32 | * @dataProvider providerAutoloader |
||
33 | */ |
||
34 | |||
35 | public function testServer(string $userAgent = null, array $expectArray = []) |
||
36 | { |
||
37 | /* setup */ |
||
38 | |||
39 | $this->_request->set('server', |
||
40 | [ |
||
41 | 'HTTP_HOST' => 'localhost', |
||
42 | 'HTTP_USER_AGENT' => $userAgent, |
||
43 | 'REMOTE_ADDR' => 'localhost', |
||
44 | 'SCRIPT_NAME' => '/redaxscript/index.php' |
||
45 | ]); |
||
46 | new Bootstrap\Common($this->_registry, $this->_request); |
||
47 | |||
48 | /* actual */ |
||
49 | |||
50 | $actualArray = |
||
51 | [ |
||
52 | 'file' => $this->_registry->get('file'), |
||
53 | 'root' => $this->_registry->get('root'), |
||
54 | 'host' => $this->_registry->get('host'), |
||
55 | 'token' => $this->_registry->get('token') |
||
56 | ]; |
||
57 | |||
58 | /* compare */ |
||
59 | |||
60 | $this->assertEquals($expectArray, $actualArray); |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * testClient |
||
65 | * |
||
66 | * @since 3.2.3 |
||
67 | * |
||
68 | * @param string $userAgent |
||
69 | * @param array $expectArray |
||
70 | * |
||
71 | * @dataProvider providerAutoloader |
||
72 | */ |
||
73 | |||
74 | public function testClient(string $userAgent = null, array $expectArray = []) |
||
75 | { |
||
76 | /* setup */ |
||
77 | |||
78 | $this->_request->setServer('HTTP_USER_AGENT', $userAgent); |
||
79 | new Bootstrap\Common($this->_registry, $this->_request); |
||
80 | |||
81 | /* actual */ |
||
82 | |||
83 | $actualArray = |
||
84 | [ |
||
85 | 'myBrowser' => $this->_registry->get('myBrowser'), |
||
86 | 'myBrowserVersion' => $this->_registry->get('myBrowserVersion'), |
||
87 | 'myEngine' => $this->_registry->get('myEngine'), |
||
88 | 'myMobile' => $this->_registry->get('myMobile'), |
||
89 | 'myTablet' => $this->_registry->get('myTablet'), |
||
90 | 'myDesktop' => $this->_registry->get('myDesktop') |
||
91 | ]; |
||
92 | |||
93 | /* compare */ |
||
94 | |||
95 | $this->assertEquals($expectArray, $actualArray); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * testDriver |
||
100 | * |
||
101 | * @since 3.2.3 |
||
102 | */ |
||
103 | |||
104 | public function testDriver() |
||
105 | { |
||
106 | /* setup */ |
||
107 | |||
108 | new Bootstrap\Common($this->_registry, $this->_request); |
||
109 | |||
110 | /* actual */ |
||
111 | |||
112 | $actualArray = $this->_registry->get('driverArray'); |
||
113 | |||
114 | /* compare */ |
||
115 | |||
116 | $this->assertNotNull($actualArray); |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * testModule |
||
121 | * |
||
122 | * @since 3.2.3 |
||
123 | */ |
||
124 | |||
125 | public function testModule() |
||
126 | { |
||
127 | /* setup */ |
||
128 | |||
129 | putenv('REDIRECT_mod_deflate=on'); |
||
130 | putenv('REDIRECT_mod_headers=on'); |
||
131 | putenv('REDIRECT_mod_rewrite=on'); |
||
132 | new Bootstrap\Common($this->_registry, $this->_request); |
||
133 | |||
134 | /* expect and actual */ |
||
135 | |||
136 | $expectArray = |
||
137 | [ |
||
138 | 'mod_deflate' => true, |
||
139 | 'mod_headers' => true, |
||
140 | 'mod_rewrite' => true |
||
141 | ]; |
||
142 | $actualArray = $this->_registry->get('moduleArray'); |
||
143 | |||
144 | /* compare */ |
||
145 | |||
146 | $this->assertEquals($expectArray, $actualArray); |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * testPhp |
||
151 | * |
||
152 | * @since 3.2.3 |
||
153 | */ |
||
154 | |||
155 | public function testPhp() |
||
156 | { |
||
157 | /* setup */ |
||
158 | |||
159 | new Bootstrap\Common($this->_registry, $this->_request); |
||
160 | |||
161 | /* actual */ |
||
162 | |||
163 | $actualArray = |
||
164 | [ |
||
165 | 'phpOs' => $this->_registry->get('phpOs'), |
||
166 | 'phpVersion' => $this->_registry->get('phpVersion'), |
||
167 | 'phpStatus' => $this->_registry->get('phpStatus') |
||
168 | ]; |
||
169 | |||
170 | /* compare */ |
||
171 | |||
172 | $this->assertString($actualArray['phpOs']); |
||
0 ignored issues
–
show
|
|||
173 | $this->assertString($actualArray['phpVersion']); |
||
0 ignored issues
–
show
It seems like
$actualArray['phpVersion'] can also be of type array ; however, Redaxscript\Tests\TestCaseAbstract::assertString() does only seem to accept string|null , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.
Loading history...
|
|||
174 | $this->assertTrue($actualArray['phpStatus']); |
||
175 | } |
||
176 | } |
||
177 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.