Skip to content

Commit

Permalink
Show the fixture file on failing tests (#3577)
Browse files Browse the repository at this point in the history
  • Loading branch information
yguedidi authored Apr 8, 2023
1 parent 59cdfc8 commit 0005141
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/Testing/PHPUnit/AbstractRectorTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,16 @@ private function doTestFileMatchesExpectedContent(
return;
}

$fixtureFilename = basename($fixtureFilePath);
$failureMessage = sprintf('Failed on fixture file "%s"', $fixtureFilename);

try {
$this->assertSame($expectedFileContents, $changedContent);
$this->assertSame($expectedFileContents, $changedContent, $failureMessage);
} catch (ExpectationFailedException) {
FixtureFileUpdater::updateFixtureContent($originalFilePath, $changedContent, $fixtureFilePath);

// if not exact match, check the regex version (useful for generated hashes/uuids in the code)
$this->assertStringMatchesFormat($expectedFileContents, $changedContent);
$this->assertStringMatchesFormat($expectedFileContents, $changedContent, $failureMessage);
}
}

Expand Down

0 comments on commit 0005141

Please sign in to comment.