diff --git a/src/Command/Acsf/AcsfApiBaseCommand.php b/src/Command/Acsf/AcsfApiBaseCommand.php index 8cecd30af..ead3b12a4 100644 --- a/src/Command/Acsf/AcsfApiBaseCommand.php +++ b/src/Command/Acsf/AcsfApiBaseCommand.php @@ -8,7 +8,6 @@ use Acquia\Cli\Command\Api\ApiBaseCommand; use Acquia\Cli\Exception\AcquiaCliException; use Symfony\Component\Console\Attribute\AsCommand; -use Symfony\Component\Console\Input\InputInterface; #[AsCommand(name: 'acsf:base')] class AcsfApiBaseCommand extends ApiBaseCommand { @@ -19,23 +18,4 @@ protected function checkAuthentication(): void { } } - /** - * @todo Remove this method when CLI-791 is resolved. - */ - protected function getRequestPath(InputInterface $input): string { - $path = $this->path; - - $arguments = $input->getArguments(); - // The command itself is the first argument. Remove it. - array_shift($arguments); - foreach ($arguments as $key => $value) { - $token = '%' . $key; - if (str_contains($path, $token)) { - return str_replace($token, $value, $path); - } - } - - return parent::getRequestPath($input); - } - } diff --git a/src/Command/Api/ApiBaseCommand.php b/src/Command/Api/ApiBaseCommand.php index b1c96921d..bb2b8cb5b 100644 --- a/src/Command/Api/ApiBaseCommand.php +++ b/src/Command/Api/ApiBaseCommand.php @@ -150,11 +150,11 @@ public function getMethod(): string { return $this->method; } - public function addPostParameter(mixed $paramName, mixed $value): void { + public function addPostParameter(string $paramName, mixed $value): void { $this->postParams[$paramName] = $value; } - public function addQueryParameter(mixed $paramName, mixed $value): void { + public function addQueryParameter(string $paramName, mixed $value): void { $this->queryParams[$paramName] = $value; } @@ -177,7 +177,7 @@ private function getParamFromInput(InputInterface $input, string $paramName): ar return NULL; } - private function castParamType(array $paramSpec, array|string|bool|int $value): array|bool|int|string { + private function castParamType(array $paramSpec, array|string|bool|int $value): array|bool|int|string|object { $oneOf = $this->getParamTypeOneOf($paramSpec); if (isset($oneOf)) { $types = []; @@ -187,8 +187,7 @@ private function castParamType(array $paramSpec, array|string|bool|int $value): } $types[] = $type['type']; } - if ((in_array('integer', $types, TRUE) || in_array('int', $types, TRUE)) - && ctype_digit($value)) { + if (in_array('integer', $types, TRUE) && ctype_digit($value)) { return $this->doCastParamType('integer', $value); } } @@ -208,13 +207,13 @@ private function castParamType(array $paramSpec, array|string|bool|int $value): return $this->doCastParamType($type, $value); } - private function doCastParamType(string $type, mixed $value): array|bool|int|string { + private function doCastParamType(string $type, mixed $value): array|bool|int|string|object { return match ($type) { - 'int', 'integer' => (int) $value, - 'bool', 'boolean' => $this->castBool($value), + 'integer' => (int) $value, + 'boolean' => $this->castBool($value), 'array' => is_string($value) ? explode(',', $value) : (array) $value, 'string' => (string) $value, - 'mixed' => $value, + 'object' => json_decode($value, FALSE, 512, JSON_THROW_ON_ERROR), }; } @@ -401,7 +400,7 @@ private function getParamTypeOneOf(array $paramSpec): ?array { return $oneOf; } - private function castParamToArray(mixed $paramSpec, array|string $originalValue): string|array|bool|int { + private function castParamToArray(array $paramSpec, array|string $originalValue): string|array|bool|int { if (array_key_exists('items', $paramSpec) && array_key_exists('type', $paramSpec['items'])) { if (!is_array($originalValue)) { $originalValue = $this->doCastParamType('array', $originalValue); diff --git a/tests/phpunit/src/Commands/Api/ApiCommandTest.php b/tests/phpunit/src/Commands/Api/ApiCommandTest.php index 1ede2c9e3..dcbc32729 100644 --- a/tests/phpunit/src/Commands/Api/ApiCommandTest.php +++ b/tests/phpunit/src/Commands/Api/ApiCommandTest.php @@ -52,22 +52,20 @@ public function testArgumentsInteractionValidation(): void { 'AH_SOMETHING', ]); } - catch (MissingInputException $exception) { - + catch (MissingInputException) { } $output = $this->getDisplay(); $this->assertStringContainsString('It must match the pattern', $output); } - public function testArgumentsInteractionValdationFormat(): void { + public function testArgumentsInteractionValidationFormat(): void { $this->command = $this->getApiCommandByName('api:notifications:find'); try { $this->executeCommand([], [ 'test', ]); } - catch (MissingInputException $exception) { - + catch (MissingInputException) { } $output = $this->getDisplay(); $this->assertStringContainsString('This is not a valid UUID', $output); @@ -122,10 +120,20 @@ public function testApiCommandExecutionForHttpGet(): void { $this->assertArrayHasKey('uuid', $contents[0]); } + public function testObjectParam(): void { + $this->mockRequest('putEnvironmentCloudActions', '24-a47ac10b-58cc-4372-a567-0e02b2c3d470'); + $this->command = $this->getApiCommandByName('api:environments:cloud-actions-update'); + $this->executeCommand([ + 'cloud-actions' => '{"fb4aa87a-8be2-42c6-bdf0-ef9d09a3de70":true}', + 'environmentId' => '24-a47ac10b-58cc-4372-a567-0e02b2c3d470', + ]); + $output = $this->getDisplay(); + $this->assertStringContainsString('Cloud Actions have been updated.', $output); + } + public function testInferApplicationUuidArgument(): void { - $mockBody = $this->getMockResponseFromSpec('/applications/{applicationUuid}', 'get', '200'); - $this->clientProphecy->request('get', '/applications')->willReturn([$mockBody])->shouldBeCalled(); - $this->clientProphecy->request('get', '/applications/' . $mockBody->uuid)->willReturn($mockBody)->shouldBeCalled(); + $applications = $this->mockRequest('getApplications'); + $application = $this->mockRequest('getApplicationByUuid', $applications[0]->uuid); $this->command = $this->getApiCommandByName('api:applications:find'); $this->executeCommand([], [ // Would you like Acquia CLI to search for a Cloud application that matches your local git config? @@ -140,7 +148,7 @@ public function testInferApplicationUuidArgument(): void { $this->prophet->checkPredictions(); $output = $this->getDisplay(); $this->assertStringContainsString('Inferring Cloud Application UUID for this command since none was provided...', $output); - $this->assertStringContainsString('Set application uuid to ' . $mockBody->uuid, $output); + $this->assertStringContainsString('Set application uuid to ' . $application->uuid, $output); $this->assertEquals(0, $this->getStatusCode()); } @@ -398,7 +406,7 @@ public function providerTestApiCommandDefinitionRequestBody(): array { * @param $method * @param $usage */ - public function testApiCommandDefinitionRequestBody(mixed $commandName, mixed $method, mixed $usage): void { + public function testApiCommandDefinitionRequestBody(string $commandName, string $method, string $usage): void { $this->command = $this->getApiCommandByName($commandName); $resource = $this->getResourceFromSpec($this->command->getPath(), $method); foreach ($resource['requestBody']['content']['application/json']['example'] as $propKey => $value) {