File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -13,7 +13,8 @@ class ReplayCommand extends Command
13
13
protected $ signature = 'event-sourcing:replay {projector?*}
14
14
{--from=0 : Replay events starting from this event number}
15
15
{--stored-event-model= : Replay events from this store}
16
- {--aggregate-uuid= : Replay events for this aggregate only} ' ;
16
+ {--aggregate-uuid= : Replay events for this aggregate only}
17
+ {--force : Replay events without asking for confirmation} ' ;
17
18
18
19
protected $ description = 'Replay stored events ' ;
19
20
@@ -45,7 +46,7 @@ public function handle(Projectionist $projectionist): void
45
46
public function selectProjectors (array $ projectorClassNames ): ?Collection
46
47
{
47
48
if (count ($ projectorClassNames ) === 0 ) {
48
- if (! $ this ->confirm ('Are you sure you want to replay events to all projectors? ' , true )) {
49
+ if ($ this -> isRunningInteractively () && ! $ this ->confirm ('Are you sure you want to replay events to all projectors? ' , true )) {
49
50
return null ;
50
51
}
51
52
@@ -96,4 +97,9 @@ protected function emptyLine(int $amount = 1): void
96
97
$ this ->line ('' );
97
98
}
98
99
}
100
+
101
+ protected function isRunningInteractively (): bool
102
+ {
103
+ return ! $ this ->option ('force ' );
104
+ }
99
105
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace Spatie \EventSourcing \Tests \Console ;
4
4
5
+ use BadMethodCallException ;
5
6
use Illuminate \Support \Facades \Artisan ;
6
7
use Illuminate \Support \Facades \Event ;
7
8
use Illuminate \Support \Facades \Mail ;
35
36
Mail::fake ();
36
37
});
37
38
39
+ it ('will run without confirmation when given the force option ' , function () {
40
+ Projectionist::addProjector (BalanceProjector::class);
41
+
42
+ $ this ->artisan ('event-sourcing:replay ' , ['--force ' => true ])
43
+ ->expectsOutput ('Replaying 3 events... ' )
44
+ ->assertExitCode (0 );
45
+ });
46
+
47
+ it ('will not run without confirmation when not given the force option ' , function () {
48
+ $ this ->expectException (BadMethodCallException::class);
49
+
50
+ Projectionist::addProjector (BalanceProjector::class);
51
+
52
+ $ this ->artisan ('event-sourcing:replay ' );
53
+ });
54
+
55
+ it ('will not replay events when the user does not confirm ' , function () {
56
+ Projectionist::addProjector (BalanceProjector::class);
57
+
58
+ $ this ->artisan ('event-sourcing:replay ' )
59
+ ->expectsConfirmation ('Are you sure you want to replay events to all projectors? ' , 'no ' )
60
+ ->expectsOutput ('No events replayed! ' )
61
+ ->assertExitCode (0 );
62
+ });
63
+
38
64
it ('will replay events to the given projectors ' , function () {
39
65
Event::fake ([FinishedEventReplay::class, StartingEventReplay::class]);
40
66
You can’t perform that action at this time.
0 commit comments