Skip to content

Commit

Permalink
feat: add support for Pest in vapor test (#233)
Browse files Browse the repository at this point in the history
* feat: add support for Pest in `vapor test`

* set working directory

* handle --pest option

* Update TestCommand.php

---------

Co-authored-by: Joe Dixon <[email protected]>
Co-authored-by: Taylor Otwell <[email protected]>
  • Loading branch information
3 people authored Sep 15, 2023
1 parent 073eeb8 commit 7eff841
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/Commands/LocalCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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',
Expand Down
15 changes: 13 additions & 2 deletions src/Commands/TestCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand All @@ -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';
}
}

0 comments on commit 7eff841

Please sign in to comment.