File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace Tests \Commands ;
6+
7+ use DragonCode \LaravelActions \Constants \Names ;
8+ use DragonCode \LaravelActions \Events \ActionEnded ;
9+ use DragonCode \LaravelActions \Events \ActionFailed ;
10+ use DragonCode \LaravelActions \Events \ActionStarted ;
11+ use Exception ;
12+ use Illuminate \Support \Facades \Event ;
13+ use Tests \TestCase ;
14+ use Throwable ;
15+
16+ class EventsTest extends TestCase
17+ {
18+ public function testSuccess ()
19+ {
20+ $ this ->copyFiles ();
21+
22+ Event::fake ();
23+
24+ $ this ->artisan (Names::ACTIONS )->assertExitCode (0 );
25+
26+ Event::assertDispatchedTimes (ActionStarted::class, 1 );
27+ Event::assertDispatchedTimes (ActionEnded::class, 1 );
28+
29+ Event::assertNotDispatched (ActionFailed::class);
30+ }
31+
32+ public function testFailed ()
33+ {
34+ $ this ->expectException (Exception::class);
35+ $ this ->expectExceptionMessage ('Custom exception ' );
36+
37+ $ this ->copyFailedMethod ();
38+
39+ Event::fake ();
40+
41+ try {
42+ $ this ->artisan (Names::ACTIONS )->run ();
43+ }
44+ catch (Throwable $ e ) {
45+ Event::assertDispatchedTimes (ActionStarted::class, 1 );
46+ Event::assertDispatchedTimes (ActionFailed::class, 1 );
47+
48+ Event::assertNotDispatched (ActionEnded::class);
49+
50+ throw $ e ;
51+ }
52+ }
53+ }
You can’t perform that action at this time.
0 commit comments