X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=tools%2Fscripts%2Fphpunit;h=2e682bc0db51253824050b4d71b2a6a467c760d8;hb=54744051dea726c2b1495f24fc1cf7ba7fa25e11;hp=88617e471e3dcd6a41a67bae10f42953353b1c3f;hpb=81557205bd2bdaab0a27f160d6d549a962de9232;p=civicrm-core.git diff --git a/tools/scripts/phpunit b/tools/scripts/phpunit index 88617e471e..2e682bc0db 100755 --- a/tools/scripts/phpunit +++ b/tools/scripts/phpunit @@ -10,11 +10,20 @@ * This script is an adapter for backwards compatibility. */ +$argFilters = []; + if (PHP_SAPI !== 'cli') { die("phpunit can only be run from command line."); } if (version_compare(PHP_VERSION, '7.0', '>=')) { $phpunit = findCommand('phpunit6'); + $argFilters[] = function ($argv) { + $pos = array_search('--tap', $argv); + if ($pos !== FALSE) { + array_splice($argv, $pos, 1, ['--printer', '\Civi\Test\TAP']); + } + return $argv; + }; } elseif (version_compare(PHP_VERSION, '5.6', '>=')) { $phpunit = findCommand('phpunit5'); @@ -41,7 +50,7 @@ array_shift($argv); // Convert class names to file names $CIVICRM_UF = 'UnitTests'; foreach ($argv as $k => $v) { - if (preg_match('/^(CRM_|api_v3_|EnvTest|WebTest_|E2E_)/', $v)) { + if (preg_match('/^(CRM_|api_v3_|api_v4_|EnvTest|WebTest_|E2E_)/', $v)) { $argv[$k] = 'tests/phpunit/' . strtr($v, '_', '/') . '.php'; } elseif (preg_match('/^Civi\\\\/', $v)) { @@ -64,6 +73,10 @@ if (is_dir('packages/PHPUnit/')) { } } +foreach ($argFilters as $filter) { + $argv = $filter($argv); +} + $cmd = findPhp() // In case this system has multiple copies of PHP, use the active/preferred one. // . ' -ddisplay_errors=1' @@ -74,12 +87,20 @@ $cmd = passthru($cmd); function findPhp() { - if (defined('PHP_BINARY')) { - return PHP_BINARY; // php 5.4+ - } elseif (defined('PHP_BINDIR') && file_exists(PHP_BINDIR . '/php')) { - return PHP_BINDIR . '/php'; // php 5.3 - } else { - die("Failed to determine active PHP version."); + // The autodetect behavior here is a potential point of contention. These two cases are hard to reconcile: + // 1. `php` is actually a wrapper script which delegates to another PHP binary and + // passes options (such as INI's and PECL extensions). Subprocesses should use the wrapper script. + // Examples: bitnami, bknix + // 2. There are multiple PHP binaries (eg `php55`, `php70`). Subprocesses should use + // the final executable (regardless of its name). + // Example: using MAMP and adding 'ln -s /Application/MAMP/.../php7.1.2/bin/php ~/bin/php71` + // Since the test infra uses a wrapper script like (1), we use autodetect logic that works there. + // If you're in situation (2), then set an env-var or just skip on using `tools/scripts/phpunit`. + if (getenv('PHP')) { + return getenv('PHP'); + } + else { + return 'php'; } }