-
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.
add consumer target and replace old projector targets
- Loading branch information
1 parent
da33974
commit 3a6e9c1
Showing
7 changed files
with
72 additions
and
235 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,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Pipeline\Target; | ||
|
||
use Patchlevel\EventSourcing\EventBus\Consumer; | ||
use Patchlevel\EventSourcing\EventBus\DefaultConsumer; | ||
use Patchlevel\EventSourcing\EventBus\Message; | ||
|
||
final class ConsumerTarget implements Target | ||
{ | ||
public function __construct( | ||
private readonly Consumer $consumer, | ||
) { | ||
} | ||
|
||
public function save(Message ...$messages): void | ||
{ | ||
foreach ($messages as $message) { | ||
$this->consumer->consume($message); | ||
} | ||
} | ||
|
||
public static function create(iterable $listeners): self | ||
Check failure on line 25 in src/Pipeline/Target/ConsumerTarget.php GitHub Actions / Static Analysis by PHPStan (locked, 8.3, ubuntu-latest)
|
||
{ | ||
return new self(DefaultConsumer::create($listeners)); | ||
Check failure on line 27 in src/Pipeline/Target/ConsumerTarget.php GitHub Actions / Static Analysis by Psalm (locked, 8.3, ubuntu-latest)MixedArgumentTypeCoercion
|
||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\Pipeline\Target; | ||
|
||
use Patchlevel\EventSourcing\EventBus\Consumer; | ||
use Patchlevel\EventSourcing\EventBus\Message; | ||
use Patchlevel\EventSourcing\Pipeline\Target\ConsumerTarget; | ||
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\Pipeline\Target\ConsumerTarget */ | ||
final class ConsumerTargetTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
public function testSave(): void | ||
{ | ||
$message = new Message( | ||
new ProfileCreated(ProfileId::fromString('1'), Email::fromString('[email protected]')), | ||
); | ||
|
||
$consumer = $this->prophesize(Consumer::class); | ||
$consumer->consume($message)->shouldBeCalledOnce(); | ||
|
||
$consumerTarget = new ConsumerTarget($consumer->reveal()); | ||
$consumerTarget->save($message); | ||
} | ||
} |
75 changes: 0 additions & 75 deletions
75
tests/Unit/Pipeline/Target/ProjectorRepositoryTargetTest.php
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.