@@ -127,11 +127,7 @@ public function assertNotHasElementWithAttributes($attributes = [], $markup = ''
127127 */
128128 public function assertElementContains ($ contents , $ selector = '' , $ markup = '' , $ message = '' )
129129 {
130- $ method = method_exists ($ this , 'assertStringContainsString ' )
131- ? 'assertStringContainsString '
132- : 'assertContains ' ; // @codeCoverageIgnore
133-
134- $ this ->$ method (
130+ $ this ->assertStringContainsString (
135131 $ contents ,
136132 $ this ->getInnerHtmlOfMatchedElements ($ markup , $ selector ),
137133 $ message
@@ -152,11 +148,7 @@ public function assertElementContains($contents, $selector = '', $markup = '', $
152148 */
153149 public function assertElementNotContains ($ contents , $ selector = '' , $ markup = '' , $ message = '' )
154150 {
155- $ method = method_exists ($ this , 'assertStringNotContainsString ' )
156- ? 'assertStringNotContainsString '
157- : 'assertNotContains ' ; // @codeCoverageIgnore
158-
159- $ this ->$ method (
151+ $ this ->assertStringNotContainsString (
160152 $ contents ,
161153 $ this ->getInnerHtmlOfMatchedElements ($ markup , $ selector ),
162154 $ message
@@ -177,6 +169,7 @@ public function assertElementNotContains($contents, $selector = '', $markup = ''
177169 */
178170 public function assertElementRegExp ($ regexp , $ selector = '' , $ markup = '' , $ message = '' )
179171 {
172+ // @phpstan-ignore function.alreadyNarrowedType (Introduced in PHPUnit 9.x, PHP 7.3+)
180173 $ method = method_exists ($ this , 'assertMatchesRegularExpression ' )
181174 ? 'assertMatchesRegularExpression '
182175 : 'assertRegExp ' ; // @codeCoverageIgnore
@@ -202,6 +195,7 @@ public function assertElementRegExp($regexp, $selector = '', $markup = '', $mess
202195 */
203196 public function assertElementNotRegExp ($ regexp , $ selector = '' , $ markup = '' , $ message = '' )
204197 {
198+ // @phpstan-ignore function.alreadyNarrowedType (Introduced in PHPUnit 9.x, PHP 7.3+)
205199 $ method = method_exists ($ this , 'assertDoesNotMatchRegularExpression ' )
206200 ? 'assertDoesNotMatchRegularExpression '
207201 : 'assertNotRegExp ' ; // @codeCoverageIgnore
@@ -252,7 +246,7 @@ private function flattenAttributeArray(array $attributes)
252246 if (empty ($ value )) {
253247 $ value = sprintf ('[%s] ' , $ key );
254248 } else {
255- $ value = sprintf ('[%s="%s"] ' , $ key , htmlspecialchars ($ value ));
249+ $ value = sprintf ('[%s="%s"] ' , $ key , htmlspecialchars (( string ) $ value ));
256250 }
257251 });
258252
@@ -276,10 +270,14 @@ private function getInnerHtmlOfMatchedElements($markup, $query)
276270
277271 // Loop through results and collect their innerHTML values.
278272 foreach ($ results as $ result ) {
273+ if (!isset ($ result ->firstChild )) {
274+ continue ;
275+ }
276+
279277 $ document = new \DOMDocument ();
280278 $ document ->appendChild ($ document ->importNode ($ result ->firstChild , true ));
281279
282- $ contents [] = trim (html_entity_decode ($ document ->saveHTML ()));
280+ $ contents [] = trim (html_entity_decode (( string ) $ document ->saveHTML ()));
283281 }
284282
285283 return implode (PHP_EOL , $ contents );
0 commit comments