3 ini_set('memory_limit', '2G');
4 ini_set('safe_mode', 0);
5 define('CIVICRM_TEST', 1);
7 eval(cv('php:boot --level=classloader', 'phpcode'));
9 // Allow autoloading of PHPUnit helper classes in this extension.
10 $loader = new \Composer\Autoload\
ClassLoader();
11 $loader->add('CRM_', __DIR__
);
12 $loader->add('Civi\\', __DIR__
);
13 $loader->add('api_', __DIR__
);
14 $loader->add('api\\', __DIR__
);
18 * Call the "cv" command.
21 * The rest of the command to send.
22 * @param string $decode
23 * Ex: 'json' or 'phpcode'.
25 * Response output (if the command executed normally).
26 * @throws \RuntimeException
27 * If the command terminates abnormally.
29 function cv($cmd, $decode = 'json') {
31 $descriptorSpec = array(0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => STDERR
);
32 $oldOutput = getenv('CV_OUTPUT');
33 putenv("CV_OUTPUT=json");
35 // Execute `cv` in the original folder. This is a work-around for
36 // phpunit/codeception, which seem to manipulate PWD.
37 $cmd = sprintf('cd %s; %s', escapeshellarg(getenv('PWD')), $cmd);
39 $process = proc_open($cmd, $descriptorSpec, $pipes, __DIR__
);
40 putenv("CV_OUTPUT=$oldOutput");
42 $result = stream_get_contents($pipes[1]);
44 if (proc_close($process) !== 0) {
45 throw new RuntimeException("Command failed ($cmd):\n$result");
52 // If the last output is /*PHPCODE*/, then we managed to complete execution.
53 if (substr(trim($result), 0, 12) !== "/*BEGINPHP*/" ||
substr(trim($result), -10) !== "/*ENDPHP*/") {
54 throw new \
RuntimeException("Command failed ($cmd):\n$result");
59 return json_decode($result, 1);
62 throw new RuntimeException("Bad decoder format ($decode)");