Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI-1302: [api:applications:environment-create] databases must be array #1715

Merged
merged 4 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Command/Api/ApiBaseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$acquiaCloudClient = $this->cloudApiClientService->getClient();
$this->addQueryParamsToClient($input, $acquiaCloudClient);
$this->addPostParamsToClient($input, $acquiaCloudClient);
// Acquia PHP SDK cannot set the Accept header itself because it would break
// API calls returning octet streams (e.g., db backups). It's safe to use
// here because the API command should always return JSON.
$acquiaCloudClient->addOption('headers', [
'Accept' => 'application/json',
'Accept' => 'application/hal+json, version=2',
]);

try {
Expand Down
10 changes: 3 additions & 7 deletions src/Command/Api/ApiCommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,6 @@ private function addApiCommandParameters(array $schema, array $acquiaCloudSpec,
elseif ($parameterSpecification['in'] === 'path') {
$command->addPathParameter($parameterDefinition->getName(), $parameterSpecification);
}
// @todo Remove this! It is a workaround for CLI-769.
elseif ($parameterSpecification['in'] === 'header') {
$command->addPostParameter($parameterDefinition->getName(), $parameterSpecification);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested to confirm this is no longer necessary

}
$usage .= $queryParamUsageSuffix;
$inputDefinition = array_merge($inputDefinition, $queryInputDefinition);
Expand Down Expand Up @@ -484,16 +480,16 @@ private function generateApiListCommands(array $apiCommands, string $commandPref
}

/**
* @param $requestBody
* @param array<mixed> $requestBody
* @return array<mixed>
*/
private function getRequestBodyContent(mixed $requestBody): array {
private function getRequestBodyContent(array $requestBody): array {
$content = $requestBody['content'];
$knownContentTypes = [
'application/hal+json',
'application/json',
'application/x-www-form-urlencoded',
'multipart/form-data',
'application/hal+json',
];
foreach ($knownContentTypes as $contentType) {
if (array_key_exists($contentType, $content)) {
Expand Down
4 changes: 2 additions & 2 deletions src/Command/Auth/AuthAcsfLoginCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
$this
->addOption('username', 'u', InputOption::VALUE_REQUIRED, "Your Site Factory username")
->addOption('key', 'k', InputOption::VALUE_REQUIRED, "Your Site Factory key")
->addOption('factory-url', 'f', InputOption::VALUE_REQUIRED, "Your Site Factory URL");
->addOption('factory-url', 'f', InputOption::VALUE_REQUIRED, "Your Site Factory URL (including https://)");
}

protected function execute(InputInterface $input, OutputInterface $output): int {
Expand All @@ -36,7 +36,7 @@
];
$factory = $this->promptChooseFromObjectsOrArrays($factoryChoices, 'url', 'url', 'Choose a Factory to login to');
if ($factory['url'] === 'Enter a new factory URL') {
$factoryUrl = $this->io->ask('Enter the full URL of the factory');
$factoryUrl = $this->io->ask('Enter the full URL of the factory including https://');

Check warning on line 39 in src/Command/Auth/AuthAcsfLoginCommand.php

View check run for this annotation

Codecov / codecov/patch

src/Command/Auth/AuthAcsfLoginCommand.php#L39

Added line #L39 was not covered by tests
$factory = [
'url' => $factoryUrl,
'users' => [],
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/src/Commands/Acsf/AcsfApiCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AcsfApiCommandTest extends AcsfCommandTestBase {

public function setUp(): void {
parent::setUp();
$this->clientProphecy->addOption('headers', ['Accept' => 'application/json']);
$this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2']);
putenv('ACQUIA_CLI_USE_CLOUD_API_SPEC_CACHE=1');
}

Expand Down
15 changes: 14 additions & 1 deletion tests/phpunit/src/Commands/Api/ApiCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class ApiCommandTest extends CommandTestBase {

public function setUp(): void {
parent::setUp();
$this->clientProphecy->addOption('headers', ['Accept' => 'application/json']);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary to kill an escaped mutant. We need to check that this method is called, but it isn't actually called on every test case.

putenv('ACQUIA_CLI_USE_CLOUD_API_SPEC_CACHE=1');
}

Expand Down Expand Up @@ -79,6 +78,7 @@ public function testArgumentsInteractionValidationFormat(): void {
*/
public function testApiCommandErrorResponse(): void {
$invalidUuid = '257a5440-22c3-49d1-894d-29497a1cf3b9';
$this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled();
$this->command = $this->getApiCommandByName('api:applications:find');
$mockBody = $this->getMockResponseFromSpec($this->command->getPath(), $this->command->getMethod(), '404');
$this->clientProphecy->request('get', '/applications/' . $invalidUuid)->willThrow(new ApiErrorException($mockBody))->shouldBeCalled();
Expand All @@ -104,6 +104,7 @@ public function testApiCommandErrorResponse(): void {
}

public function testApiCommandExecutionForHttpGet(): void {
$this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled();
$mockBody = $this->getMockResponseFromSpec('/account/ssh-keys', 'get', '200');
$this->clientProphecy->addQuery('limit', '1')->shouldBeCalled();
$this->clientProphecy->request('get', '/account/ssh-keys')->willReturn($mockBody->{'_embedded'}->items)->shouldBeCalled();
Expand Down Expand Up @@ -136,6 +137,7 @@ public function testObjectParam(): void {
}

public function testInferApplicationUuidArgument(): void {
$this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled();
$applications = $this->mockRequest('getApplications');
$application = $this->mockRequest('getApplicationByUuid', $applications[0]->uuid);
$this->command = $this->getApiCommandByName('api:applications:find');
Expand Down Expand Up @@ -171,6 +173,7 @@ public function providerTestConvertApplicationAliasToUuidArgument(): array {
*/
public function testConvertApplicationAliasToUuidArgument(bool $support): void {
ClearCacheCommand::clearCaches();
$this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled();
$tamper = function (&$response): void {
unset($response[1]);
};
Expand Down Expand Up @@ -232,7 +235,11 @@ public function testConvertNonUniqueApplicationAliasToUuidArgument(): void {

}

/**
* @serial
*/
public function testConvertApplicationAliasWithRealmToUuidArgument(): void {
$this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled();
$this->mockApplicationsRequest(1, FALSE);
$this->clientProphecy->addQuery('filter', 'hosting=@devcloud:devcloud2')->shouldBeCalled();
$this->mockApplicationRequest();
Expand All @@ -248,6 +255,7 @@ public function testConvertApplicationAliasWithRealmToUuidArgument(): void {
*/
public function testConvertEnvironmentAliasToUuidArgument(): void {
ClearCacheCommand::clearCaches();
$this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled();
$applicationsResponse = $this->mockApplicationsRequest(1);
$this->clientProphecy->addQuery('filter', 'hosting=@*:devcloud2')->shouldBeCalled();
$this->mockEnvironmentsRequest($applicationsResponse);
Expand Down Expand Up @@ -291,6 +299,7 @@ public function testConvertInvalidEnvironmentAliasToUuidArgument(): void {
}

public function testApiCommandExecutionForHttpPost(): void {
$this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled();
$mockRequestArgs = $this->getMockRequestBodyFromSpec('/account/ssh-keys');
$mockResponseBody = $this->getMockResponseFromSpec('/account/ssh-keys', 'post', '202');
foreach ($mockRequestArgs as $name => $value) {
Expand All @@ -308,6 +317,7 @@ public function testApiCommandExecutionForHttpPost(): void {
}

public function testApiCommandExecutionForHttpPut(): void {
$this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled();
$mockRequestOptions = $this->getMockRequestBodyFromSpec('/environments/{environmentId}', 'put');
$mockRequestOptions['max_input_vars'] = 1001;
$mockResponseBody = $this->getMockEnvironmentResponse('put', '202');
Expand Down Expand Up @@ -416,6 +426,7 @@ public function testApiCommandDefinitionRequestBody(string $commandName, string
}

public function testGetApplicationUuidFromBltYml(): void {
$this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled();
$mockBody = $this->getMockResponseFromSpec('/applications/{applicationUuid}', 'get', '200');
$this->clientProphecy->request('get', '/applications/' . $mockBody->uuid)->willReturn($mockBody)->shouldBeCalled();
$this->command = $this->getApiCommandByName('api:applications:find');
Expand All @@ -431,6 +442,7 @@ public function testOrganizationMemberDeleteByUserUuid(): void {
$orgId = 'bfafd31a-83a6-4257-b0ec-afdeff83117a';
$memberUuid = '26c4af83-545b-45cb-b165-d537adc9e0b4';

$this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled();
$this->mockRequest('postOrganizationMemberDelete', [$orgId, $memberUuid], NULL, 'Member removed');

$this->command = $this->getApiCommandByName('api:organizations:member-delete');
Expand All @@ -450,6 +462,7 @@ public function testOrganizationMemberDeleteByUserUuid(): void {
* Test of deletion of the user from organization by user email.
*/
public function testOrganizationMemberDeleteByUserEmail(): void {
$this->clientProphecy->addOption('headers', ['Accept' => 'application/hal+json, version=2'])->shouldBeCalled();
$membersResponse = $this->getMockResponseFromSpec('/organizations/{organizationUuid}/members', 'get', 200);
$orgId = 'bfafd31a-83a6-4257-b0ec-afdeff83117a';
$memberMail = $membersResponse->_embedded->items[0]->mail;
Expand Down