diff --git a/.phpstorm.meta.php b/.phpstorm.meta.php index 23883cf97..3a02d6a2a 100644 --- a/.phpstorm.meta.php +++ b/.phpstorm.meta.php @@ -4,6 +4,8 @@ use AcquiaCloudApi\Response\AccountResponse; use AcquiaCloudApi\Response\ApplicationResponse; use AcquiaCloudApi\Response\ApplicationsResponse; + use AcquiaCloudApi\Response\CronResponse; + use AcquiaCloudApi\Response\CronsResponse; use AcquiaCloudApi\Response\DatabasesResponse; use AcquiaCloudApi\Response\EnvironmentResponse; use AcquiaCloudApi\Response\EnvironmentsResponse; @@ -14,7 +16,9 @@ 'getApplicationByUuid' => ApplicationResponse::class, 'getApplicationEnvironments' => EnvironmentsResponse::class, 'getEnvironmentsDatabases' => DatabasesResponse::class, - 'getEnvironment' => EnvironmentResponse::class + 'getEnvironment' => EnvironmentResponse::class, + 'getCron' => CronResponse::class, + 'getCronJobsByEnvironmentId' => CronsResponse::class ])); } diff --git a/src/EventListener/ExceptionListener.php b/src/EventListener/ExceptionListener.php index 9a6ffdd7d..ead38e639 100644 --- a/src/EventListener/ExceptionListener.php +++ b/src/EventListener/ExceptionListener.php @@ -79,6 +79,10 @@ public function onConsoleError(ConsoleErrorEvent $event): void { } } + if ($error instanceof \TypeError && str_contains($error->getMessage(), 'AcquiaCloudApi\Response')) { + $newErrorMessage = 'Cloud Platform API returned an unexpected data type. This is not an issue with Acquia CLI but could indicate a problem with your Cloud Platform application.'; + } + $this->helpMessages[] = "You can find Acquia CLI documentation at https://docs.acquia.com/acquia-cli/"; $this->writeUpdateHelp($event); $this->writeSupportTicketHelp($event); diff --git a/tests/phpunit/src/Application/ExceptionApplicationTest.php b/tests/phpunit/src/Application/ExceptionApplicationTest.php index c79061ef1..90c69b982 100644 --- a/tests/phpunit/src/Application/ExceptionApplicationTest.php +++ b/tests/phpunit/src/Application/ExceptionApplicationTest.php @@ -93,4 +93,21 @@ public function testInvalidApplicationUuid(): void { self::assertStringContainsString('An alias consists of an application name', $buffer); } + /** + * @group serial + */ + public function testApiTypeError(): void { + $tamper = function ($response): void { + $response[0]->server = []; + }; + $this->mockRequest('getCronJobsByEnvironmentId', '24-a47ac10b-58cc-4372-a567-0e02b2c3d470', NULL, NULL, $tamper); + $this->setInput([ + 'command' => 'env:cron-copy', + 'dest_env' => '24-a47ac10b-58cc-4372-a567-0e02b2c3d471', + 'source_env' => '24-a47ac10b-58cc-4372-a567-0e02b2c3d470', + ]); + $buffer = $this->runApp(); + self::assertStringContainsString('Cloud Platform API returned an unexpected data type.', $buffer); + } + }