|
23 | 23 | use PHPUnit\Framework\Attributes\After; |
24 | 24 | use PHPUnit\Framework\Attributes\Before; |
25 | 25 | use PHPUnit\Framework\Attributes\CoversClass; |
| 26 | +use PHPUnit\Framework\Attributes\DataProvider; |
26 | 27 | use PHPUnit\Framework\Attributes\Group; |
27 | 28 | use Tests\Support\Commands\Modern\GeneratorFixtureCommand; |
28 | 29 | use Tests\Support\Commands\Modern\ImportSortingGeneratorCommand; |
@@ -498,16 +499,37 @@ protected function execute(array $arguments, array $options): int |
498 | 499 | }; |
499 | 500 | } |
500 | 501 |
|
501 | | - public function testImportsAreSortedInGeneratedContent(): void |
| 502 | + #[DataProvider('provideImportsAreSortedInGeneratedContent')] |
| 503 | + public function testImportsAreSortedInGeneratedContent(string $template, string $expected): void |
502 | 504 | { |
503 | | - $command = new ImportSortingGeneratorCommand(new Commands()); |
| 505 | + $command = new ImportSortingGeneratorCommand(new Commands()); |
| 506 | + $command->renderedTemplate = $template; |
504 | 507 | $command->setInteractive(false); |
505 | 508 |
|
506 | 509 | $command->run(['foo'], []); |
507 | 510 |
|
508 | | - $content = file_get_contents(APPPATH . 'Widgets' . DIRECTORY_SEPARATOR . 'Foo.php'); |
509 | | - $this->assertIsString($content); |
510 | | - $this->assertStringContainsString("use App\\Alpha;\nuse App\\Zebra;", $content); |
| 511 | + $this->assertSame($expected, file_get_contents(APPPATH . 'Widgets' . DIRECTORY_SEPARATOR . 'Foo.php')); |
| 512 | + } |
| 513 | + |
| 514 | + /** |
| 515 | + * @return iterable<string, array{string, string}> |
| 516 | + */ |
| 517 | + public static function provideImportsAreSortedInGeneratedContent(): iterable |
| 518 | + { |
| 519 | + yield 'LF' => [ |
| 520 | + "<?php\n\nuse App\\Zebra;\nuse App\\Alpha;\n\nclass Foo {}\n", |
| 521 | + "<?php\n\nuse App\\Alpha;\nuse App\\Zebra;\n\nclass Foo {}\n", |
| 522 | + ]; |
| 523 | + |
| 524 | + yield 'CRLF' => [ |
| 525 | + "<?php\r\n\r\nuse App\\Zebra;\r\nuse App\\Alpha;\r\n\r\nclass Foo {}\r\n", |
| 526 | + "<?php\r\n\r\nuse App\\Alpha;\r\nuse App\\Zebra;\r\n\r\nclass Foo {}\r\n", |
| 527 | + ]; |
| 528 | + |
| 529 | + yield 'mixed' => [ |
| 530 | + "<?php\r\n\r\nuse App\\Zebra;\r\nuse App\\Beta;\nuse App\\Alpha;\r\n\r\nclass Foo {}\r\n", |
| 531 | + "<?php\r\n\r\nuse App\\Alpha;\r\nuse App\\Beta;\r\nuse App\\Zebra;\r\n\r\nclass Foo {}\r\n", |
| 532 | + ]; |
511 | 533 | } |
512 | 534 |
|
513 | 535 | public function testImportSortingCanBeDisabled(): void |
|
0 commit comments