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\Head; |
||
3 | |||
4 | use org\bovigo\vfs\vfsStream as Stream; |
||
5 | use Redaxscript\Head; |
||
6 | use Redaxscript\Tests\TestCaseAbstract; |
||
7 | |||
8 | /** |
||
9 | * LinkTest |
||
10 | * |
||
11 | * @since 3.0.0 |
||
12 | * |
||
13 | * @package Redaxscript |
||
14 | * @category Tests |
||
15 | * @author Henry Ruhs |
||
16 | * @author Balázs Szilágyi |
||
17 | * |
||
18 | * @covers Redaxscript\Head\HeadAbstract |
||
19 | * @covers Redaxscript\Head\Link |
||
20 | */ |
||
21 | |||
22 | class LinkTest extends TestCaseAbstract |
||
23 | { |
||
24 | /** |
||
25 | * setUp |
||
26 | * |
||
27 | * @since 3.0.0 |
||
28 | */ |
||
29 | |||
30 | public function setUp() |
||
31 | { |
||
32 | Stream::setup('root', 0777, $this->getJSON('tests' . DIRECTORY_SEPARATOR. 'provider' . DIRECTORY_SEPARATOR. 'Head' . DIRECTORY_SEPARATOR. 'LinkTest_setUp.json')); |
||
0 ignored issues
–
show
|
|||
33 | } |
||
34 | |||
35 | /** |
||
36 | * testAppend |
||
37 | * |
||
38 | * @since 3.0.0 |
||
39 | * |
||
40 | * @param array $coreArray |
||
41 | * @param array $moduleArray |
||
42 | * @param string $expect |
||
43 | * |
||
44 | * @dataProvider providerAutoloader |
||
45 | */ |
||
46 | |||
47 | public function testAppend(array $coreArray = [], array $moduleArray = [], string $expect = null) |
||
48 | { |
||
49 | /* setup */ |
||
50 | |||
51 | $link = Head\Link::getInstance(); |
||
52 | $link->init('append'); |
||
53 | |||
54 | /* process core */ |
||
55 | |||
56 | foreach ($coreArray as $key => $value) |
||
57 | { |
||
58 | $link->append($value); |
||
59 | } |
||
60 | |||
61 | /* process module */ |
||
62 | |||
63 | foreach ($moduleArray as $key => $value) |
||
64 | { |
||
65 | $link->appendFile($value); |
||
66 | } |
||
67 | |||
68 | /* actual */ |
||
69 | |||
70 | $actual = $link; |
||
71 | |||
72 | /* compare */ |
||
73 | |||
74 | $this->assertEquals($expect, $this->normalizeNewline($actual)); |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * testPrepend |
||
79 | * |
||
80 | * @since 3.0.0 |
||
81 | * |
||
82 | * @param array $coreArray |
||
83 | * @param array $moduleArray |
||
84 | * @param string $expect |
||
85 | * |
||
86 | * @dataProvider providerAutoloader |
||
87 | */ |
||
88 | |||
89 | public function testPrepend(array $coreArray = [], array $moduleArray = [], string $expect = null) |
||
90 | { |
||
91 | /* setup */ |
||
92 | |||
93 | $link = Head\Link::getInstance(); |
||
94 | $link->init('prepend'); |
||
95 | |||
96 | /* process core */ |
||
97 | |||
98 | foreach ($coreArray as $value) |
||
99 | { |
||
100 | $link->prepend($value); |
||
101 | } |
||
102 | |||
103 | /* process module */ |
||
104 | |||
105 | foreach ($moduleArray as $key => $value) |
||
106 | { |
||
107 | $link->prependFile($value); |
||
108 | } |
||
109 | |||
110 | /* actual */ |
||
111 | |||
112 | $actual = $link; |
||
113 | |||
114 | /* compare */ |
||
115 | |||
116 | $this->assertEquals($expect, $this->normalizeNewline($actual)); |
||
117 | } |
||
118 | |||
119 | /** |
||
120 | * testRemove |
||
121 | * |
||
122 | * @since 3.0.0 |
||
123 | * |
||
124 | * @param array $coreArray |
||
125 | * @param string $deleteFile |
||
126 | * @param string $expect |
||
127 | * |
||
128 | * @dataProvider providerAutoloader |
||
129 | */ |
||
130 | |||
131 | public function testRemove(array $coreArray = [], string $deleteFile = null, string $expect = null) |
||
132 | { |
||
133 | /* setup */ |
||
134 | |||
135 | $link = Head\Link::getInstance(); |
||
136 | $link->init('remove'); |
||
137 | |||
138 | /* process core */ |
||
139 | |||
140 | foreach ($coreArray as $key => $value) |
||
141 | { |
||
142 | $link->append($value); |
||
143 | } |
||
144 | $link->removeFile($deleteFile); |
||
145 | |||
146 | /* actual */ |
||
147 | |||
148 | $actual = $link; |
||
149 | |||
150 | /* compare */ |
||
151 | |||
152 | $this->assertEquals($expect, $this->normalizeNewline($actual)); |
||
153 | } |
||
154 | |||
155 | /** |
||
156 | * testConcat |
||
157 | * |
||
158 | * @since 3.0.0 |
||
159 | * |
||
160 | * @param array $concatArray |
||
161 | * @param string $expect |
||
162 | * |
||
163 | * @dataProvider providerAutoloader |
||
164 | */ |
||
165 | |||
166 | public function testConcat(array $concatArray = [], string $expect = null) |
||
167 | { |
||
168 | /* setup */ |
||
169 | |||
170 | $optionArray = |
||
171 | [ |
||
172 | 'directory' => Stream::url('root' . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR . 'styles') |
||
173 | ]; |
||
174 | $link = Head\Link::getInstance(); |
||
175 | $link->init('concat'); |
||
176 | |||
177 | /* process concat */ |
||
178 | |||
179 | foreach ($concatArray as $key => $value) |
||
180 | { |
||
181 | $link->append($value); |
||
182 | } |
||
183 | $link |
||
184 | ->concat($optionArray) |
||
185 | ->concat($optionArray); |
||
186 | |||
187 | /* actual */ |
||
188 | |||
189 | $actual = $link; |
||
190 | |||
191 | /* compare */ |
||
192 | |||
193 | $this->assertEquals($expect, $this->normalizeNewline($actual)); |
||
194 | } |
||
195 | |||
196 | /** |
||
197 | * testRewrite |
||
198 | * |
||
199 | * @since 3.0.0 |
||
200 | */ |
||
201 | |||
202 | public function testRewrite() |
||
203 | { |
||
204 | /* setup */ |
||
205 | |||
206 | $link = Head\Link::getInstance(); |
||
207 | $link |
||
208 | ->init('rewrite') |
||
209 | ->rewrite( |
||
210 | [ |
||
211 | 'rewrite-one' => 'rewrite-one', |
||
212 | 'rewrite-two' => 'rewrite-two' |
||
213 | ]) |
||
214 | ->rewrite( |
||
215 | [ |
||
216 | 'rewrite-three' => 'rewrite-three' |
||
217 | ]); |
||
218 | |||
219 | /* expect and actual */ |
||
220 | |||
221 | $expectArray = |
||
222 | [ |
||
223 | 'rewrite-one' => 'rewrite-one', |
||
224 | 'rewrite-two' => 'rewrite-two', |
||
225 | 'rewrite-three' => 'rewrite-three' |
||
226 | ]; |
||
227 | $actualArray = $this->getProperty($link, '_rewriteArray')['Redaxscript\Head\Link\Rewrite']; |
||
0 ignored issues
–
show
$link is of type object<Redaxscript\Head\Link> , but the function expects a null|object<Redaxscript\Tests\object> .
It seems like the type of the argument is not accepted by the function/method which you are calling. In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug. We suggest to add an explicit type cast like in the following example: function acceptsInteger($int) { }
$x = '123'; // string "123"
// Instead of
acceptsInteger($x);
// we recommend to use
acceptsInteger((integer) $x);
Loading history...
|
|||
228 | |||
229 | /* compare */ |
||
230 | |||
231 | $this->assertEquals($expectArray, $actualArray); |
||
232 | } |
||
233 | |||
234 | /** |
||
235 | * testInvalid |
||
236 | * |
||
237 | * @since 3.0.0 |
||
238 | */ |
||
239 | |||
240 | public function testInvalid() |
||
241 | { |
||
242 | /* setup */ |
||
243 | |||
244 | $link = Head\Link::getInstance(); |
||
245 | $link->init('invalid'); |
||
246 | |||
247 | /* actual */ |
||
248 | |||
249 | $actual = $link; |
||
250 | |||
251 | /* compare */ |
||
252 | |||
253 | $this->assertEquals('<!-- Redaxscript\Head\Link\Invalid -->', $actual); |
||
254 | } |
||
255 | } |
||
256 |
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.