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