Skip to content

Commit

Permalink
Merge pull request #143 from Yoast/feature/update-for-changed-message…
Browse files Browse the repository at this point in the history
…-format

Tests: account for changes failure message format
  • Loading branch information
jrfnl committed Nov 20, 2023
2 parents 3ae58af + ac2b6bf commit a8ef9ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
11 changes: 6 additions & 5 deletions tests/Polyfills/AssertIgnoringLineEndingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand Down
12 changes: 6 additions & 6 deletions tests/Polyfills/AssertStringContainsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
Expand All @@ -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' );
}
Expand All @@ -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 );
Expand All @@ -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 );
Expand Down

0 comments on commit a8ef9ea

Please sign in to comment.