|
21 | 21 | use PHPUnit\Framework\Attributes\After; |
22 | 22 | use PHPUnit\Framework\Attributes\Before; |
23 | 23 | use PHPUnit\Framework\Attributes\CoversClass; |
| 24 | +use PHPUnit\Framework\Attributes\DataProvider; |
24 | 25 | use PHPUnit\Framework\Attributes\Group; |
25 | 26 | use Tests\Support\Commands\Modern\GeneratorFixtureCommand; |
26 | 27 | use Tests\Support\Commands\Modern\ImportSortingGeneratorCommand; |
@@ -413,16 +414,37 @@ public function testAcceptingCodeIgniterNamespacePromptProceeds(): void |
413 | 414 | $this->assertStringContainsString('File exists: ', $io->getOutput()); |
414 | 415 | } |
415 | 416 |
|
416 | | - public function testImportsAreSortedInGeneratedContent(): void |
| 417 | + #[DataProvider('provideImportsAreSortedInGeneratedContent')] |
| 418 | + public function testImportsAreSortedInGeneratedContent(string $template, string $expected): void |
417 | 419 | { |
418 | | - $command = new ImportSortingGeneratorCommand(new Commands()); |
| 420 | + $command = new ImportSortingGeneratorCommand(new Commands()); |
| 421 | + $command->renderedTemplate = $template; |
419 | 422 | $command->setInteractive(false); |
420 | 423 |
|
421 | 424 | $command->run(['foo'], []); |
422 | 425 |
|
423 | | - $content = file_get_contents(APPPATH . 'Widgets' . DIRECTORY_SEPARATOR . 'Foo.php'); |
424 | | - $this->assertIsString($content); |
425 | | - $this->assertStringContainsString("use App\\Alpha;\nuse App\\Zebra;", $content); |
| 426 | + $this->assertSame($expected, file_get_contents(APPPATH . 'Widgets' . DIRECTORY_SEPARATOR . 'Foo.php')); |
| 427 | + } |
| 428 | + |
| 429 | + /** |
| 430 | + * @return iterable<string, array{string, string}> |
| 431 | + */ |
| 432 | + public static function provideImportsAreSortedInGeneratedContent(): iterable |
| 433 | + { |
| 434 | + yield 'LF' => [ |
| 435 | + "<?php\n\nuse App\\Zebra;\nuse App\\Alpha;\n\nclass Foo {}\n", |
| 436 | + "<?php\n\nuse App\\Alpha;\nuse App\\Zebra;\n\nclass Foo {}\n", |
| 437 | + ]; |
| 438 | + |
| 439 | + yield 'CRLF' => [ |
| 440 | + "<?php\r\n\r\nuse App\\Zebra;\r\nuse App\\Alpha;\r\n\r\nclass Foo {}\r\n", |
| 441 | + "<?php\r\n\r\nuse App\\Alpha;\r\nuse App\\Zebra;\r\n\r\nclass Foo {}\r\n", |
| 442 | + ]; |
| 443 | + |
| 444 | + yield 'mixed' => [ |
| 445 | + "<?php\r\n\r\nuse App\\Zebra;\r\nuse App\\Beta;\nuse App\\Alpha;\r\n\r\nclass Foo {}\r\n", |
| 446 | + "<?php\r\n\r\nuse App\\Alpha;\r\nuse App\\Beta;\r\nuse App\\Zebra;\r\n\r\nclass Foo {}\r\n", |
| 447 | + ]; |
426 | 448 | } |
427 | 449 |
|
428 | 450 | public function testImportSortingCanBeDisabled(): void |
|
0 commit comments