Skip to content

Commit

Permalink
Tests: account for changes failure message format
Browse files Browse the repository at this point in the history
... which was causing test failures.
  • Loading branch information
jrfnl committed Nov 20, 2023
1 parent 3ae58af commit 32fadf1
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 ) ),

Check warning on line 322 in tests/Polyfills/AssertIgnoringLineEndingsTest.php

View workflow job for this annotation

GitHub Actions / Basic CS and QA checks

Passing the $delimiter as the second parameter to preg_quote() is strongly recommended.

Check warning on line 322 in tests/Polyfills/AssertIgnoringLineEndingsTest.php

View workflow job for this annotation

GitHub Actions / Basic CS and QA checks

Passing the $delimiter as the second parameter to preg_quote() is strongly recommended.
\preg_quote( self::normalizeLineEndings( $needle ) ),

Check warning on line 323 in tests/Polyfills/AssertIgnoringLineEndingsTest.php

View workflow job for this annotation

GitHub Actions / Basic CS and QA checks

Passing the $delimiter as the second parameter to preg_quote() is strongly recommended.

Check warning on line 323 in tests/Polyfills/AssertIgnoringLineEndingsTest.php

View workflow job for this annotation

GitHub Actions / Basic CS and QA checks

Passing the $delimiter as the second parameter to preg_quote() is strongly recommended.
'( \[[^\]]+\]\(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 32fadf1

Please sign in to comment.