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 | use function putenv; |
||
7 | |||
8 | /** |
||
9 | * CommonTest |
||
10 | * |
||
11 | * @since 3.1.0 |
||
12 | * |
||
13 | * @package Redaxscript |
||
14 | * @category Tests |
||
15 | * @author Henry Ruhs |
||
16 | * |
||
17 | * @covers Redaxscript\Bootstrap\Common |
||
18 | * @covers Redaxscript\Bootstrap\BootstrapAbstract |
||
19 | * |
||
20 | * @runTestsInSeparateProcesses |
||
21 | */ |
||
22 | |||
23 | class CommonTest extends TestCaseAbstract |
||
24 | { |
||
25 | /** |
||
26 | * testServer |
||
27 | * |
||
28 | * @since 3.2.3 |
||
29 | * |
||
30 | * @param string $userAgent |
||
31 | * @param array $expectArray |
||
32 | * |
||
33 | * @dataProvider providerAutoloader |
||
34 | */ |
||
35 | |||
36 | public function testServer(string $userAgent = null, array $expectArray = []) |
||
37 | { |
||
38 | /* setup */ |
||
39 | |||
40 | $this->_request->set('server', |
||
41 | [ |
||
42 | 'HTTP_HOST' => 'localhost', |
||
43 | 'HTTP_USER_AGENT' => $userAgent, |
||
44 | 'REMOTE_ADDR' => 'localhost', |
||
45 | 'SCRIPT_NAME' => '/redaxscript/index.php' |
||
46 | ]); |
||
47 | new Bootstrap\Common($this->_registry, $this->_request); |
||
48 | |||
49 | /* actual */ |
||
50 | |||
51 | $actualArray = |
||
52 | [ |
||
53 | 'file' => $this->_registry->get('file'), |
||
54 | 'root' => $this->_registry->get('root'), |
||
55 | 'host' => $this->_registry->get('host'), |
||
56 | 'token' => $this->_registry->get('token') |
||
57 | ]; |
||
58 | |||
59 | /* compare */ |
||
60 | |||
61 | $this->assertEquals($expectArray, $actualArray); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * testClient |
||
66 | * |
||
67 | * @since 3.2.3 |
||
68 | * |
||
69 | * @param string $userAgent |
||
70 | * @param array $expectArray |
||
71 | * |
||
72 | * @dataProvider providerAutoloader |
||
73 | */ |
||
74 | |||
75 | public function testClient(string $userAgent = null, array $expectArray = []) |
||
76 | { |
||
77 | /* setup */ |
||
78 | |||
79 | $this->_request->setServer('HTTP_USER_AGENT', $userAgent); |
||
80 | new Bootstrap\Common($this->_registry, $this->_request); |
||
81 | |||
82 | /* actual */ |
||
83 | |||
84 | $actualArray = |
||
85 | [ |
||
86 | 'myBrowser' => $this->_registry->get('myBrowser'), |
||
87 | 'myBrowserVersion' => $this->_registry->get('myBrowserVersion'), |
||
88 | 'myEngine' => $this->_registry->get('myEngine'), |
||
89 | 'myMobile' => $this->_registry->get('myMobile'), |
||
90 | 'myTablet' => $this->_registry->get('myTablet'), |
||
91 | 'myDesktop' => $this->_registry->get('myDesktop') |
||
92 | ]; |
||
93 | |||
94 | /* compare */ |
||
95 | |||
96 | $this->assertEquals($expectArray, $actualArray); |
||
97 | } |
||
98 | |||
99 | /** |
||
100 | * testDriver |
||
101 | * |
||
102 | * @since 3.2.3 |
||
103 | */ |
||
104 | |||
105 | public function testDriver() |
||
106 | { |
||
107 | /* setup */ |
||
108 | |||
109 | new Bootstrap\Common($this->_registry, $this->_request); |
||
110 | |||
111 | /* actual */ |
||
112 | |||
113 | $actualArray = $this->_registry->get('driverArray'); |
||
114 | |||
115 | /* compare */ |
||
116 | |||
117 | $this->assertNotNull($actualArray); |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * testModule |
||
122 | * |
||
123 | * @since 3.2.3 |
||
124 | */ |
||
125 | |||
126 | public function testModule() |
||
127 | { |
||
128 | /* setup */ |
||
129 | |||
130 | putenv('REDIRECT_mod_deflate=on'); |
||
131 | putenv('REDIRECT_mod_headers=on'); |
||
132 | putenv('REDIRECT_mod_rewrite=on'); |
||
133 | new Bootstrap\Common($this->_registry, $this->_request); |
||
134 | |||
135 | /* expect and actual */ |
||
136 | |||
137 | $expectArray = |
||
138 | [ |
||
139 | 'mod_deflate' => true, |
||
140 | 'mod_headers' => true, |
||
141 | 'mod_rewrite' => true |
||
142 | ]; |
||
143 | $actualArray = $this->_registry->get('moduleArray'); |
||
144 | |||
145 | /* compare */ |
||
146 | |||
147 | $this->assertEquals($expectArray, $actualArray); |
||
148 | } |
||
149 | |||
150 | /** |
||
151 | * testPhp |
||
152 | * |
||
153 | * @since 3.2.3 |
||
154 | */ |
||
155 | |||
156 | public function testPhp() |
||
157 | { |
||
158 | /* setup */ |
||
159 | |||
160 | new Bootstrap\Common($this->_registry, $this->_request); |
||
161 | |||
162 | /* actual */ |
||
163 | |||
164 | $actualArray = |
||
165 | [ |
||
166 | 'phpOs' => $this->_registry->get('phpOs'), |
||
167 | 'phpVersion' => $this->_registry->get('phpVersion'), |
||
168 | 'phpStatus' => $this->_registry->get('phpStatus') |
||
169 | ]; |
||
170 | |||
171 | /* compare */ |
||
172 | |||
173 | $this->assertString($actualArray['phpOs']); |
||
0 ignored issues
–
show
|
|||
174 | $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...
|
|||
175 | $this->assertTrue($actualArray['phpStatus']); |
||
176 | } |
||
177 | } |
||
178 |
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.