-
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.
decouple consume and publish in outbox
- Loading branch information
1 parent
7b52991
commit e4ee47c
Showing
7 changed files
with
96 additions
and
14 deletions.
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,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Outbox; | ||
|
||
use Patchlevel\EventSourcing\EventBus\EventBus; | ||
use Patchlevel\EventSourcing\EventBus\Message; | ||
|
||
final class EventBusPublisher implements OutboxPublisher | ||
{ | ||
public function __construct( | ||
private readonly EventBus $eventBus, | ||
) { | ||
} | ||
|
||
public function publish(Message $message): void | ||
{ | ||
$this->eventBus->dispatch($message); | ||
} | ||
} |
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,12 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Outbox; | ||
|
||
use Patchlevel\EventSourcing\EventBus\Message; | ||
|
||
interface OutboxPublisher | ||
{ | ||
public function publish(Message $message): void; | ||
} |
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
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,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\Outbox; | ||
|
||
use Patchlevel\EventSourcing\EventBus\EventBus; | ||
use Patchlevel\EventSourcing\EventBus\Message; | ||
use Patchlevel\EventSourcing\Outbox\EventBusPublisher; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
|
||
/** @covers \Patchlevel\EventSourcing\Outbox\EventBusPublisher */ | ||
final class EventBusPublisherTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
public function testPublish(): void | ||
{ | ||
$message = new Message( | ||
new ProfileCreated( | ||
ProfileId::fromString('1'), | ||
Email::fromString('[email protected]'), | ||
), | ||
); | ||
|
||
$eventBus = $this->prophesize(EventBus::class); | ||
$eventBus->dispatch($message)->shouldBeCalled(); | ||
|
||
$publisher = new EventBusPublisher($eventBus->reveal()); | ||
$publisher->publish($message); | ||
} | ||
} |
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