Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danepowell committed Mar 26, 2024
1 parent 81e458a commit a046994
Showing 1 changed file with 47 additions and 6 deletions.
53 changes: 47 additions & 6 deletions tests/phpunit/src/Misc/ExceptionListenerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,31 @@
use Acquia\Cli\EventListener\ExceptionListener;
use Acquia\Cli\Exception\AcquiaCliException;
use Acquia\Cli\Tests\TestBase;
use AcquiaCloudApi\Exception\ApiErrorException;
use League\OAuth2\Client\Provider\Exception\IdentityProviderException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Event\ConsoleErrorEvent;
use Symfony\Component\Console\Exception\RuntimeException;
use Throwable;

class ExceptionListenerTest extends TestBase {
private static string $siteAliasHelp = '<bg=blue;options=bold>environmentId</> can also be a site alias. E.g. <bg=blue;fg=white;options=bold>myapp.dev</>.' . PHP_EOL . 'Run <bg=blue;options=bold>acli remote:aliases:list</> to see a list of all available aliases.';
private static string $appAliasHelp = 'The <bg=blue;options=bold>applicationUuid</> argument must be a valid UUID or unique application alias accessible to your Cloud Platform user.' . PHP_EOL . PHP_EOL . 'An alias consists of an application name optionally prefixed with a hosting realm, e.g. <bg=blue;fg=white;options=bold>myapp</> or <bg=blue;fg=white;options=bold>prod.myapp</>.' . PHP_EOL . PHP_EOL . 'Run <bg=blue;options=bold>acli remote:aliases:list</> to see a list of all available aliases.';

/**
* @dataProvider providerTestHelp
*/
public function testHelp(Throwable $error, string $helpText): void {
public function testHelp(Throwable $error, string|array $helpText): void {
$exceptionListener = new ExceptionListener();
$commandProphecy = $this->prophet->prophesize(Command::class);
$applicationProphecy = $this->prophet->prophesize(Application::class);
$messages = [$helpText, 'You can find Acquia CLI documentation at https://docs.acquia.com/acquia-cli/', 'You can submit a support ticket at https://support-acquia.force.com/s/contactsupport' . PHP_EOL . 'Re-run the command with the <bg=blue;fg=white;options=bold>-vvv</> flag and include the full command output in your support ticket.'];
$messages1 = ['You can find Acquia CLI documentation at https://docs.acquia.com/acquia-cli/', 'You can submit a support ticket at https://support-acquia.force.com/s/contactsupport' . PHP_EOL . 'Re-run the command with the <bg=blue;fg=white;options=bold>-vvv</> flag and include the full command output in your support ticket.'];
if (is_array($helpText)) {
$messages = array_merge($helpText, $messages1);
}
else {
$messages = array_merge([$helpText], $messages1);
}
$applicationProphecy->setHelpMessages($messages)->shouldBeCalled();
$commandProphecy->getApplication()->willReturn($applicationProphecy->reveal());
$consoleErrorEvent = new ConsoleErrorEvent($this->input, $this->output, $error, $commandProphecy->reveal());
Expand All @@ -43,11 +52,35 @@ public function providerTestHelp(): array {
],
[
new RuntimeException('Not enough arguments (missing: "environmentId").'),
'<bg=blue;options=bold>environmentId</> can also be a site alias. E.g. <bg=blue;fg=white;options=bold>myapp.dev</>.' . PHP_EOL . 'Run <bg=blue;options=bold>acli remote:aliases:list</> to see a list of all available aliases.',
self::$siteAliasHelp,
],
[
new RuntimeException('Not enough arguments (missing: "environmentUuid").'),
'<bg=blue;options=bold>environmentId</> can also be a site alias. E.g. <bg=blue;fg=white;options=bold>myapp.dev</>.' . PHP_EOL . 'Run <bg=blue;options=bold>acli remote:aliases:list</> to see a list of all available aliases.',
self::$siteAliasHelp,
],
[
new AcquiaCliException('No applications match the alias {applicationAlias}'),
self::$appAliasHelp,
],
[
new AcquiaCliException('Multiple applications match the alias {applicationAlias}'),
self::$appAliasHelp,
],
[
new AcquiaCliException('{environmentId} must be a valid UUID or site alias.'),
self::$siteAliasHelp,
],
[
new AcquiaCliException('{environmentUuid} must be a valid UUID or site alias.'),
self::$siteAliasHelp,
],
[
new AcquiaCliException('Access token file not found at {file}'),
'Get help for this error at https://docs.acquia.com/ide/known-issues/#the-automated-cloud-platform-api-authentication-might-fail',
],
[
new AcquiaCliException('Access token expiry file not found at {file}'),
'Get help for this error at https://docs.acquia.com/ide/known-issues/#the-automated-cloud-platform-api-authentication-might-fail',
],
[
new AcquiaCliException('This machine is not yet authenticated with the Cloud Platform.'),
Expand All @@ -58,8 +91,16 @@ public function providerTestHelp(): array {
'Run `acli auth:acsf-login` to re-authenticate with Site Factory.',
],
[
new AcquiaCliException('Access token file not found at {file}'),
'Get help for this error at https://docs.acquia.com/ide/known-issues/#the-automated-cloud-platform-api-authentication-might-fail',
new ApiErrorException((object) ['error' => '', 'message' => "There are no available Cloud IDEs for this application.\n"]),
'Delete an existing IDE via <bg=blue;fg=white;options=bold>acli ide:delete</> or contact your Account Manager or Acquia Sales to purchase additional IDEs.',
],
[
new ApiErrorException((object) ['error' => '', 'message' => 'This resource requires additional authentication.']),
['This is likely because you have Federated Authentication required for your organization.', 'Run `acli login` to authenticate via API token and then try again.'],
],
[
new ApiErrorException((object) ['error' => 'asdf', 'message' => 'fdsa']),
'You can learn more about Cloud Platform API at https://docs.acquia.com/cloud-platform/develop/api/',
],
];
}
Expand Down

0 comments on commit a046994

Please sign in to comment.