Tests: Ignore EOL differences in some tests using multiline string assertions.

Unix vs. Windows EOL style mismatches can cause misleading failures in tests using the heredoc syntax (`<<<`) or multiline strings as the expected result.

Follow-up to [48466], [50995], [51079].

See #52625.

git-svn-id: https://develop.svn.wordpress.org/trunk@51135 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Sergey Biryukov
2021-06-09 19:41:47 +00:00
parent b0eadda6e6
commit 81e84e12e8
3 changed files with 41 additions and 26 deletions
+18 -3
View File
@@ -660,12 +660,27 @@ abstract class WP_UnitTestCase_Base extends PHPUnit\Framework\TestCase {
* Asserts that two values have the same type and value, with EOL differences discarded.
*
* @since 5.6.0
* @since 5.8.0 Added support for nested arrays.
*
* @param string $expected The expected value.
* @param string $actual The actual value.
* @param string|array $expected The expected value.
* @param string|array $actual The actual value.
*/
public function assertSameIgnoreEOL( $expected, $actual ) {
$this->assertSame( str_replace( "\r\n", "\n", $expected ), str_replace( "\r\n", "\n", $actual ) );
$expected = map_deep(
$expected,
function ( $value ) {
return str_replace( "\r\n", "\n", $value );
}
);
$actual = map_deep(
$actual,
function ( $value ) {
return str_replace( "\r\n", "\n", $value );
}
);
$this->assertSame( $expected, $actual );
}
/**