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.");
17 $phpunit = findCommand('phpunit4');
19 $phpunit = findCommand('phpunit');
22 echo "Plesae ensure that:\n";
23 echo " * PHPUnit is installed.\n";
24 echo " * The extensions for dbunit and selenium are installed.\n" ;
25 echo " * The command \"phpunit\" is in the PATH.\n";
26 echo "See also: https://github.com/civicrm/civicrm-buildkit/\n";
30 chdir(dirname(dirname(__DIR__
))); // civicrm-core root dir
34 // Convert class names to file names
35 foreach ($argv as $k => $v) {
36 if (preg_match('/^(CRM_|api_v3_|EnvTest|WebTest_)/', $v)) {
37 $argv[$k] = 'tests/phpunit/' . strtr($v, '_', '/') . '.php';
39 elseif (preg_match('/^Civi\\\\/', $v)) {
40 $argv[$k] = 'tests/phpunit/' . strtr($v, '\\', '/') . '.php';
43 if (!preg_match('/^(WebTest)/', $v)) {
44 putenv('CIVICRM_UF=UnitTests');
48 // Transition: Make sure we use phpunit code from PATH, not
49 // civicrm-packages. This will be unnecessary once civicrm-packages is
51 if (is_dir('packages/PHPUnit/')) {
52 if (!rename('packages/PHPUnit', 'packages/PHPUnit.bak')) {
53 echo "Failed to move aside stale copy of PHPUnit.\n";
59 findPhp() // In case this system has multiple copies of PHP, use the active/preferred one.
60 // . ' -ddisplay_errors=1'
62 . escapeshellarg($phpunit)
64 . implode(' ', array_map('escapeshellarg', $argv));
68 if (defined('PHP_BINARY')) {
69 return PHP_BINARY
; // php 5.4+
70 } elseif (defined('PHP_BINDIR') && file_exists(PHP_BINDIR
. '/php')) {
71 return PHP_BINDIR
. '/php'; // php 5.3
73 die("Failed to determine active PHP version.");
77 function findCommand($name) {
78 $paths = explode(PATH_SEPARATOR
, getenv('PATH'));
79 foreach ($paths as $path) {
80 if (file_exists("$path/$name")) {