export( $actual ), $expected ); if ( $message !== '' ) { $msg = $message . \PHP_EOL . $msg; } $actual = self::normalizeLineEndingsForIgnoringLineEndingsAssertions( (string) $actual ); static::assertSame( $expected, $actual, $msg ); } /** * Asserts that two variables are equal (ignoring case). * * @param string $needle The string to search for. * @param string $haystack The string to treat as the haystack. * @param string $message Optional failure message to display. * * @return void * * @throws TypeError When any of the passed arguments do not meet the required type. */ final public static function assertStringContainsStringIgnoringLineEndings( $needle, $haystack, $message = '' ) { /* * Parameter input validation. * In PHPUnit this is done via PHP native type declarations. Emulating this for the polyfill. * Note: using `is_scalar()` instead of `is_string()` as test files may not be using strict_types. */ if ( \is_scalar( $needle ) === false ) { throw new TypeError( \sprintf( 'Argument 1 passed to assertStringContainsStringIgnoringLineEndings() must be of type string, %s given', \gettype( $needle ) ) ); } if ( \is_scalar( $haystack ) === false ) { throw new TypeError( \sprintf( 'Argument 2 passed to assertStringContainsStringIgnoringLineEndings() must be of type string, %s given', \gettype( $haystack ) ) ); } $needle = self::normalizeLineEndingsForIgnoringLineEndingsAssertions( (string) $needle ); $haystack = self::normalizeLineEndingsForIgnoringLineEndingsAssertions( (string) $haystack ); static::assertStringContainsString( $needle, $haystack, $message ); } /** * Normalize line endings. * * @param string $value The text to normalize. * * @return string */ private static function normalizeLineEndingsForIgnoringLineEndingsAssertions( $value ) { return \strtr( $value, [ "\r\n" => "\n", "\r" => "\n", ] ); } /** * Helper function to obtain an instance of the Exporter class. * * @return Exporter|Exporter_In_Phar|Exporter_In_Phar_Old */ private static function getPHPUnitExporterObjectForIgnoringLineEndings() { if ( \class_exists( Exporter::class ) ) { // Composer install or really old PHAR files. return new Exporter(); } elseif ( \class_exists( Exporter_In_Phar::class ) ) { // PHPUnit PHAR file for 8.5.38+, 9.6.19+, 10.5.17+ and 11.0.10+. return new Exporter_In_Phar(); } // PHPUnit PHAR file for < 8.5.38, < 9.6.19, < 10.5.17 and < 11.0.10. return new Exporter_In_Phar_Old(); } }