5 * In the past, Civi bundled a hacked copy of PHPUnit used like:
8 * ./scripts/phpunit Some_Class_NameTest
10 * This script is an adapter for backwards compatibility.
13 if (PHP_SAPI
!== 'cli') {
14 die("phpunit can only be run from command line.");
16 if (version_compare(PHP_VERSION
, '5.6', '>=')) {
17 $phpunit = findCommand('phpunit5');
20 $phpunit = findCommand('phpunit4');
23 $phpunit = findCommand('phpunit');
26 echo "Plesae ensure that:\n";
27 echo " * PHPUnit is installed.\n";
28 echo " * The extensions for dbunit and selenium are installed.\n" ;
29 echo " * The command \"phpunit\" is in the PATH.\n";
30 echo "See also: https://github.com/civicrm/civicrm-buildkit/\n";
34 chdir(dirname(dirname(__DIR__
))); // civicrm-core root dir
38 // Convert class names to file names
39 $CIVICRM_UF = 'UnitTests';
40 foreach ($argv as $k => $v) {
41 if (preg_match('/^(CRM_|api_v3_|EnvTest|WebTest_|E2E_)/', $v)) {
42 $argv[$k] = 'tests/phpunit/' . strtr($v, '_', '/') . '.php';
44 elseif (preg_match('/^Civi\\\\/', $v)) {
45 $argv[$k] = 'tests/phpunit/' . strtr($v, '\\', '/') . '.php';
48 if (preg_match('/^(WebTest|E2E)/', $v)) {
52 putenv("CIVICRM_UF=$CIVICRM_UF");
54 // Transition: Make sure we use phpunit code from PATH, not
55 // civicrm-packages. This will be unnecessary once civicrm-packages is
57 if (is_dir('packages/PHPUnit/')) {
58 if (!rename('packages/PHPUnit', 'packages/PHPUnit.bak')) {
59 echo "Failed to move aside stale copy of PHPUnit.\n";
65 findPhp() // In case this system has multiple copies of PHP, use the active/preferred one.
66 // . ' -ddisplay_errors=1'
68 . escapeshellarg($phpunit)
70 . implode(' ', array_map('escapeshellarg', $argv));
74 if (defined('PHP_BINARY')) {
75 return PHP_BINARY
; // php 5.4+
76 } elseif (defined('PHP_BINDIR') && file_exists(PHP_BINDIR
. '/php')) {
77 return PHP_BINDIR
. '/php'; // php 5.3
79 die("Failed to determine active PHP version.");
83 function findCommand($name) {
84 $paths = explode(PATH_SEPARATOR
, getenv('PATH'));
85 foreach ($paths as $path) {
86 if (file_exists("$path/$name")) {