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 | * directory of the provider |
||
69 | * |
||
70 | * @var string |
||
71 | */ |
||
72 | |||
73 | protected $_providerDirectory = 'tests' . DIRECTORY_SEPARATOR . 'unit-provider'; |
||
74 | |||
75 | /** |
||
76 | * namespace of the testing suite |
||
77 | * |
||
78 | * @var string |
||
79 | */ |
||
80 | |||
81 | protected $_testNamespace = __NAMESPACE__; |
||
82 | |||
83 | /** |
||
84 | * setUp |
||
85 | * |
||
86 | * @since 3.1.0 |
||
87 | */ |
||
88 | |||
89 | public function setUp() : void |
||
90 | { |
||
91 | Db::clearCache(); |
||
92 | $this->_registry = Registry::getInstance(); |
||
93 | $this->_request = Request::getInstance(); |
||
94 | $this->_language = Language::getInstance(); |
||
95 | $this->_config = Config::getInstance(); |
||
96 | } |
||
97 | |||
98 | /** |
||
99 | * installerFactory |
||
100 | * |
||
101 | * @since 3.1.0 |
||
102 | * |
||
103 | * @return Installer |
||
104 | */ |
||
105 | |||
106 | public function installerFactory() : Installer |
||
107 | { |
||
108 | return new Installer($this->_registry, $this->_request, $this->_language, $this->_config); |
||
109 | } |
||
110 | |||
111 | /** |
||
112 | * settingFactory |
||
113 | * |
||
114 | * @since 3.3.0 |
||
115 | * |
||
116 | * @return Model\Setting |
||
117 | */ |
||
118 | |||
119 | public function settingFactory() : Model\Setting |
||
120 | { |
||
121 | return new Model\Setting(); |
||
122 | } |
||
123 | |||
124 | /** |
||
125 | * createDatabase |
||
126 | * |
||
127 | * @since 4.0.0 |
||
128 | */ |
||
129 | |||
130 | public function createDatabase() : void |
||
131 | { |
||
132 | $installer = $this->installerFactory(); |
||
0 ignored issues
–
show
|
|||
133 | $installer->init(); |
||
134 | $installer->rawCreate(); |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * dropDatabase |
||
139 | * |
||
140 | * @since 4.0.0 |
||
141 | */ |
||
142 | |||
143 | public function dropDatabase() : void |
||
144 | { |
||
145 | $installer = $this->installerFactory(); |
||
0 ignored issues
–
show
The method
installerFactory() does not seem to exist on object<Redaxscript\Tests\TestCaseAbstract> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||
146 | $installer->init(); |
||
147 | $installer->rawDrop(); |
||
148 | } |
||
149 | /** |
||
150 | * getOptionArray |
||
151 | * |
||
152 | * @since 4.1.0 |
||
153 | */ |
||
154 | |||
155 | public function getOptionArray() : array |
||
156 | { |
||
157 | return |
||
158 | [ |
||
159 | 'adminName' => 'Test', |
||
160 | 'adminUser' => 'test', |
||
161 | 'adminPassword' => 'test', |
||
162 | 'adminEmail' => '[email protected]' |
||
163 | ]; |
||
164 | } |
||
165 | |||
166 | /** |
||
167 | * installTestDummy |
||
168 | * |
||
169 | * @since 4.0.0 |
||
170 | */ |
||
171 | |||
172 | public function installTestDummy() : void |
||
173 | { |
||
174 | $testDummy = new TestDummy\TestDummy($this->_registry, $this->_request, $this->_language, $this->_config); |
||
175 | $testDummy->install(); |
||
176 | } |
||
177 | |||
178 | /** |
||
179 | * uninstallTestDummy |
||
180 | * |
||
181 | * @since 4.0.0 |
||
182 | */ |
||
183 | |||
184 | public function uninstallTestDummy() : void |
||
185 | { |
||
186 | $testDummy = new TestDummy\TestDummy($this->_registry, $this->_request, $this->_language, $this->_config); |
||
187 | $testDummy->clearNotification('success'); |
||
188 | $testDummy->clearNotification('warning'); |
||
189 | $testDummy->clearNotification('error'); |
||
190 | $testDummy->clearNotification('info'); |
||
191 | $testDummy->uninstall(); |
||
192 | } |
||
193 | |||
194 | /** |
||
195 | * getJSON |
||
196 | * |
||
197 | * @since 4.0.0 |
||
198 | * |
||
199 | * @param string $file |
||
200 | * |
||
201 | * @return array|null |
||
202 | */ |
||
203 | |||
204 | public function getJSON(string $file = null) : ?array |
||
205 | { |
||
206 | if (file_exists($file)) |
||
207 | { |
||
208 | $content = file_get_contents($file); |
||
209 | return json_decode($content, true); |
||
210 | } |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * getProperty |
||
215 | * |
||
216 | * @since 3.0.0 |
||
217 | * |
||
218 | * @param object $object |
||
219 | * @param string $property |
||
220 | * |
||
221 | * @return array|object |
||
222 | */ |
||
223 | |||
224 | public function getProperty(object $object = null, string $property = null) |
||
225 | { |
||
226 | $reflection = new ReflectionClass($object); |
||
227 | $reflectionProperty = $reflection->getProperty($property); |
||
228 | $reflectionProperty->setAccessible(true); |
||
229 | return $reflectionProperty->getValue($object); |
||
230 | } |
||
231 | |||
232 | /** |
||
233 | * callMethod |
||
234 | * |
||
235 | * @since 3.0.0 |
||
236 | * |
||
237 | * @param object $object |
||
238 | * @param string $method |
||
239 | * @param array $argumentArray |
||
240 | * |
||
241 | * @return array|object |
||
242 | */ |
||
243 | |||
244 | public function callMethod(object $object = null, string $method = null, array $argumentArray = []) |
||
245 | { |
||
246 | $reflection = new ReflectionClass($object); |
||
247 | $reflectionMethod = $reflection->getMethod($method); |
||
248 | $reflectionMethod->setAccessible(true); |
||
249 | return $reflectionMethod->invokeArgs($object, $argumentArray); |
||
250 | } |
||
251 | |||
252 | /** |
||
253 | * normalizeSeparator |
||
254 | * |
||
255 | * @since 3.2.0 |
||
256 | * |
||
257 | * @param string $actual |
||
258 | * |
||
259 | * @return string |
||
260 | */ |
||
261 | |||
262 | public function normalizeSeparator(string $actual = null) : string |
||
263 | { |
||
264 | return str_replace(DIRECTORY_SEPARATOR, chr(47), $actual); |
||
265 | } |
||
266 | |||
267 | /** |
||
268 | * normalizeNewline |
||
269 | * |
||
270 | * @since 3.0.0 |
||
271 | * |
||
272 | * @param string $actual |
||
273 | * |
||
274 | * @return string |
||
275 | */ |
||
276 | |||
277 | public function normalizeNewline(string $actual = null) : string |
||
278 | { |
||
279 | return str_replace(PHP_EOL, chr(10), $actual); |
||
280 | } |
||
281 | |||
282 | /** |
||
283 | * getHeaderArray |
||
284 | * |
||
285 | * @since 3.0.0 |
||
286 | * |
||
287 | * @return array|null |
||
288 | */ |
||
289 | |||
290 | public function getHeaderArray() : ?array |
||
291 | { |
||
292 | if (function_exists('xdebug_get_headers')) |
||
293 | { |
||
294 | return xdebug_get_headers(); |
||
295 | } |
||
296 | $this->markTestSkipped(); |
||
297 | return null; |
||
298 | } |
||
299 | |||
300 | /** |
||
301 | * skipOnEnv |
||
302 | * |
||
303 | * @since 4.0.0 |
||
304 | * |
||
305 | * @param string|null $env |
||
306 | */ |
||
307 | |||
308 | public function skipOnEnv(string $env = null) : void |
||
309 | { |
||
310 | if (getenv($env)) |
||
311 | { |
||
312 | $this->markTestSkipped(); |
||
313 | } |
||
314 | } |
||
315 | } |
||
316 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.