From 50b5e150217fa4fd123bec32884417a03b0f28f3 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 21 Feb 2024 00:23:36 +0000 Subject: [PATCH] Use PHPUnit or ParaTest --- CHANGELOG.md | 1 + versa | 13 +++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d445d21..a9f5391 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ ### 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. * Add `versa build` to build a Sculpin project. * Add `--extra-args` to pass extra arguments to the underlying command. diff --git a/versa b/versa index 4eceed9..f641310 100755 --- a/versa +++ b/versa @@ -44,6 +44,8 @@ $application->addOption( $application->setCode(function (InputInterface $input): int { $projectType = null; + $devDependencies = []; + $extraArgs = $input->getOption('extra-args'); $workingDir = $input->getOption('working-dir'); @@ -59,6 +61,7 @@ $application->setCode(function (InputInterface $input): int { ); $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)) { $projectType = ProjectType::Drupal->value; @@ -135,10 +138,16 @@ $application->setCode(function (InputInterface $input): int { break; 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? $process = Process::create( - command: ['./vendor/bin/phpunit'], + command: $command, extraArgs: $extraArgs, workingDir: $workingDir, );