From ac2b6bff2e56ffa4ba2be77c74cafb531f983fdd Mon Sep 17 00:00:00 2001 From: jrfnl Date: Mon, 20 Nov 2023 04:34:32 +0100 Subject: [PATCH] Tests: account for changes failure message format ... which was causing test failures. --- tests/Polyfills/AssertIgnoringLineEndingsTest.php | 11 ++++++----- tests/Polyfills/AssertStringContainsTest.php | 12 ++++++------ 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/tests/Polyfills/AssertIgnoringLineEndingsTest.php b/tests/Polyfills/AssertIgnoringLineEndingsTest.php index e73dde0..cb60ef4 100644 --- a/tests/Polyfills/AssertIgnoringLineEndingsTest.php +++ b/tests/Polyfills/AssertIgnoringLineEndingsTest.php @@ -317,14 +317,15 @@ public function testAssertStringContainsStringIgnoringLineEndingsBug5279( $needl */ public function testAssertStringContainsStringIgnoringLineEndingsFails( $needle, $haystack ) { $exporter = \class_exists( Exporter::class ) ? new Exporter() : new Exporter_In_Phar(); - $msg = \sprintf( - 'Failed asserting that %s contains "%s".', - $exporter->export( $haystack ), - self::normalizeLineEndings( $needle ) + $pattern = \sprintf( + '`^Failed asserting that %1$s%3$s contains "%2$s"%3$s\.`', + \preg_quote( $exporter->export( $haystack ), '`' ), + \preg_quote( self::normalizeLineEndings( $needle ), '`' ), + '( \[[^\]]+\]\(length: [0-9]+\))?' ); $this->expectException( $this->getAssertionFailedExceptionName() ); - $this->expectExceptionMessage( $msg ); + $this->expectExceptionMessageMatches( $pattern ); $this->assertStringContainsStringIgnoringLineEndings( $needle, $haystack ); } diff --git a/tests/Polyfills/AssertStringContainsTest.php b/tests/Polyfills/AssertStringContainsTest.php index ba89bc4..43f4dd4 100644 --- a/tests/Polyfills/AssertStringContainsTest.php +++ b/tests/Polyfills/AssertStringContainsTest.php @@ -104,10 +104,10 @@ public function testAssertStringContainsStringIgnoringCaseEmptyNeedle() { * @return void */ public function testAssertStringNotContainsStringEmptyNeedle( $haystack ) { - $msg = "Failed asserting that '{$haystack}' does not contain \"\"."; + $pattern = "`^Failed asserting that '{$haystack}'( \[[^\]]+\]\(length: [0-9]+\))? does not contain \"\"( \[[^\]]+\]\(length: [0-9]+\))?\.`"; $this->expectException( $this->getAssertionFailedExceptionName() ); - $this->expectExceptionMessage( $msg ); + $this->expectExceptionMessageMatches( $pattern ); self::assertStringNotContainsString( '', $haystack ); } @@ -124,10 +124,10 @@ public function testAssertStringNotContainsStringEmptyNeedle( $haystack ) { * @return void */ public function testAssertStringNotContainsStringIgnoringCaseEmptyNeedle() { - $msg = 'Failed asserting that \'text with whitespace\' does not contain "".'; + $pattern = '`^Failed asserting that \'text with whitespace\'( \[[^\]]+\]\(length: [0-9]+\))? does not contain ""( \[[^\]]+\]\(length: [0-9]+\))?.`'; $this->expectException( $this->getAssertionFailedExceptionName() ); - $this->expectExceptionMessage( $msg ); + $this->expectExceptionMessageMatches( $pattern ); $this->assertStringNotContainsStringIgnoringCase( '', 'text with whitespace' ); } @@ -154,7 +154,7 @@ public static function dataHaystacks() { * @return void */ public function testAssertStringNotContainsStringFailsWithCustomMessage() { - $pattern = '`^This assertion failed for reason XYZ\s+Failed asserting that \'.+?\' does not contain ""\.`s'; + $pattern = '`^This assertion failed for reason XYZ\s+Failed asserting that \'.+?\'( \[[^\]]+\]\(length: [0-9]+\))? does not contain ""( \[[^\]]+\]\(length: [0-9]+\))?\.`s'; $this->expectException( $this->getAssertionFailedExceptionName() ); $this->expectExceptionMessageMatches( $pattern ); @@ -169,7 +169,7 @@ public function testAssertStringNotContainsStringFailsWithCustomMessage() { * @return void */ public function testssertStringNotContainsStringIgnoringCaseFailsWithCustomMessage() { - $pattern = '`^This assertion failed for reason XYZ\s+Failed asserting that \'.+?\' does not contain ""\.`s'; + $pattern = '`^This assertion failed for reason XYZ\s+Failed asserting that \'.+?\'( \[[^\]]+\]\(length: [0-9]+\))? does not contain ""( \[[^\]]+\]\(length: [0-9]+\))?\.`s'; $this->expectException( $this->getAssertionFailedExceptionName() ); $this->expectExceptionMessageMatches( $pattern );