From 7eff8413d780406c3ea82084f7db48638de35e6c Mon Sep 17 00:00:00 2001 From: Owen Voke Date: Fri, 15 Sep 2023 14:20:31 +0100 Subject: [PATCH] feat: add support for Pest in `vapor test` (#233) * feat: add support for Pest in `vapor test` * set working directory * handle --pest option * Update TestCommand.php --------- Co-authored-by: Joe Dixon Co-authored-by: Taylor Otwell --- src/Commands/LocalCommand.php | 3 ++- src/Commands/TestCommand.php | 15 +++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Commands/LocalCommand.php b/src/Commands/LocalCommand.php index aa76c7b3..54b908e1 100644 --- a/src/Commands/LocalCommand.php +++ b/src/Commands/LocalCommand.php @@ -57,7 +57,7 @@ protected function configure() */ public function handle() { - $options = array_slice($_SERVER['argv'], $this->option('php') ? 3 : 2); + $options = array_slice($_SERVER['argv'], $this->option('php') && array_search('--php='.$this->option('php'), $_SERVER['argv']) !== false ? 3 : 2); $status = 0; @@ -79,6 +79,7 @@ public function handle() '-e DB_USERNAME=vapor', '-e DB_PASSWORD=secret', '-e REDIS_HOST=redis', + '-w /app', '-v', Path::current().':/app', 'app', diff --git a/src/Commands/TestCommand.php b/src/Commands/TestCommand.php index e47ec7de..77a77dcb 100644 --- a/src/Commands/TestCommand.php +++ b/src/Commands/TestCommand.php @@ -30,7 +30,8 @@ protected function configure() $this ->setName('test') ->addOption('php', null, InputOption::VALUE_OPTIONAL, 'The PHP version that should be used to execute the tests') - ->setDescription('Run PHPUnit inside a simulated Vapor environment'); + ->addOption('pest', null, InputOption::VALUE_NONE, 'Run Pest tests') + ->setDescription('Run PHPUnit or Pest inside a simulated Vapor environment'); } /** @@ -42,10 +43,20 @@ protected function configure() */ public function handle() { - array_splice($_SERVER['argv'], 2, 0, 'vendor/bin/phpunit'); + array_splice($_SERVER['argv'], 2, count($_SERVER['argv']), $this->getTestRunnerBinary()); $this->getApplication()->find('local')->run(new ArrayInput([ '--php' => $this->option('php'), ]), $this->output); } + + /** + * Determine the test runner binary. + * + * @return string + */ + protected function getTestRunnerBinary() + { + return $this->option('pest') ? 'vendor/bin/pest' : 'vendor/bin/phpunit'; + } }