From 41ce87450fd59376a5e21145f93d7a1cd2183f6d Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Fri, 14 May 2021 09:33:52 +0100 Subject: [PATCH 1/3] fix: resolve test directory before function call --- src/Laravel/Commands/PestDatasetCommand.php | 6 +++++- src/Laravel/Commands/PestInstallCommand.php | 5 ++++- src/Laravel/Commands/PestTestCommand.php | 8 ++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Laravel/Commands/PestDatasetCommand.php b/src/Laravel/Commands/PestDatasetCommand.php index 64dd63b4..4fbc1469 100644 --- a/src/Laravel/Commands/PestDatasetCommand.php +++ b/src/Laravel/Commands/PestDatasetCommand.php @@ -8,6 +8,7 @@ use Illuminate\Console\Command; use Illuminate\Support\Facades\File; use Illuminate\Support\Str; use Pest\Exceptions\InvalidConsoleArgument; +use Pest\TestSuite; use function Pest\testDirectory; /** @@ -20,7 +21,8 @@ final class PestDatasetCommand extends Command * * @var string */ - protected $signature = 'pest:dataset {name : The name of the dataset}'; + protected $signature = 'pest:dataset {name : The name of the dataset} + {--test-directory=tests : The name of the tests directory}'; /** * The console command description. @@ -34,6 +36,8 @@ final class PestDatasetCommand extends Command */ public function handle(): void { + TestSuite::getInstance(base_path(), $this->option('test-directory', 'tests')); + /** @var string $name */ $name = $this->argument('name'); diff --git a/src/Laravel/Commands/PestInstallCommand.php b/src/Laravel/Commands/PestInstallCommand.php index 34d3503a..91f6ee91 100644 --- a/src/Laravel/Commands/PestInstallCommand.php +++ b/src/Laravel/Commands/PestInstallCommand.php @@ -8,6 +8,7 @@ use Illuminate\Console\Command; use Illuminate\Support\Facades\File; use Pest\Console\Thanks; use Pest\Exceptions\InvalidConsoleArgument; +use Pest\TestSuite; use function Pest\testDirectory; /** @@ -20,7 +21,7 @@ final class PestInstallCommand extends Command * * @var string */ - protected $signature = 'pest:install'; + protected $signature = 'pest:install {--test-directory=tests : The name of the tests directory}'; /** * The console command description. @@ -34,6 +35,8 @@ final class PestInstallCommand extends Command */ public function handle(): void { + TestSuite::getInstance(base_path(), $this->option('test-directory', 'tests')); + /* @phpstan-ignore-next-line */ $pest = base_path(testDirectory('Pest.php')); $stubs = 'stubs/Laravel'; diff --git a/src/Laravel/Commands/PestTestCommand.php b/src/Laravel/Commands/PestTestCommand.php index 793d425b..aeb60e53 100644 --- a/src/Laravel/Commands/PestTestCommand.php +++ b/src/Laravel/Commands/PestTestCommand.php @@ -8,6 +8,7 @@ use Illuminate\Console\Command; use Illuminate\Support\Facades\File; use Pest\Exceptions\InvalidConsoleArgument; use Pest\Support\Str; +use Pest\TestSuite; use function Pest\testDirectory; /** @@ -20,7 +21,7 @@ final class PestTestCommand extends Command * * @var string */ - protected $signature = 'pest:test {name : The name of the file} {--unit : Create a unit test} {--dusk : Create a Dusk test}'; + protected $signature = 'pest:test {name : The name of the file} {--unit : Create a unit test} {--dusk : Create a Dusk test} {--test-directory=tests : The name of the tests directory}'; /** * The console command description. @@ -34,12 +35,15 @@ final class PestTestCommand extends Command */ public function handle(): void { + TestSuite::getInstance(base_path(), $this->option('test-directory', 'tests')); + /** @var string $name */ $name = $this->argument('name'); $type = ((bool) $this->option('unit')) ? 'Unit' : (((bool) $this->option('dusk')) ? 'Browser' : 'Feature'); - $relativePath = sprintf(testDirectory('%s/%s.php'), + $relativePath = sprintf( + testDirectory('%s/%s.php'), $type, ucfirst($name) ); From 564a21badd03b8bf2908dd6fe8a9443733b3afb9 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Fri, 14 May 2021 10:00:53 +0100 Subject: [PATCH 2/3] style: apply fixes from php-cs-fixer --- src/Laravel/Commands/PestDatasetCommand.php | 2 +- src/Laravel/Commands/PestInstallCommand.php | 2 +- src/Laravel/Commands/PestTestCommand.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Laravel/Commands/PestDatasetCommand.php b/src/Laravel/Commands/PestDatasetCommand.php index 4fbc1469..14bd79ac 100644 --- a/src/Laravel/Commands/PestDatasetCommand.php +++ b/src/Laravel/Commands/PestDatasetCommand.php @@ -8,8 +8,8 @@ use Illuminate\Console\Command; use Illuminate\Support\Facades\File; use Illuminate\Support\Str; use Pest\Exceptions\InvalidConsoleArgument; -use Pest\TestSuite; use function Pest\testDirectory; +use Pest\TestSuite; /** * @internal diff --git a/src/Laravel/Commands/PestInstallCommand.php b/src/Laravel/Commands/PestInstallCommand.php index 91f6ee91..98e201fb 100644 --- a/src/Laravel/Commands/PestInstallCommand.php +++ b/src/Laravel/Commands/PestInstallCommand.php @@ -8,8 +8,8 @@ use Illuminate\Console\Command; use Illuminate\Support\Facades\File; use Pest\Console\Thanks; use Pest\Exceptions\InvalidConsoleArgument; -use Pest\TestSuite; use function Pest\testDirectory; +use Pest\TestSuite; /** * @internal diff --git a/src/Laravel/Commands/PestTestCommand.php b/src/Laravel/Commands/PestTestCommand.php index aeb60e53..2c3aa1b8 100644 --- a/src/Laravel/Commands/PestTestCommand.php +++ b/src/Laravel/Commands/PestTestCommand.php @@ -8,8 +8,8 @@ use Illuminate\Console\Command; use Illuminate\Support\Facades\File; use Pest\Exceptions\InvalidConsoleArgument; use Pest\Support\Str; -use Pest\TestSuite; use function Pest\testDirectory; +use Pest\TestSuite; /** * @internal From ea8ab880569cbaad07970fe503ea67c0b22577b5 Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Fri, 14 May 2021 10:04:01 +0100 Subject: [PATCH 3/3] style: apply fixes from PHPStan --- src/Laravel/Commands/PestDatasetCommand.php | 3 ++- src/Laravel/Commands/PestInstallCommand.php | 3 ++- src/Laravel/Commands/PestTestCommand.php | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Laravel/Commands/PestDatasetCommand.php b/src/Laravel/Commands/PestDatasetCommand.php index 14bd79ac..e5cab365 100644 --- a/src/Laravel/Commands/PestDatasetCommand.php +++ b/src/Laravel/Commands/PestDatasetCommand.php @@ -36,7 +36,8 @@ final class PestDatasetCommand extends Command */ public function handle(): void { - TestSuite::getInstance(base_path(), $this->option('test-directory', 'tests')); + /* @phpstan-ignore-next-line */ + TestSuite::getInstance(base_path(), $this->option('test-directory')); /** @var string $name */ $name = $this->argument('name'); diff --git a/src/Laravel/Commands/PestInstallCommand.php b/src/Laravel/Commands/PestInstallCommand.php index 98e201fb..75f6dd54 100644 --- a/src/Laravel/Commands/PestInstallCommand.php +++ b/src/Laravel/Commands/PestInstallCommand.php @@ -35,7 +35,8 @@ final class PestInstallCommand extends Command */ public function handle(): void { - TestSuite::getInstance(base_path(), $this->option('test-directory', 'tests')); + /* @phpstan-ignore-next-line */ + TestSuite::getInstance(base_path(), $this->option('test-directory')); /* @phpstan-ignore-next-line */ $pest = base_path(testDirectory('Pest.php')); diff --git a/src/Laravel/Commands/PestTestCommand.php b/src/Laravel/Commands/PestTestCommand.php index 2c3aa1b8..55d9dc3a 100644 --- a/src/Laravel/Commands/PestTestCommand.php +++ b/src/Laravel/Commands/PestTestCommand.php @@ -35,7 +35,8 @@ final class PestTestCommand extends Command */ public function handle(): void { - TestSuite::getInstance(base_path(), $this->option('test-directory', 'tests')); + /* @phpstan-ignore-next-line */ + TestSuite::getInstance(base_path(), $this->option('test-directory')); /** @var string $name */ $name = $this->argument('name');