-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: Add test for worker dispatcher
- Loading branch information
1 parent
5bc3d0e
commit 7ce435b
Showing
3 changed files
with
93 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace DigitalRisks\LaravelEventStore\Tests\Fixtures; | ||
|
||
use Rxnet\EventStore\Record\EventRecord; | ||
|
||
class TestEvent | ||
{ | ||
public $event; | ||
|
||
public function __construct(EventRecord $event) | ||
{ | ||
$this->event = $event; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
namespace DigitalRisks\LaravelEventStore\Tests; | ||
|
||
use DigitalRisks\LaravelEventStore\ShouldBeEventStored; | ||
use DigitalRisks\LaravelEventStore\Tests\Traits\InteractsWithEventStore; | ||
use DigitalRisks\LaravelEventStore\SendsToEventStore; | ||
use DigitalRisks\LaravelEventStore\Tests\Traits\MakesEventRecords; | ||
use DigitalRisks\LaravelEventStore\EventStoreWorker; | ||
use Illuminate\Support\Facades\Event; | ||
use Rxnet\EventStore\Record\EventRecord; | ||
use DigitalRisks\LaravelEventStore\Tests\Fixtures\TestEvent; | ||
|
||
class WorkerTest extends TestCase | ||
{ | ||
use InteractsWithEventStore, MakesEventRecords; | ||
|
||
/** @test */ | ||
public function it_dispatches_an_event_from_a_subscribed_event() | ||
{ | ||
// Arrange. | ||
Event::fake(); | ||
$worker = resolve(EventStoreWorker::class); | ||
$event = $this->makeEventRecord('event_with_no_class', ['hello' => 'world']); | ||
|
||
// Act. | ||
$worker->dispatch($event); | ||
|
||
// Assert. | ||
Event::assertDispatched('event_with_no_class', function ($type, EventRecord $event) { | ||
$this->assertEquals(['hello' => 'world'], $event->getData()); | ||
|
||
return true; | ||
}); | ||
} | ||
|
||
/** @test */ | ||
public function it_dispatches_a_classed_event_from_a_subscribed_event() | ||
{ | ||
// Arrange. | ||
Event::fake(); | ||
$worker = resolve(EventStoreWorker::class); | ||
$event = $this->makeEventRecord('TestEvent', ['hello' => 'world']); | ||
config(['eventstore.namespace' => 'DigitalRisks\LaravelEventStore\Tests\Fixtures']); | ||
|
||
// Act. | ||
$worker->dispatch($event); | ||
|
||
// Assert. | ||
Event::assertDispatched(TestEvent::class, function (TestEvent $event) { | ||
$this->assertEquals(['hello' => 'world'], $event->event->getData()); | ||
|
||
return true; | ||
}); | ||
} | ||
|
||
/** @test */ | ||
public function it_dispatches_a_classed_event_from_a_parked_event() | ||
{ | ||
// Arrange. | ||
Event::fake(); | ||
$worker = resolve(EventStoreWorker::class); | ||
$event = $this->makeEventRecord('TestEvent', ['hello' => 'world']); | ||
config(['eventstore.namespace' => 'DigitalRisks\LaravelEventStore\Tests\Fixtures']); | ||
|
||
// Act. | ||
$worker->dispatch($event); | ||
|
||
// Assert. | ||
Event::assertDispatched(TestEvent::class, function (TestEvent $event) { | ||
$this->assertEquals(['hello' => 'world'], $event->event->getData()); | ||
|
||
return true; | ||
}); | ||
} | ||
} |