protected $settingsPath;
- protected $env = array();
+ protected $env;
/**
* @var array
$this->root = $civicrm_root;
$this->settingsPath = defined('CIVICRM_SETTINGS_PATH') ? CIVICRM_SETTINGS_PATH : NULL;
$this->defaultParams = $defaultParams;
- $this->addEnv(array(
- 'CIVICRM_UF' => CIVICRM_UF,
- ));
+ $this->env = $_ENV;
}
/**
public function createProcess($apiCall) {
$parts = array();
- $executableFinder = new PhpExecutableFinder();
- $php = $executableFinder->find();
- if (!$php) {
- throw new \CRM_Core_Exception("Failed to locate PHP interpreter.");
+ if (defined('CIVICRM_TEST') && CIVICRM_TEST) {
+ // When testing, civicrm.settings.php may rely on $_CV, which is only
+ // populated/propagated if we execute through `cv`.
+ $parts[] = 'cv api';
+ $parts[] = escapeshellarg($apiCall['entity'] . '.' . $apiCall['action']);
+ $parts[] = "--out=json-strict";
+ foreach ($apiCall['params'] as $key => $value) {
+ $parts[] = escapeshellarg("$key=$value");
+ }
}
- $parts[] = $php;
-
- $parts[] = escapeshellarg($this->root . '/bin/cli.php');
- $parts[] = escapeshellarg("-e=" . $apiCall['entity']);
- $parts[] = escapeshellarg("-a=" . $apiCall['action']);
- $parts[] = "--json";
- $parts[] = escapeshellarg("-u=dummyuser");
- foreach ($apiCall['params'] as $key => $value) {
- $parts[] = escapeshellarg("--$key=$value");
+ else {
+ // But in production, we may not have `cv` installed.
+ $executableFinder = new PhpExecutableFinder();
+ $php = $executableFinder->find();
+ if (!$php) {
+ throw new \CRM_Core_Exception("Failed to locate PHP interpreter.");
+ }
+ $parts[] = $php;
+ $parts[] = escapeshellarg($this->root . '/bin/cli.php');
+ $parts[] = escapeshellarg("-e=" . $apiCall['entity']);
+ $parts[] = escapeshellarg("-a=" . $apiCall['action']);
+ $parts[] = "--json";
+ $parts[] = escapeshellarg("-u=dummyuser");
+ foreach ($apiCall['params'] as $key => $value) {
+ $parts[] = escapeshellarg("--$key=$value");
+ }
}
- $command = implode(" ", $parts);
+ $command = implode(" ", $parts);
$env = array_merge($this->env, array(
'CIVICRM_SETTINGS' => $this->settingsPath,
));
*
*/
if (!defined('CIVICRM_DSN')) {
- if (CIVICRM_UF !== 'UnitTests') {
- define('CIVICRM_DSN', 'mysql://%%dbUser%%:%%dbPass%%@%%dbHost%%/%%dbName%%?new_link=true');
+ if (CIVICRM_UF === 'UnitTests' && isset($GLOBALS['_CV']['TEST_DB_DSN'])) {
+ define('CIVICRM_DSN', $GLOBALS['_CV']['TEST_DB_DSN']);
}
else {
- define('CIVICRM_DSN', 'mysql://%%testUser%%:%%testPass%%@%%testHost%%/%%testName%%?new_link=true');
+ define('CIVICRM_DSN', 'mysql://%%dbUser%%:%%dbPass%%@%%dbHost%%/%%dbName%%?new_link=true');
}
}