Use PHPUnit or ParaTest

This commit is contained in:
Oliver Davies 2024-02-21 00:23:36 +00:00
parent 7ee4e308d5
commit 50b5e15021
2 changed files with 12 additions and 2 deletions

View file

@ -4,6 +4,7 @@
### Added ### Added
* Automatically use PHPUnit or ParaTest based on `require-dev` dependencies.
* Automatically find the PHP project type (i.e. Drupal or Sculpin) based on its `composer.json` dependencies. * Automatically find the PHP project type (i.e. Drupal or Sculpin) based on its `composer.json` dependencies.
* Add `versa build` to build a Sculpin project. * Add `versa build` to build a Sculpin project.
* Add `--extra-args` to pass extra arguments to the underlying command. * Add `--extra-args` to pass extra arguments to the underlying command.

13
versa
View file

@ -44,6 +44,8 @@ $application->addOption(
$application->setCode(function (InputInterface $input): int { $application->setCode(function (InputInterface $input): int {
$projectType = null; $projectType = null;
$devDependencies = [];
$extraArgs = $input->getOption('extra-args'); $extraArgs = $input->getOption('extra-args');
$workingDir = $input->getOption('working-dir'); $workingDir = $input->getOption('working-dir');
@ -59,6 +61,7 @@ $application->setCode(function (InputInterface $input): int {
); );
$dependencies = array_keys($json['require']); $dependencies = array_keys($json['require']);
$devDependencies = array_keys($json['require-dev']);
if (in_array(needle: 'drupal/core', haystack: $dependencies, strict: true) || in_array(needle: 'drupal/core-recommended', haystack: $dependencies, strict: true)) { if (in_array(needle: 'drupal/core', haystack: $dependencies, strict: true) || in_array(needle: 'drupal/core-recommended', haystack: $dependencies, strict: true)) {
$projectType = ProjectType::Drupal->value; $projectType = ProjectType::Drupal->value;
@ -135,10 +138,16 @@ $application->setCode(function (InputInterface $input): int {
break; break;
case 'test': case 'test':
// TODO: PHPUnit, Pest or ParaTest. // TODO: Pest and Behat.
if (in_array(needle: 'brianium/paratest', haystack: $devDependencies, strict: true)) {
$command = ['./vendor/bin/paratest'];
} else {
$command = ['./vendor/bin/phpunit'];
}
// TODO: commands in Docker Compose? // TODO: commands in Docker Compose?
$process = Process::create( $process = Process::create(
command: ['./vendor/bin/phpunit'], command: $command,
extraArgs: $extraArgs, extraArgs: $extraArgs,
workingDir: $workingDir, workingDir: $workingDir,
); );