diff --git a/src/Console/Concerns/InteractsWithTestingFrameworks.php b/src/Console/Concerns/InteractsWithTestingFrameworks.php new file mode 100644 index 000000000..7cb0e2a58 --- /dev/null +++ b/src/Console/Concerns/InteractsWithTestingFrameworks.php @@ -0,0 +1,16 @@ +option('pest')) { + if ($this->usingPest()) { $binaryPath = 'vendor/pestphp/pest/bin/pest'; } @@ -172,7 +173,7 @@ protected function env() */ protected function shouldUseCollisionPrinter() { - return ! $this->option('pest') + return ! $this->usingPest() && class_exists(EnsurePrinterIsRegisteredSubscriber::class) && version_compare(Version::id(), '10.0', '>='); } diff --git a/src/Console/InstallCommand.php b/src/Console/InstallCommand.php index 62d7597ed..a4ccdf8b8 100644 --- a/src/Console/InstallCommand.php +++ b/src/Console/InstallCommand.php @@ -6,6 +6,8 @@ class InstallCommand extends Command { + use Concerns\InteractsWithTestingFrameworks; + /** * The name and signature of the console command. * @@ -50,12 +52,30 @@ public function handle() } $stubs = [ - 'ExampleTest.stub' => base_path('tests/Browser/ExampleTest.php'), 'HomePage.stub' => base_path('tests/Browser/Pages/HomePage.php'), 'DuskTestCase.stub' => base_path('tests/DuskTestCase.php'), 'Page.stub' => base_path('tests/Browser/Pages/Page.php'), ]; + if ($this->usingPest()) { + $stubs['ExampleTest.pest.stub'] = base_path('tests/Browser/ExampleTest.php'); + + $contents = file_get_contents(base_path('tests/Pest.php')); + + $contents = str_replace('in('Browser'); + EOT, $contents); + + file_put_contents(base_path('tests/Pest.php'), $contents); + } else { + $stubs['ExampleTest.stub'] = base_path('tests/Browser/ExampleTest.php'); + } + foreach ($stubs as $stub => $file) { if (! is_file($file)) { copy(__DIR__.'/../../stubs/'.$stub, $file); diff --git a/src/Console/MakeCommand.php b/src/Console/MakeCommand.php index 98dd70c74..fa2062c61 100644 --- a/src/Console/MakeCommand.php +++ b/src/Console/MakeCommand.php @@ -7,6 +7,8 @@ class MakeCommand extends GeneratorCommand { + use Concerns\InteractsWithTestingFrameworks; + /** * The console command name. * @@ -35,7 +37,9 @@ class MakeCommand extends GeneratorCommand */ protected function getStub() { - return __DIR__.'/stubs/test.stub'; + return $this->usingPest() + ? __DIR__.'/stubs/test.pest.stub' + : __DIR__.'/stubs/test.stub'; } /** diff --git a/src/Console/stubs/test.pest.stub b/src/Console/stubs/test.pest.stub new file mode 100644 index 000000000..0b37062b7 --- /dev/null +++ b/src/Console/stubs/test.pest.stub @@ -0,0 +1,10 @@ +browse(function (Browser $browser) { + $browser->visit('/') + ->assertSee('Laravel'); + }); +}); diff --git a/stubs/ExampleTest.pest.stub b/stubs/ExampleTest.pest.stub new file mode 100644 index 000000000..89a00645a --- /dev/null +++ b/stubs/ExampleTest.pest.stub @@ -0,0 +1,10 @@ +browse(function (Browser $browser) { + $browser->visit('/') + ->assertSee('Laravel'); + }); +});