@@ -127,11 +127,7 @@ public function assertNotHasElementWithAttributes($attributes = [], $markup = ''
127
127
*/
128
128
public function assertElementContains ($ contents , $ selector = '' , $ markup = '' , $ message = '' )
129
129
{
130
- $ method = method_exists ($ this , 'assertStringContainsString ' )
131
- ? 'assertStringContainsString '
132
- : 'assertContains ' ; // @codeCoverageIgnore
133
-
134
- $ this ->$ method (
130
+ $ this ->assertStringContainsString (
135
131
$ contents ,
136
132
$ this ->getInnerHtmlOfMatchedElements ($ markup , $ selector ),
137
133
$ message
@@ -152,11 +148,7 @@ public function assertElementContains($contents, $selector = '', $markup = '', $
152
148
*/
153
149
public function assertElementNotContains ($ contents , $ selector = '' , $ markup = '' , $ message = '' )
154
150
{
155
- $ method = method_exists ($ this , 'assertStringNotContainsString ' )
156
- ? 'assertStringNotContainsString '
157
- : 'assertNotContains ' ; // @codeCoverageIgnore
158
-
159
- $ this ->$ method (
151
+ $ this ->assertStringNotContainsString (
160
152
$ contents ,
161
153
$ this ->getInnerHtmlOfMatchedElements ($ markup , $ selector ),
162
154
$ message
@@ -177,6 +169,7 @@ public function assertElementNotContains($contents, $selector = '', $markup = ''
177
169
*/
178
170
public function assertElementRegExp ($ regexp , $ selector = '' , $ markup = '' , $ message = '' )
179
171
{
172
+ // @phpstan-ignore function.alreadyNarrowedType (Introduced in PHPUnit 9.x, PHP 7.3+)
180
173
$ method = method_exists ($ this , 'assertMatchesRegularExpression ' )
181
174
? 'assertMatchesRegularExpression '
182
175
: 'assertRegExp ' ; // @codeCoverageIgnore
@@ -202,6 +195,7 @@ public function assertElementRegExp($regexp, $selector = '', $markup = '', $mess
202
195
*/
203
196
public function assertElementNotRegExp ($ regexp , $ selector = '' , $ markup = '' , $ message = '' )
204
197
{
198
+ // @phpstan-ignore function.alreadyNarrowedType (Introduced in PHPUnit 9.x, PHP 7.3+)
205
199
$ method = method_exists ($ this , 'assertDoesNotMatchRegularExpression ' )
206
200
? 'assertDoesNotMatchRegularExpression '
207
201
: 'assertNotRegExp ' ; // @codeCoverageIgnore
@@ -252,7 +246,7 @@ private function flattenAttributeArray(array $attributes)
252
246
if (empty ($ value )) {
253
247
$ value = sprintf ('[%s] ' , $ key );
254
248
} else {
255
- $ value = sprintf ('[%s="%s"] ' , $ key , htmlspecialchars ($ value ));
249
+ $ value = sprintf ('[%s="%s"] ' , $ key , htmlspecialchars (( string ) $ value ));
256
250
}
257
251
});
258
252
@@ -276,10 +270,14 @@ private function getInnerHtmlOfMatchedElements($markup, $query)
276
270
277
271
// Loop through results and collect their innerHTML values.
278
272
foreach ($ results as $ result ) {
273
+ if (!isset ($ result ->firstChild )) {
274
+ continue ;
275
+ }
276
+
279
277
$ document = new \DOMDocument ();
280
278
$ document ->appendChild ($ document ->importNode ($ result ->firstChild , true ));
281
279
282
- $ contents [] = trim (html_entity_decode ($ document ->saveHTML ()));
280
+ $ contents [] = trim (html_entity_decode (( string ) $ document ->saveHTML ()));
283
281
}
284
282
285
283
return implode (PHP_EOL , $ contents );
0 commit comments