|
6 | 6 | use Illuminate\Support\Composer;
|
7 | 7 | use Illuminate\Support\ProcessUtils;
|
8 | 8 | use Illuminate\Support\Str;
|
| 9 | +use RecursiveDirectoryIterator; |
| 10 | +use RecursiveIteratorIterator; |
9 | 11 | use RuntimeException;
|
10 | 12 | use Symfony\Component\Console\Command\Command;
|
11 | 13 | use Symfony\Component\Console\Input\InputArgument;
|
@@ -149,17 +151,12 @@ protected function interact(InputInterface $input, OutputInterface $output)
|
149 | 151 | }
|
150 | 152 | }
|
151 | 153 |
|
152 |
| - if ($this->usingLaravelStarterKit($input)) { |
153 |
| - if (! $input->getOption('phpunit') && |
154 |
| - ! $input->getOption('pest')) { |
155 |
| - $input->setOption('pest', select( |
156 |
| - label: 'Which testing framework do you prefer?', |
157 |
| - options: ['Pest', 'PHPUnit'], |
158 |
| - default: 'Pest', |
159 |
| - ) === 'Pest'); |
160 |
| - } |
161 |
| - } else { |
162 |
| - $input->setOption('phpunit', true); |
| 154 | + if (! $input->getOption('phpunit') && ! $input->getOption('pest')) { |
| 155 | + $input->setOption('pest', select( |
| 156 | + label: 'Which testing framework do you prefer?', |
| 157 | + options: ['Pest', 'PHPUnit'], |
| 158 | + default: 'Pest', |
| 159 | + ) === 'Pest'); |
163 | 160 | }
|
164 | 161 | }
|
165 | 162 |
|
@@ -587,36 +584,45 @@ protected function installPest(string $directory, InputInterface $input, OutputI
|
587 | 584 | $this->phpBinary().' ./vendor/bin/pest --init',
|
588 | 585 | ];
|
589 | 586 |
|
590 |
| - if ($this->usingStarterKit($input)) { |
591 |
| - $commands[] = $composerBinary.' require pestphp/pest-plugin-drift --dev'; |
592 |
| - $commands[] = $this->phpBinary().' ./vendor/bin/pest --drift'; |
593 |
| - $commands[] = $composerBinary.' remove pestphp/pest-plugin-drift --dev'; |
594 |
| - } |
| 587 | + $commands[] = $composerBinary.' require pestphp/pest-plugin-drift --dev'; |
| 588 | + $commands[] = $this->phpBinary().' ./vendor/bin/pest --drift'; |
| 589 | + $commands[] = $composerBinary.' remove pestphp/pest-plugin-drift --dev'; |
595 | 590 |
|
596 | 591 | $this->runCommands($commands, $input, $output, workingPath: $directory, env: [
|
597 | 592 | 'PEST_NO_SUPPORT' => 'true',
|
598 | 593 | ]);
|
599 | 594 |
|
600 |
| - $this->replaceFile( |
601 |
| - 'pest/Feature.php', |
602 |
| - $directory.'/tests/Feature/ExampleTest.php', |
603 |
| - ); |
604 |
| - |
605 |
| - $this->replaceFile( |
606 |
| - 'pest/Unit.php', |
607 |
| - $directory.'/tests/Unit/ExampleTest.php', |
608 |
| - ); |
609 |
| - |
610 | 595 | if ($this->usingStarterKit($input)) {
|
611 | 596 | $this->replaceInFile(
|
612 | 597 | './vendor/bin/phpunit',
|
613 | 598 | './vendor/bin/pest',
|
614 | 599 | $directory.'/.github/workflows/tests.yml',
|
615 | 600 | );
|
616 |
| - } |
617 | 601 |
|
618 |
| - if ($this->usingStarterKit($input) && $input->getOption('phpunit')) { |
619 |
| - $this->deleteFile($directory.'/tests/Pest.php'); |
| 602 | + $contents = file_get_contents("$directory/tests/Pest.php"); |
| 603 | + |
| 604 | + $contents = str_replace( |
| 605 | + " // ->use(Illuminate\Foundation\Testing\RefreshDatabase::class)", |
| 606 | + " ->use(Illuminate\Foundation\Testing\RefreshDatabase::class)", |
| 607 | + $contents, |
| 608 | + ); |
| 609 | + |
| 610 | + file_put_contents("$directory/tests/Pest.php", $contents); |
| 611 | + |
| 612 | + $directoryIterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)); |
| 613 | + |
| 614 | + foreach ($directoryIterator as $testFile) { |
| 615 | + if ($testFile->isDir()) { |
| 616 | + continue; |
| 617 | + } |
| 618 | + |
| 619 | + $contents = file_get_contents($testFile); |
| 620 | + |
| 621 | + file_put_contents( |
| 622 | + $testFile, |
| 623 | + str_replace("\n\nuses(\Illuminate\Foundation\Testing\RefreshDatabase::class);", '', $contents), |
| 624 | + ); |
| 625 | + } |
620 | 626 | }
|
621 | 627 |
|
622 | 628 | $this->commitChanges('Install Pest', $directory, $input, $output);
|
|
0 commit comments