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