diff --git a/src/Command/App/TaskWaitCommand.php b/src/Command/App/TaskWaitCommand.php index 339ae25ed..73fabd872 100644 --- a/src/Command/App/TaskWaitCommand.php +++ b/src/Command/App/TaskWaitCommand.php @@ -28,8 +28,13 @@ protected function configure(): void { protected function execute(InputInterface $input, OutputInterface $output): int { $notificationUuid = $this->getNotificationUuid($input); - $this->waitForNotificationToComplete($this->cloudApiClientService->getClient(), $notificationUuid, "Waiting for task $notificationUuid to complete"); - return Command::SUCCESS; + $success = $this->waitForNotificationToComplete($this->cloudApiClientService->getClient(), $notificationUuid, "Waiting for task $notificationUuid to complete"); + if ($success) { + return Command::SUCCESS; + } + else { + return Command::FAILURE; + } } private function getNotificationUuid(InputInterface $input): string { diff --git a/src/Command/CommandBase.php b/src/Command/CommandBase.php index d0e03b6a9..b34f4ef4c 100644 --- a/src/Command/CommandBase.php +++ b/src/Command/CommandBase.php @@ -1438,7 +1438,7 @@ protected function checkAuthentication(): void { } } - protected function waitForNotificationToComplete(Client $acquiaCloudClient, string $uuid, string $message, callable $success = NULL): void { + protected function waitForNotificationToComplete(Client $acquiaCloudClient, string $uuid, string $message, callable $success = NULL): bool { $notificationsResource = new Notifications($acquiaCloudClient); $notification = NULL; $checkNotificationStatus = static function () use ($notificationsResource, &$notification, $uuid): bool { @@ -1451,6 +1451,7 @@ protected function waitForNotificationToComplete(Client $acquiaCloudClient, stri }; } LoopHelper::getLoopy($this->output, $this->io, $this->logger, $message, $checkNotificationStatus, $success); + return $notification->status === 'completed'; } private function writeCompletedMessage(NotificationResponse $notification): void { diff --git a/tests/phpunit/src/Commands/App/TaskWaitCommandTest.php b/tests/phpunit/src/Commands/App/TaskWaitCommandTest.php index c286dd9e6..a47a3d40f 100644 --- a/tests/phpunit/src/Commands/App/TaskWaitCommandTest.php +++ b/tests/phpunit/src/Commands/App/TaskWaitCommandTest.php @@ -21,7 +21,7 @@ protected function createCommand(): Command { /** * @dataProvider providerTestTaskWaitCommand */ - public function testTaskWaitCommand(string $status, string $message): void { + public function testTaskWaitCommand(string $status, string $message, int $statusCode): void { $notificationUuid = '94835c3e-b112-4660-a14d-d541906c205b'; $this->mockNotificationResponse($notificationUuid, $status); $this->executeCommand([ @@ -36,6 +36,7 @@ public function testTaskWaitCommand(string $status, string $message): void { $this->assertStringContainsString('Completed: Mon Jul 29 20:47:13 UTC 2019', $output); $this->assertStringContainsString('Task type: Application added to recents list', $output); $this->assertStringContainsString('Duration: 0 seconds', $output); + $this->assertEquals($statusCode, $this->getStatusCode()); } /** @@ -46,10 +47,12 @@ public function providerTestTaskWaitCommand(): array { [ 'completed', ' [OK] The task with notification uuid 1bd3487e-71d1-4fca-a2d9-5f969b3d35c1 completed', + Command::SUCCESS, ], [ 'failed', ' [ERROR] The task with notification uuid 1bd3487e-71d1-4fca-a2d9-5f969b3d35c1 failed', + Command::FAILURE, ], ]; }