|
5 | 5 | use PHPUnit\Framework\AssertionFailedError;
|
6 | 6 | use PHPUnit\Framework\TestCase;
|
7 | 7 | use PHPUnit\Runner\Version as PHPUnit_Version;
|
8 |
| -use PHPUnit\SebastianBergmann\Exporter\Exporter as Exporter_In_Phar; |
| 8 | +use PHPUnit\SebastianBergmann\Exporter\Exporter as Exporter_In_Phar_Old; |
9 | 9 | use PHPUnit_Framework_AssertionFailedError;
|
| 10 | +use PHPUnitPHAR\SebastianBergmann\Exporter\Exporter as Exporter_In_Phar; |
10 | 11 | use SebastianBergmann\Exporter\Exporter;
|
11 | 12 | use stdClass;
|
12 | 13 | use TypeError;
|
@@ -140,7 +141,7 @@ public static function dataAssertStringEqualsStringIgnoringLineEndingsTypeVariat
|
140 | 141 | */
|
141 | 142 | public function testAssertStringEqualsStringIgnoringLineEndingsFails( $expected, $actual ) {
|
142 | 143 |
|
143 |
| - $exporter = \class_exists( Exporter::class ) ? new Exporter() : new Exporter_In_Phar(); |
| 144 | + $exporter = self::getPHPUnitExporterObjectForIgnoringLineEndingsForTests(); |
144 | 145 | $msg = \sprintf(
|
145 | 146 | 'Failed asserting that %s is equal to "%s" ignoring line endings.',
|
146 | 147 | $exporter->export( $actual ),
|
@@ -179,7 +180,7 @@ public function testAssertStringEqualsStringIgnoringLineEndingsFailsWithCustomMe
|
179 | 180 | $actual = 'ab';
|
180 | 181 | $expected = "a b\n";
|
181 | 182 |
|
182 |
| - $exporter = \class_exists( Exporter::class ) ? new Exporter() : new Exporter_In_Phar(); |
| 183 | + $exporter = self::getPHPUnitExporterObjectForIgnoringLineEndingsForTests(); |
183 | 184 | $msg = \sprintf(
|
184 | 185 | 'Failed asserting that %s is equal to "%s" ignoring line endings.',
|
185 | 186 | $exporter->export( $actual ),
|
@@ -316,7 +317,7 @@ public function testAssertStringContainsStringIgnoringLineEndingsBug5279( $needl
|
316 | 317 | * @return void
|
317 | 318 | */
|
318 | 319 | public function testAssertStringContainsStringIgnoringLineEndingsFails( $needle, $haystack ) {
|
319 |
| - $exporter = \class_exists( Exporter::class ) ? new Exporter() : new Exporter_In_Phar(); |
| 320 | + $exporter = self::getPHPUnitExporterObjectForIgnoringLineEndingsForTests(); |
320 | 321 | $pattern = \sprintf(
|
321 | 322 | '`^Failed asserting that %1$s%3$s contains "%2$s"%3$s\.`',
|
322 | 323 | \preg_quote( $exporter->export( $haystack ), '`' ),
|
@@ -389,4 +390,25 @@ private static function normalizeLineEndings( $value ) {
|
389 | 390 | ]
|
390 | 391 | );
|
391 | 392 | }
|
| 393 | + |
| 394 | + /** |
| 395 | + * Helper function to obtain an instance of the Exporter class. |
| 396 | + * |
| 397 | + * Note: the helper from the trait is accessible, but may not be available if the "empty" trait is being loaded. |
| 398 | + * |
| 399 | + * @return SebastianBergmann\Exporter\Exporter|PHPUnitPHAR\SebastianBergmann\Exporter\Exporter|PHPUnit\SebastianBergmann\Exporter\Exporter |
| 400 | + */ |
| 401 | + private static function getPHPUnitExporterObjectForIgnoringLineEndingsForTests() { |
| 402 | + if ( \class_exists( Exporter::class ) ) { |
| 403 | + // Composer install or really old PHAR files. |
| 404 | + return new Exporter(); |
| 405 | + } |
| 406 | + elseif ( \class_exists( Exporter_In_Phar::class ) ) { |
| 407 | + // PHPUnit PHAR file for 8.5.38+, 9.6.19+, 10.5.17+ and 11.0.10+. |
| 408 | + return new Exporter_In_Phar(); |
| 409 | + } |
| 410 | + |
| 411 | + // PHPUnit PHAR file for < 8.5.38, < 9.6.19, < 10.5.17 and < 11.0.10. |
| 412 | + return new Exporter_In_Phar_Old(); |
| 413 | + } |
392 | 414 | }
|
0 commit comments