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; |
||
3 | |||
4 | use PHPUnitProviderAutoloader; |
||
5 | use Redaxscript\Config; |
||
6 | use Redaxscript\Db; |
||
7 | use Redaxscript\Installer; |
||
8 | use Redaxscript\Language; |
||
9 | use Redaxscript\Model; |
||
10 | use Redaxscript\Modules\TestDummy; |
||
11 | use Redaxscript\Registry; |
||
12 | use Redaxscript\Request; |
||
13 | use ReflectionClass; |
||
14 | use function chr; |
||
15 | use function file_exists; |
||
16 | use function file_get_contents; |
||
17 | use function function_exists; |
||
18 | use function getenv; |
||
19 | use function json_decode; |
||
20 | use function str_replace; |
||
21 | use function xdebug_get_headers; |
||
22 | |||
23 | /** |
||
24 | * TestCaseAbstract |
||
25 | * |
||
26 | * @since 2.2.0 |
||
27 | * |
||
28 | * @package Redaxscript |
||
29 | * @category Tests |
||
30 | * @author Henry Ruhs |
||
31 | */ |
||
32 | |||
33 | abstract class TestCaseAbstract extends PHPUnitProviderAutoloader\TestCaseAbstract |
||
34 | { |
||
35 | /** |
||
36 | * instance of the registry class |
||
37 | * |
||
38 | * @var Registry |
||
39 | */ |
||
40 | |||
41 | protected $_registry; |
||
42 | |||
43 | /** |
||
44 | * instance of the request class |
||
45 | * |
||
46 | * @var Request |
||
47 | */ |
||
48 | |||
49 | protected $_request; |
||
50 | |||
51 | /** |
||
52 | * instance of the language class |
||
53 | * |
||
54 | * @var Language |
||
55 | */ |
||
56 | |||
57 | protected $_language; |
||
58 | |||
59 | /** |
||
60 | * instance of the config class |
||
61 | * |
||
62 | * @var Config |
||
63 | */ |
||
64 | |||
65 | protected $_config; |
||
66 | |||
67 | /** |
||
68 | * namespace of the testing suite |
||
69 | * |
||
70 | * @var string |
||
71 | */ |
||
72 | |||
73 | protected $_testNamespace = __NAMESPACE__; |
||
74 | |||
75 | /** |
||
76 | * setUp |
||
77 | * |
||
78 | * @since 3.1.0 |
||
79 | */ |
||
80 | |||
81 | public function setUp() |
||
82 | { |
||
83 | Db::clearCache(); |
||
84 | $this->_registry = Registry::getInstance(); |
||
85 | $this->_request = Request::getInstance(); |
||
86 | $this->_language = Language::getInstance(); |
||
87 | $this->_config = Config::getInstance(); |
||
88 | } |
||
89 | |||
90 | /** |
||
91 | * installerFactory |
||
92 | * |
||
93 | * @since 3.1.0 |
||
94 | * |
||
95 | * @return Installer |
||
96 | */ |
||
97 | |||
98 | public function installerFactory() : Installer |
||
99 | { |
||
100 | return new Installer($this->_registry, $this->_request, $this->_language, $this->_config); |
||
101 | } |
||
102 | |||
103 | /** |
||
104 | * settingFactory |
||
105 | * |
||
106 | * @since 3.3.0 |
||
107 | * |
||
108 | * @return Model\Setting |
||
109 | */ |
||
110 | |||
111 | public function settingFactory() : Model\Setting |
||
112 | { |
||
113 | return new Model\Setting(); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * createDatabase |
||
118 | * |
||
119 | * @since 4.0.0 |
||
120 | */ |
||
121 | |||
122 | public function createDatabase() |
||
123 | { |
||
124 | $installer = $this->installerFactory(); |
||
125 | $installer->init(); |
||
126 | $installer->rawCreate(); |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * dropDatabase |
||
131 | * |
||
132 | * @since 4.0.0 |
||
133 | */ |
||
134 | |||
135 | public function dropDatabase() |
||
136 | { |
||
137 | $installer = $this->installerFactory(); |
||
138 | $installer->init(); |
||
139 | $installer->rawDrop(); |
||
140 | } |
||
141 | |||
142 | /** |
||
143 | * installTestDummy |
||
144 | * |
||
145 | * @since 4.0.0 |
||
146 | */ |
||
147 | |||
148 | public function installTestDummy() |
||
149 | { |
||
150 | $testDummy = new TestDummy\TestDummy($this->_registry, $this->_request, $this->_language, $this->_config); |
||
151 | $testDummy->install(); |
||
152 | } |
||
153 | |||
154 | /** |
||
155 | * uninstallTestDummy |
||
156 | * |
||
157 | * @since 4.0.0 |
||
158 | */ |
||
159 | |||
160 | public function uninstallTestDummy() |
||
161 | { |
||
162 | $testDummy = new TestDummy\TestDummy($this->_registry, $this->_request, $this->_language, $this->_config); |
||
163 | $testDummy->clearNotification('success'); |
||
164 | $testDummy->clearNotification('warning'); |
||
165 | $testDummy->clearNotification('error'); |
||
166 | $testDummy->clearNotification('info'); |
||
167 | $testDummy->uninstall(); |
||
168 | } |
||
169 | |||
170 | /** |
||
171 | * getJSON |
||
172 | * |
||
173 | * @since 4.0.0 |
||
174 | * |
||
175 | * @param string $file |
||
176 | * |
||
177 | * @return array|null |
||
178 | */ |
||
179 | |||
180 | public function getJSON(string $file = null) : ?array |
||
181 | { |
||
182 | if (file_exists($file)) |
||
183 | { |
||
184 | $content = file_get_contents($file); |
||
185 | return json_decode($content, true); |
||
186 | } |
||
187 | } |
||
188 | |||
189 | /** |
||
190 | * getProperty |
||
191 | * |
||
192 | * @since 3.0.0 |
||
193 | * |
||
194 | * @param object $object |
||
195 | * @param string $property |
||
196 | * |
||
197 | * @return array|object |
||
198 | */ |
||
199 | |||
200 | public function getProperty(object $object = null, string $property = null) |
||
201 | { |
||
202 | $reflection = new ReflectionClass($object); |
||
203 | $reflectionProperty = $reflection->getProperty($property); |
||
204 | $reflectionProperty->setAccessible(true); |
||
205 | return $reflectionProperty->getValue($object); |
||
206 | } |
||
207 | |||
208 | /** |
||
209 | * callMethod |
||
210 | * |
||
211 | * @since 3.0.0 |
||
212 | * |
||
213 | * @param object $object |
||
214 | * @param string $method |
||
215 | * @param array $argumentArray |
||
216 | * |
||
217 | * @return array|object |
||
218 | */ |
||
219 | |||
220 | public function callMethod(object $object = null, string $method = null, array $argumentArray = []) |
||
221 | { |
||
222 | $reflection = new ReflectionClass($object); |
||
223 | $reflectionMethod = $reflection->getMethod($method); |
||
224 | $reflectionMethod->setAccessible(true); |
||
225 | return $reflectionMethod->invokeArgs($object, $argumentArray); |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * assertString |
||
230 | * |
||
231 | * @since 3.0.0 |
||
232 | * |
||
233 | * @param string|null $actual |
||
234 | */ |
||
235 | |||
236 | public function assertString(?string $actual = null) |
||
237 | { |
||
238 | $this->assertInternalType('string', $actual); |
||
0 ignored issues
–
show
|
|||
239 | } |
||
240 | |||
241 | /** |
||
242 | * assertNumber |
||
243 | * |
||
244 | * @since 3.1.0 |
||
245 | * |
||
246 | * @param int|null $actual |
||
247 | */ |
||
248 | |||
249 | public function assertNumber(?int $actual = null) |
||
250 | { |
||
251 | $this->assertInternalType('integer', $actual); |
||
0 ignored issues
–
show
The method
PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369
This method has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.
Loading history...
|
|||
252 | } |
||
253 | |||
254 | /** |
||
255 | * assertObject |
||
256 | * |
||
257 | * @since 3.1.0 |
||
258 | * |
||
259 | * @param object|null $actual |
||
260 | */ |
||
261 | |||
262 | public function assertObject(?object $actual = null) |
||
263 | { |
||
264 | $this->assertInternalType('object', $actual); |
||
0 ignored issues
–
show
The method
PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369
This method has been deprecated. The supplier of the class has supplied an explanatory message. The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.
Loading history...
|
|||
265 | } |
||
266 | |||
267 | /** |
||
268 | * normalizeSeparator |
||
269 | * |
||
270 | * @since 3.2.0 |
||
271 | * |
||
272 | * @param string $actual |
||
273 | * |
||
274 | * @return string |
||
275 | */ |
||
276 | |||
277 | public function normalizeSeparator(string $actual = null) : string |
||
278 | { |
||
279 | return str_replace(DIRECTORY_SEPARATOR, chr(47), $actual); |
||
280 | } |
||
281 | |||
282 | /** |
||
283 | * normalizeNewline |
||
284 | * |
||
285 | * @since 3.0.0 |
||
286 | * |
||
287 | * @param string $actual |
||
288 | * |
||
289 | * @return string |
||
290 | */ |
||
291 | |||
292 | public function normalizeNewline(string $actual = null) : string |
||
293 | { |
||
294 | return str_replace(PHP_EOL, chr(10), $actual); |
||
295 | } |
||
296 | |||
297 | /** |
||
298 | * getHeaderArray |
||
299 | * |
||
300 | * @since 3.0.0 |
||
301 | * |
||
302 | * @return array|null |
||
303 | */ |
||
304 | |||
305 | public function getHeaderArray() : ?array |
||
306 | { |
||
307 | if (function_exists('xdebug_get_headers')) |
||
308 | { |
||
309 | return xdebug_get_headers(); |
||
310 | } |
||
311 | $this->markTestSkipped(); |
||
312 | return null; |
||
313 | } |
||
314 | |||
315 | /** |
||
316 | * skipOnEnv |
||
317 | * |
||
318 | * @since 4.0.0 |
||
319 | * |
||
320 | * @param string|null $env |
||
321 | */ |
||
322 | |||
323 | public function skipOnEnv(string $env = null) |
||
324 | { |
||
325 | if (getenv($env)) |
||
326 | { |
||
327 | $this->markTestSkipped(); |
||
328 | } |
||
329 | } |
||
330 | } |
||
331 |
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.