72e46ef00c0c4f211260b5fba69d543209664797
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('phpunit');
19 echo "Plesae ensure that:\n";
20 echo " * PHPUnit is installed.\n";
21 echo " * The extensions for dbunit and selenium are installed.\n" ;
22 echo " * The command \"phpunit\" is in the PATH.\n";
23 echo "See also: https://github.com/civicrm/civicrm-buildkit/\n";
27 chdir(dirname(dirname(__DIR__
))); // civicrm-core root dir
31 // Convert class names to file names
32 foreach ($argv as $k => $v) {
33 if (preg_match('/^(CRM_|api_v3|WebTest_)/', $v)) {
34 $argv[$k] = 'tests/phpunit/' . strtr($v, '_', '/') . '.php';
36 elseif (preg_match('/^Civi\\\\/', $v)) {
37 $argv[$k] = 'tests/phpunit/' . strtr($v, '\\', '/') . '.php';
41 // Transition: Make sure we use phpunit code from PATH, not
42 // civicrm-packages. This will be unnecessary once civicrm-packages is
44 if (is_dir('packages/PHPUnit/')) {
45 if (!rename('packages/PHPUnit', 'packages/PHPUnit.bak')) {
46 echo "Failed to move aside stale copy of PHPUnit.\n";
52 findPhp() // In case this system has multiple copies of PHP, use the active/preferred one.
54 . escapeshellarg($phpunit)
56 . implode(' ', array_map('escapeshellarg', $argv));
60 if (defined('PHP_BINARY')) {
61 return PHP_BINARY
; // php 5.4+
62 } elseif (defined('PHP_BINDIR') && file_exists(PHP_BINDIR
. '/php')) {
63 return PHP_BINDIR
. '/php'; // php 5.3
65 die("Failed to determine active PHP version.");
69 function findCommand($name) {
70 $paths = explode(PATH_SEPARATOR
, getenv('PATH'));
71 foreach ($paths as $path) {
72 if (file_exists("$path/$name")) {