Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | #!/usr/bin/env php |
2 | <?php | |
620c8b6e TO |
3 | |
4 | /** | |
5 | * In the past, Civi bundled a hacked copy of PHPUnit used like: | |
6a488035 | 6 | * |
620c8b6e TO |
7 | * cd tools |
8 | * ./scripts/phpunit Some_Class_NameTest | |
6a488035 | 9 | * |
620c8b6e | 10 | * This script is an adapter for backwards compatibility. |
6a488035 TO |
11 | */ |
12 | ||
620c8b6e TO |
13 | if (PHP_SAPI !== 'cli') { |
14 | die("phpunit can only be run from command line."); | |
89771184 TO |
15 | } |
16 | ||
620c8b6e TO |
17 | $phpunit = findCommand('phpunit'); |
18 | if (!$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"; | |
24 | exit(127); | |
6a488035 TO |
25 | } |
26 | ||
620c8b6e | 27 | chdir(dirname(dirname(__DIR__))); // civicrm-core root dir |
6a488035 | 28 | |
620c8b6e | 29 | array_shift($argv); |
6a488035 | 30 | |
620c8b6e TO |
31 | // Convert class names to file names |
32 | foreach ($argv as $k => $v) { | |
fa71ec19 | 33 | if (preg_match('/^(CRM_|api_v3_|EnvTest|WebTest_)/', $v)) { |
620c8b6e | 34 | $argv[$k] = 'tests/phpunit/' . strtr($v, '_', '/') . '.php'; |
7e0295ce TO |
35 | } |
36 | elseif (preg_match('/^Civi\\\\/', $v)) { | |
37 | $argv[$k] = 'tests/phpunit/' . strtr($v, '\\', '/') . '.php'; | |
620c8b6e | 38 | } |
f5dfa52e TO |
39 | |
40 | if (!preg_match('/^(WebTest)/', $v)) { | |
41 | putenv('CIVICRM_UF=UnitTests'); | |
42 | } | |
620c8b6e | 43 | } |
6a488035 | 44 | |
620c8b6e TO |
45 | // Transition: Make sure we use phpunit code from PATH, not |
46 | // civicrm-packages. This will be unnecessary once civicrm-packages is | |
47 | // updated. | |
48 | if (is_dir('packages/PHPUnit/')) { | |
49 | if (!rename('packages/PHPUnit', 'packages/PHPUnit.bak')) { | |
50 | echo "Failed to move aside stale copy of PHPUnit.\n"; | |
51 | exit(1); | |
52 | } | |
53 | } | |
6a488035 | 54 | |
620c8b6e TO |
55 | $cmd = |
56 | findPhp() // In case this system has multiple copies of PHP, use the active/preferred one. | |
f5dfa52e | 57 | // . ' -ddisplay_errors=1' |
620c8b6e TO |
58 | . ' ' |
59 | . escapeshellarg($phpunit) | |
60 | . ' ' | |
61 | . implode(' ', array_map('escapeshellarg', $argv)); | |
62 | passthru($cmd); | |
6a488035 | 63 | |
620c8b6e TO |
64 | function findPhp() { |
65 | if (defined('PHP_BINARY')) { | |
66 | return PHP_BINARY; // php 5.4+ | |
67 | } elseif (defined('PHP_BINDIR') && file_exists(PHP_BINDIR . '/php')) { | |
68 | return PHP_BINDIR . '/php'; // php 5.3 | |
69 | } else { | |
70 | die("Failed to determine active PHP version."); | |
71 | } | |
72 | } | |
73 | ||
74 | function findCommand($name) { | |
75 | $paths = explode(PATH_SEPARATOR, getenv('PATH')); | |
76 | foreach ($paths as $path) { | |
77 | if (file_exists("$path/$name")) { | |
78 | return "$path/$name"; | |
79 | } | |
80 | } | |
81 | return NULL; | |
82 | } |