From 1cb7b94fc226b161287e802479b58a107837ce2c Mon Sep 17 00:00:00 2001 From: Jakob Buis Date: Sun, 26 Apr 2020 18:50:55 +0200 Subject: [PATCH 1/3] fix PHPUnit warning for using assert(Not)Contains on strings --- src/MarkupAssertionsTrait.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MarkupAssertionsTrait.php b/src/MarkupAssertionsTrait.php index 14767a7..6806b94 100644 --- a/src/MarkupAssertionsTrait.php +++ b/src/MarkupAssertionsTrait.php @@ -114,7 +114,7 @@ public function assertNotHasElementWithAttributes($attributes = [], $output = '' */ public function assertElementContains($contents, $selector = '', $output = '', $message = '') { - $this->assertContains( + $this->assertStringContainsString( $contents, $this->getInnerHtmlOfMatchedElements($output, $selector), $message @@ -133,7 +133,7 @@ public function assertElementContains($contents, $selector = '', $output = '', $ */ public function assertElementNotContains($contents, $selector = '', $output = '', $message = '') { - $this->assertNotContains( + $this->assertStringNotContainsString( $contents, $this->getInnerHtmlOfMatchedElements($output, $selector), $message From 1d6675c5fd2d559fbe71688b240bd230efd25fac Mon Sep 17 00:00:00 2001 From: Jakob Buis Date: Sun, 26 Apr 2020 19:05:20 +0200 Subject: [PATCH 2/3] preserve compatability with PHPUnit < 8.0 which do not support the assertString(Not)ContainsString assertion --- src/MarkupAssertionsTrait.php | 37 +++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/MarkupAssertionsTrait.php b/src/MarkupAssertionsTrait.php index 6806b94..2aa11d8 100644 --- a/src/MarkupAssertionsTrait.php +++ b/src/MarkupAssertionsTrait.php @@ -114,11 +114,19 @@ public function assertNotHasElementWithAttributes($attributes = [], $output = '' */ public function assertElementContains($contents, $selector = '', $output = '', $message = '') { - $this->assertStringContainsString( - $contents, - $this->getInnerHtmlOfMatchedElements($output, $selector), - $message - ); + if (method_exists($this, 'assertStringContainsString')) { + $this->assertStringContainsString( + $contents, + $this->getInnerHtmlOfMatchedElements($output, $selector), + $message + ); + } else { + $this->assertContains( + $contents, + $this->getInnerHtmlOfMatchedElements($output, $selector), + $message + ); + } } /** @@ -133,11 +141,20 @@ public function assertElementContains($contents, $selector = '', $output = '', $ */ public function assertElementNotContains($contents, $selector = '', $output = '', $message = '') { - $this->assertStringNotContainsString( - $contents, - $this->getInnerHtmlOfMatchedElements($output, $selector), - $message - ); + if (method_exists($this, 'assertStringContainsString')) { + $this->assertStringNotContainsString( + $contents, + $this->getInnerHtmlOfMatchedElements($output, $selector), + $message + ); + } + else { + $this->assertNotContains( + $contents, + $this->getInnerHtmlOfMatchedElements($output, $selector), + $message + ); + } } /** From 8655ff637be124a9876822d66eea320225f6cb97 Mon Sep 17 00:00:00 2001 From: Jakob Buis Date: Sun, 26 Apr 2020 19:13:09 +0200 Subject: [PATCH 3/3] use the right method in the method_exists check This technically worked, as the two methods were introduced in the same PHPUnit release, but this is more accurate. --- src/MarkupAssertionsTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MarkupAssertionsTrait.php b/src/MarkupAssertionsTrait.php index 2aa11d8..3cae94f 100644 --- a/src/MarkupAssertionsTrait.php +++ b/src/MarkupAssertionsTrait.php @@ -141,7 +141,7 @@ public function assertElementContains($contents, $selector = '', $output = '', $ */ public function assertElementNotContains($contents, $selector = '', $output = '', $message = '') { - if (method_exists($this, 'assertStringContainsString')) { + if (method_exists($this, 'assertStringNotContainsString')) { $this->assertStringNotContainsString( $contents, $this->getInnerHtmlOfMatchedElements($output, $selector),