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-1292: Catch Cloud API type errors #1701

Merged
merged 3 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 5 additions & 1 deletion .phpstorm.meta.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
]));

}
4 changes: 4 additions & 0 deletions src/EventListener/ExceptionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@
}
}

if ($error instanceof \TypeError && str_contains($error->getMessage(), 'AcquiaCloudApi\Response')) {

Check warning on line 82 in src/EventListener/ExceptionListener.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "InstanceOf_": --- Original +++ New @@ @@ $this->helpMessages[] = "You can learn more about Cloud Platform API at https://docs.acquia.com/cloud-platform/develop/api/"; } } - if ($error instanceof \TypeError && str_contains($error->getMessage(), 'AcquiaCloudApi\\Response')) { + if (false && 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/";

Check warning on line 82 in src/EventListener/ExceptionListener.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "InstanceOf_": --- Original +++ New @@ @@ $this->helpMessages[] = "You can learn more about Cloud Platform API at https://docs.acquia.com/cloud-platform/develop/api/"; } } - if ($error instanceof \TypeError && str_contains($error->getMessage(), 'AcquiaCloudApi\\Response')) { + if (true && 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/";

Check warning on line 82 in src/EventListener/ExceptionListener.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "LogicalAnd": --- Original +++ New @@ @@ $this->helpMessages[] = "You can learn more about Cloud Platform API at https://docs.acquia.com/cloud-platform/develop/api/"; } } - if ($error instanceof \TypeError && str_contains($error->getMessage(), 'AcquiaCloudApi\\Response')) { + 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/";

Check warning on line 82 in src/EventListener/ExceptionListener.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "LogicalAndAllSubExprNegation": --- Original +++ New @@ @@ $this->helpMessages[] = "You can learn more about Cloud Platform API at https://docs.acquia.com/cloud-platform/develop/api/"; } } - if ($error instanceof \TypeError && str_contains($error->getMessage(), 'AcquiaCloudApi\\Response')) { + 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/";

Check warning on line 82 in src/EventListener/ExceptionListener.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "LogicalAndNegation": --- Original +++ New @@ @@ $this->helpMessages[] = "You can learn more about Cloud Platform API at https://docs.acquia.com/cloud-platform/develop/api/"; } } - if ($error instanceof \TypeError && str_contains($error->getMessage(), 'AcquiaCloudApi\\Response')) { + 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/";

Check warning on line 82 in src/EventListener/ExceptionListener.php

View workflow job for this annotation

GitHub Actions / Mutation Testing

Escaped Mutant for Mutator "LogicalAndSingleSubExprNegation": --- Original +++ New @@ @@ $this->helpMessages[] = "You can learn more about Cloud Platform API at https://docs.acquia.com/cloud-platform/develop/api/"; } } - if ($error instanceof \TypeError && str_contains($error->getMessage(), 'AcquiaCloudApi\\Response')) { + 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/";
danepowell marked this conversation as resolved.
Show resolved Hide resolved
$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);
Expand Down
17 changes: 17 additions & 0 deletions tests/phpunit/src/Application/ExceptionApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}