-
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.
- Loading branch information
1 parent
44d2a2d
commit 757a04c
Showing
16 changed files
with
116 additions
and
211 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
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 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
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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Message\Serializer; | ||
|
||
use RuntimeException; | ||
|
||
final class InvalidArgument extends RuntimeException | ||
{ | ||
} |
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
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 |
---|---|---|
|
@@ -13,11 +13,12 @@ | |
use Patchlevel\EventSourcing\Serializer\EventSerializer; | ||
use Patchlevel\EventSourcing\Serializer\SerializedEvent; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Header\FooHeader; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\Argument; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
use RuntimeException; | ||
use Symfony\Component\Console\Input\ArrayInput; | ||
use Symfony\Component\Console\Output\BufferedOutput; | ||
|
||
|
@@ -46,9 +47,8 @@ public function testMessage(): void | |
)); | ||
|
||
$headersSerializer = $this->prophesize(HeadersSerializer::class); | ||
$headersSerializer->serialize($message->headers(), [Encoder::OPTION_PRETTY_PRINT => true])->willReturn( | ||
['aggregate' => '{"aggregateName":"profile","aggregateId":"1","playhead":1,"recordedOn":"2020-01-01T20:00:00+01:00"}'], | ||
); | ||
$headersSerializer->serialize(Argument::any())->shouldNotBeCalled(); | ||
|
||
$console = new OutputStyle($input, $output); | ||
|
||
$console->message( | ||
|
@@ -63,10 +63,10 @@ public function testMessage(): void | |
self::assertStringContainsString('profile', $content); | ||
self::assertStringContainsString('{"id":"1","email":"[email protected]"}', $content); | ||
self::assertStringContainsString('aggregate', $content); | ||
self::assertStringContainsString('{"aggregateName":"profile","aggregateId":"1","playhead":1,"recordedOn":"2020-01-01T20:00:00+01:00"}', $content); | ||
self::assertStringContainsString('profile', $content); | ||
} | ||
|
||
public function testMessageWithErrorAtEventSerialization(): void | ||
public function testMessageWithCustomHeaders(): void | ||
{ | ||
$input = new ArrayInput([]); | ||
$output = new BufferedOutput(); | ||
|
@@ -76,44 +76,11 @@ public function testMessageWithErrorAtEventSerialization(): void | |
Email::fromString('[email protected]'), | ||
); | ||
|
||
$message = Message::create($event) | ||
->withHeader(new AggregateHeader('profile', '1', 1, new DateTimeImmutable())); | ||
|
||
$eventSerializer = $this->prophesize(EventSerializer::class); | ||
$eventSerializer | ||
->serialize($event, [Encoder::OPTION_PRETTY_PRINT => true]) | ||
->willThrow(new RuntimeException('Unknown Error')); | ||
|
||
$headersSerializer = $this->prophesize(HeadersSerializer::class); | ||
$headersSerializer->serialize($message->headers(), [Encoder::OPTION_PRETTY_PRINT => true]) | ||
->shouldNotBeCalled(); | ||
|
||
$console = new OutputStyle($input, $output); | ||
|
||
$console->message( | ||
$eventSerializer->reveal(), | ||
$headersSerializer->reveal(), | ||
$message, | ||
); | ||
|
||
$content = $output->fetch(); | ||
|
||
self::assertStringContainsString('Unknown Error', $content); | ||
self::assertStringContainsString(ProfileCreated::class, $content); | ||
} | ||
|
||
public function testMessageWithErrorAtHeadersSerialization(): void | ||
{ | ||
$input = new ArrayInput([]); | ||
$output = new BufferedOutput(); | ||
|
||
$event = new ProfileCreated( | ||
ProfileId::fromString('1'), | ||
Email::fromString('[email protected]'), | ||
); | ||
$fooHeader = new FooHeader('foo'); | ||
|
||
$message = Message::create($event) | ||
->withHeader(new AggregateHeader('profile', '1', 1, new DateTimeImmutable())); | ||
->withHeader(new AggregateHeader('profile', '1', 1, new DateTimeImmutable())) | ||
->withHeader($fooHeader); | ||
|
||
$eventSerializer = $this->prophesize(EventSerializer::class); | ||
$eventSerializer->serialize($event, [Encoder::OPTION_PRETTY_PRINT => true])->willReturn(new SerializedEvent( | ||
|
@@ -122,8 +89,9 @@ public function testMessageWithErrorAtHeadersSerialization(): void | |
)); | ||
|
||
$headersSerializer = $this->prophesize(HeadersSerializer::class); | ||
$headersSerializer->serialize($message->headers(), [Encoder::OPTION_PRETTY_PRINT => true]) | ||
->willThrow(new RuntimeException('Unknown Error')); | ||
$headersSerializer->serialize([$fooHeader])->willReturn( | ||
'{"aggregate":{"aggregateName":"profile","aggregateId":"1","playhead":1,"recordedOn":"2020-01-01T20:00:00+01:00"},"archived":[]}', | ||
)->shouldBeCalled(); | ||
|
||
$console = new OutputStyle($input, $output); | ||
|
||
|
@@ -135,6 +103,10 @@ public function testMessageWithErrorAtHeadersSerialization(): void | |
|
||
$content = $output->fetch(); | ||
|
||
self::assertStringContainsString('Unknown Error', $content); | ||
self::assertStringContainsString('profile.created', $content); | ||
self::assertStringContainsString('profile', $content); | ||
self::assertStringContainsString('{"id":"1","email":"[email protected]"}', $content); | ||
self::assertStringContainsString('aggregate', $content); | ||
self::assertStringContainsString('profile', $content); | ||
} | ||
} |
Oops, something went wrong.