Skip to content

Commit 8522464

Browse files
committed
Expect choice for failed-jobs command
1 parent 1022bbc commit 8522464

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

src/Console/Commands/FailedJobs.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@ class FailedJobs extends Command implements Isolatable, PromptsForMissingInput
1616
/**
1717
* @var string
1818
*/
19-
protected $signature = 'codebarista:failed-jobs {action : The action: retry or delete}';
19+
protected $signature = 'codebarista:failed-jobs';
2020

2121
/**
2222
* @var string
2323
*/
24-
protected $description = 'Retry or delete all failed jobs.';
24+
protected $description = 'Retry or delete failed jobs';
2525

2626
public function handle(RedisJobRepository $repository): int
2727
{
28-
return match ($this->argument('action')) {
28+
$action = $this->choice('What action should be taken?', [
29+
'delete',
30+
'retry',
31+
]);
32+
33+
return match ($action) {
2934
'delete' => $this->deleteFailedJobs($repository),
3035
'retry' => $this->retryFailedJobs($repository),
3136
default => self::INVALID,

tests/Feature/FailedJobsTest.php

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,52 @@
22

33
it('returns invalid', function () {
44
$this->artisan('codebarista:failed-jobs')
5-
->expectsQuestion('What is the action: retry or delete?', 'invalid')
5+
->expectsChoice('What action should be taken?', 'invalid', [
6+
'delete',
7+
'retry',
8+
])
69
->assertExitCode(2);
710
});
811

912
it('aborts retry failed jobs', function () {
1013
$this->artisan('codebarista:failed-jobs')
11-
->expectsQuestion('What is the action: retry or delete?', 'retry')
14+
->expectsChoice('What action should be taken?', 'retry', [
15+
'delete',
16+
'retry',
17+
])
1218
->expectsConfirmation('Really retry all failed jobs?')
1319
->expectsOutputToContain('Process terminated by user')
1420
->assertExitCode(0);
1521
});
1622

1723
it('aborts delete failed jobs', function () {
1824
$this->artisan('codebarista:failed-jobs')
19-
->expectsQuestion('What is the action: retry or delete?', 'delete')
25+
->expectsChoice('What action should be taken?', 'delete', [
26+
'delete',
27+
'retry',
28+
])
2029
->expectsConfirmation('Really delete all failed jobs?')
2130
->expectsOutputToContain('Process terminated by user')
2231
->assertExitCode(0);
2332
});
2433

2534
it('retries failed jobs', function () {
2635
$this->artisan('codebarista:failed-jobs')
27-
->expectsQuestion('What is the action: retry or delete?', 'retry')
36+
->expectsChoice('What action should be taken?', 'retry', [
37+
'delete',
38+
'retry',
39+
])
2840
->expectsConfirmation('Really retry all failed jobs?', 'yes')
2941
->expectsOutputToContain('jobs retried')
3042
->assertExitCode(0);
3143
});
3244

3345
it('deletes failed jobs', function () {
3446
$this->artisan('codebarista:failed-jobs')
35-
->expectsQuestion('What is the action: retry or delete?', 'delete')
47+
->expectsChoice('What action should be taken?', 'delete', [
48+
'delete',
49+
'retry',
50+
])
3651
->expectsConfirmation('Really delete all failed jobs?', 'yes')
3752
->expectsOutputToContain('jobs deleted')
3853
->assertExitCode(0);

0 commit comments

Comments
 (0)