Skip to content

Commit 2c8c76d

Browse files
Merge pull request #117 from TheDragonCode/4.x-1
Added Events tests
2 parents dce0e2c + 937e254 commit 2c8c76d

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

tests/Commands/EventsTest.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
}

0 commit comments

Comments
 (0)