diff --git a/src/Tempest/CommandBus/src/HandleAsyncCommand.php b/src/Tempest/CommandBus/src/HandleAsyncCommand.php index 90b9e7630..79ede0702 100644 --- a/src/Tempest/CommandBus/src/HandleAsyncCommand.php +++ b/src/Tempest/CommandBus/src/HandleAsyncCommand.php @@ -9,8 +9,8 @@ use Tempest\Console\ExitCode; use Tempest\Console\HasConsole; use Tempest\Container\Container; -use Throwable; use function Tempest\Support\arr; +use Throwable; final readonly class HandleAsyncCommand { @@ -21,7 +21,8 @@ public function __construct( private Container $container, private Console $console, private CommandRepository $repository, - ) {} + ) { + } #[ConsoleCommand(name: 'command:handle')] public function __invoke(?string $uuid = null): ExitCode @@ -35,6 +36,7 @@ public function __invoke(?string $uuid = null): ExitCode if (! $command) { $this->error('No pending command found'); + return ExitCode::ERROR; } @@ -43,6 +45,7 @@ public function __invoke(?string $uuid = null): ExitCode if (! $commandHandler) { $commandClass = $command::class; $this->error("No handler found for command {$commandClass}"); + return ExitCode::ERROR; } @@ -53,10 +56,12 @@ public function __invoke(?string $uuid = null): ExitCode $this->repository->markAsDone($uuid); $this->success('Done'); + return ExitCode::SUCCESS; } catch (Throwable $throwable) { $this->repository->markAsFailed($uuid); $this->error($throwable->getMessage()); + return ExitCode::ERROR; } } diff --git a/tests/Integration/CommandBus/AsyncCommandTest.php b/tests/Integration/CommandBus/AsyncCommandTest.php index 73ad6fa5e..da40850de 100644 --- a/tests/Integration/CommandBus/AsyncCommandTest.php +++ b/tests/Integration/CommandBus/AsyncCommandTest.php @@ -9,10 +9,10 @@ use Tempest\CommandBus\AsyncCommandRepositories\MemoryRepository; use Tempest\CommandBus\CommandRepository; use Tempest\Highlight\Themes\TerminalStyle; +use function Tempest\Support\arr; use Tests\Tempest\Fixtures\Handlers\MyAsyncCommandHandler; use Tests\Tempest\Integration\CommandBus\Fixtures\MyAsyncCommand; use Tests\Tempest\Integration\FrameworkIntegrationTestCase; -use function Tempest\Support\arr; /** * @internal @@ -25,7 +25,7 @@ public function test_async_commands_are_stored_and_handled_afterwards(): void $this->container->singleton( CommandRepository::class, - fn () => $repository + fn () => $repository, ); MyAsyncCommandHandler::$isHandled = false; @@ -78,6 +78,11 @@ public function test_async_failed_command_monitor(): void $this->assertStringContainsString('failed at', $output); $this->assertStringContainsString('Failed command', $output); $process->stop(); + + arr(glob(__DIR__ . '/../../../src/Tempest/CommandBus/src/stored-commands/*.failed.txt')) + ->each(function (string $filename): void { + unlink($filename); + }); } private function getOutput(Process $process): string