fix: resolve test directory before function call

This commit is contained in:
Owen Voke
2021-05-14 09:33:52 +01:00
parent fb0eef4200
commit 41ce87450f
3 changed files with 15 additions and 4 deletions

View File

@ -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');

View File

@ -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';

View File

@ -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)
);