Skip to content

Commit feaf4f9

Browse files
committed
wip
1 parent f5f732d commit feaf4f9

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/Tempest/CommandBus/src/HandleAsyncCommand.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
use Tempest\Console\ExitCode;
1010
use Tempest\Console\HasConsole;
1111
use Tempest\Container\Container;
12-
use Throwable;
1312
use function Tempest\Support\arr;
13+
use Throwable;
1414

1515
final readonly class HandleAsyncCommand
1616
{
@@ -21,7 +21,8 @@ public function __construct(
2121
private Container $container,
2222
private Console $console,
2323
private CommandRepository $repository,
24-
) {}
24+
) {
25+
}
2526

2627
#[ConsoleCommand(name: 'command:handle')]
2728
public function __invoke(?string $uuid = null): ExitCode
@@ -35,6 +36,7 @@ public function __invoke(?string $uuid = null): ExitCode
3536

3637
if (! $command) {
3738
$this->error('No pending command found');
39+
3840
return ExitCode::ERROR;
3941
}
4042

@@ -43,6 +45,7 @@ public function __invoke(?string $uuid = null): ExitCode
4345
if (! $commandHandler) {
4446
$commandClass = $command::class;
4547
$this->error("No handler found for command {$commandClass}");
48+
4649
return ExitCode::ERROR;
4750
}
4851

@@ -53,10 +56,12 @@ public function __invoke(?string $uuid = null): ExitCode
5356

5457
$this->repository->markAsDone($uuid);
5558
$this->success('Done');
59+
5660
return ExitCode::SUCCESS;
5761
} catch (Throwable $throwable) {
5862
$this->repository->markAsFailed($uuid);
5963
$this->error($throwable->getMessage());
64+
6065
return ExitCode::ERROR;
6166
}
6267
}

tests/Integration/CommandBus/AsyncCommandTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
use Tempest\CommandBus\AsyncCommandRepositories\MemoryRepository;
1010
use Tempest\CommandBus\CommandRepository;
1111
use Tempest\Highlight\Themes\TerminalStyle;
12+
use function Tempest\Support\arr;
1213
use Tests\Tempest\Fixtures\Handlers\MyAsyncCommandHandler;
1314
use Tests\Tempest\Integration\CommandBus\Fixtures\MyAsyncCommand;
1415
use Tests\Tempest\Integration\FrameworkIntegrationTestCase;
15-
use function Tempest\Support\arr;
1616

1717
/**
1818
* @internal
@@ -25,7 +25,7 @@ public function test_async_commands_are_stored_and_handled_afterwards(): void
2525

2626
$this->container->singleton(
2727
CommandRepository::class,
28-
fn () => $repository
28+
fn () => $repository,
2929
);
3030

3131
MyAsyncCommandHandler::$isHandled = false;
@@ -78,6 +78,11 @@ public function test_async_failed_command_monitor(): void
7878
$this->assertStringContainsString('failed at', $output);
7979
$this->assertStringContainsString('Failed command', $output);
8080
$process->stop();
81+
82+
arr(glob(__DIR__ . '/../../../src/Tempest/CommandBus/src/stored-commands/*.failed.txt'))
83+
->each(function (string $filename): void {
84+
unlink($filename);
85+
});
8186
}
8287

8388
private function getOutput(Process $process): string

0 commit comments

Comments
 (0)