Removed method isTestingOnOcisOrReva, and refactored its use
This commit is contained in:
@@ -789,54 +789,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
|
||||
?string $adminPassword = null,
|
||||
?string $baseUrl = null
|
||||
):array {
|
||||
if (OcisHelper::isTestingOnOcisOrReva()) {
|
||||
return [];
|
||||
}
|
||||
$baseUrl = self::checkBaseUrl($baseUrl, "runOcc");
|
||||
$adminUsername = self::checkAdminUsername($adminUsername, "runOcc");
|
||||
$adminPassword = self::checkAdminPassword($adminPassword, "runOcc");
|
||||
|
||||
if (!\is_array($commands)) {
|
||||
throw new Exception("commands must be an array");
|
||||
}
|
||||
|
||||
$isTestingAppEnabledText = "Is the testing app installed and enabled?\n";
|
||||
$bodies = [];
|
||||
|
||||
foreach ($commands as $occ) {
|
||||
if (!\array_key_exists('command', $occ)) {
|
||||
throw new \InvalidArgumentException("command key is missing in array passed to runBulkOcc");
|
||||
}
|
||||
|
||||
$body = [
|
||||
'command' => \implode(' ', $occ['command'])
|
||||
];
|
||||
|
||||
if (isset($occ['envVariables'])) {
|
||||
$body['env_variables'] = $occ['envVariables'];
|
||||
}
|
||||
\array_push($bodies, $body);
|
||||
}
|
||||
try {
|
||||
$result = OcsApiHelper::sendRequest(
|
||||
$baseUrl,
|
||||
$adminUsername,
|
||||
$adminPassword,
|
||||
"POST",
|
||||
"/apps/testing/api/v1/occ/bulk?format=json",
|
||||
$xRequestId,
|
||||
\json_encode($bodies)
|
||||
);
|
||||
} catch (ServerException $e) {
|
||||
throw new Exception(
|
||||
"Could not execute 'occ'. " .
|
||||
$isTestingAppEnabledText .
|
||||
$e->getResponse()->getBody()
|
||||
);
|
||||
}
|
||||
$result = \json_decode($result->getBody()->getContents());
|
||||
|
||||
return $result->ocs->data;
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -864,129 +817,7 @@ class SetupHelper extends \PHPUnit\Framework\Assert {
|
||||
?string $ocPath = null,
|
||||
?array $envVariables = null
|
||||
):array {
|
||||
if (OcisHelper::isTestingOnOcisOrReva() && !OcisHelper::isTestingParallelDeployment()) {
|
||||
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
|
||||
}
|
||||
$baseUrl = self::checkBaseUrl($baseUrl, "runOcc");
|
||||
$adminUsername = self::checkAdminUsername($adminUsername, "runOcc");
|
||||
$adminPassword = self::checkAdminPassword($adminPassword, "runOcc");
|
||||
if (self::$ocPath === null
|
||||
&& $ocPath === null
|
||||
) {
|
||||
throw new Exception(
|
||||
"runOcc called without ocPath - pass the ocPath or call SetupHelper::init"
|
||||
);
|
||||
}
|
||||
if ($ocPath === null) {
|
||||
$ocPath = self::$ocPath;
|
||||
} else {
|
||||
$ocPath = self::normaliseOcPath($ocPath);
|
||||
}
|
||||
|
||||
$body = [];
|
||||
$argsString = \implode(' ', $args);
|
||||
$body['command'] = $argsString;
|
||||
|
||||
if ($envVariables !== null) {
|
||||
$body['env_variables'] = $envVariables;
|
||||
}
|
||||
|
||||
$isTestingAppEnabledText = "Is the testing app installed and enabled?\n";
|
||||
|
||||
try {
|
||||
$result = OcsApiHelper::sendRequest(
|
||||
$baseUrl,
|
||||
$adminUsername,
|
||||
$adminPassword,
|
||||
"POST",
|
||||
$ocPath,
|
||||
$xRequestId,
|
||||
$body
|
||||
);
|
||||
} catch (ServerException $e) {
|
||||
throw new Exception(
|
||||
"Could not execute 'occ'. " .
|
||||
$isTestingAppEnabledText .
|
||||
$e->getResponse()->getBody()
|
||||
);
|
||||
}
|
||||
|
||||
$return = [];
|
||||
$contents = $result->getBody()->getContents();
|
||||
$resultXml = \simplexml_load_string($contents);
|
||||
|
||||
if ($resultXml === false) {
|
||||
$status = $result->getStatusCode();
|
||||
throw new Exception(
|
||||
"Response is not valid XML after executing 'occ $argsString'. " .
|
||||
"HTTP status was $status. " .
|
||||
$isTestingAppEnabledText .
|
||||
"Response contents were '$contents'"
|
||||
);
|
||||
}
|
||||
|
||||
$return['code'] = $resultXml->xpath("//ocs/data/code");
|
||||
$return['stdOut'] = $resultXml->xpath("//ocs/data/stdOut");
|
||||
$return['stdErr'] = $resultXml->xpath("//ocs/data/stdErr");
|
||||
|
||||
if (!isset($return['code'][0])) {
|
||||
throw new Exception(
|
||||
"Return code not found after executing 'occ $argsString'. " .
|
||||
$isTestingAppEnabledText .
|
||||
$contents
|
||||
);
|
||||
}
|
||||
|
||||
if (!isset($return['stdOut'][0])) {
|
||||
throw new Exception(
|
||||
"Return stdOut not found after executing 'occ $argsString'. " .
|
||||
$isTestingAppEnabledText .
|
||||
$contents
|
||||
);
|
||||
}
|
||||
|
||||
if (!isset($return['stdErr'][0])) {
|
||||
throw new Exception(
|
||||
"Return stdErr not found after executing 'occ $argsString'. " .
|
||||
$isTestingAppEnabledText .
|
||||
$contents
|
||||
);
|
||||
}
|
||||
|
||||
if (!\is_a($return['code'][0], "SimpleXMLElement")) {
|
||||
throw new Exception(
|
||||
"Return code is not a SimpleXMLElement after executing 'occ $argsString'. " .
|
||||
$isTestingAppEnabledText .
|
||||
$contents
|
||||
);
|
||||
}
|
||||
|
||||
if (!\is_a($return['stdOut'][0], "SimpleXMLElement")) {
|
||||
throw new Exception(
|
||||
"Return stdOut is not a SimpleXMLElement after executing 'occ $argsString'. " .
|
||||
$isTestingAppEnabledText .
|
||||
$contents
|
||||
);
|
||||
}
|
||||
|
||||
if (!\is_a($return['stdErr'][0], "SimpleXMLElement")) {
|
||||
throw new Exception(
|
||||
"Return stdErr is not a SimpleXMLElement after executing 'occ $argsString'. " .
|
||||
$isTestingAppEnabledText .
|
||||
$contents
|
||||
);
|
||||
}
|
||||
|
||||
$return['code'] = $return['code'][0]->__toString();
|
||||
$return['stdOut'] = $return['stdOut'][0]->__toString();
|
||||
$return['stdErr'] = $return['stdErr'][0]->__toString();
|
||||
self::resetOpcache(
|
||||
$baseUrl,
|
||||
$adminUsername,
|
||||
$adminPassword,
|
||||
$xRequestId
|
||||
);
|
||||
return $return;
|
||||
return ['code' => '', 'stdOut' => '', 'stdErr' => '' ];
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user