diff --git a/src/EventStoreWorker.php b/src/EventStoreWorker.php index e970630..be15a12 100644 --- a/src/EventStoreWorker.php +++ b/src/EventStoreWorker.php @@ -7,6 +7,7 @@ use EventLoop\EventLoop; use Rxnet\EventStore\EventStore; use Rxnet\EventStore\Record\AcknowledgeableEventRecord; +use Rxnet\EventStore\Record\EventRecord; class EventStoreWorker extends Command { @@ -87,7 +88,7 @@ private function processStream($eventStore, string $stream) }, 'report'); } - protected function dispatch(AcknowledgeableEventRecord $event) + public function dispatch(EventRecord $event) { $type = $event->getType(); $class = config('eventstore.namespace') . '\\' . $type; diff --git a/tests/Fixtures/TestEvent.php b/tests/Fixtures/TestEvent.php new file mode 100644 index 0000000..305d7f0 --- /dev/null +++ b/tests/Fixtures/TestEvent.php @@ -0,0 +1,15 @@ +event = $event; + } +} diff --git a/tests/WorkerTest.php b/tests/WorkerTest.php new file mode 100644 index 0000000..86339f3 --- /dev/null +++ b/tests/WorkerTest.php @@ -0,0 +1,76 @@ +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; + }); + } +}