-
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.
Merge pull request #98 from patchlevel/rename-trait-and-cleanup-tests
rename DefaultApplyMethod to NonStrictApplyMethod & cleanup tests
- Loading branch information
Showing
10 changed files
with
182 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ public function __construct($value, string $need) | |
gettype($value) | ||
) | ||
); | ||
|
||
$this->value = $value; | ||
} | ||
|
||
|
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
64 changes: 64 additions & 0 deletions
64
tests/Unit/Aggregate/AggregateRootWithNonStrictApplyTest.php
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,64 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\Aggregate; | ||
|
||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Message; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\MessageId; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithNonStrictApply; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class AggregateRootWithNonStrictApplyTest extends TestCase | ||
{ | ||
public function testApplyMethod(): void | ||
{ | ||
$id = ProfileId::fromString('1'); | ||
$email = Email::fromString('david.badura@patchlevel.de'); | ||
|
||
$profile = ProfileWithNonStrictApply::createProfile($id, $email); | ||
|
||
self::assertEquals('1', $profile->aggregateRootId()); | ||
self::assertEquals(1, $profile->playhead()); | ||
self::assertEquals($id, $profile->id()); | ||
self::assertEquals($email, $profile->email()); | ||
|
||
$events = $profile->releaseEvents(); | ||
|
||
self::assertCount(1, $events); | ||
$event = $events[0]; | ||
self::assertEquals(1, $event->playhead()); | ||
} | ||
|
||
public function testEventWithoutApplyMethod(): void | ||
{ | ||
$profileId = ProfileId::fromString('1'); | ||
$email = Email::fromString('david.badura@patchlevel.de'); | ||
|
||
$messageId = MessageId::fromString('2'); | ||
|
||
$profile = ProfileWithNonStrictApply::createProfile($profileId, $email); | ||
|
||
$events = $profile->releaseEvents(); | ||
|
||
self::assertCount(1, $events); | ||
self::assertEquals(1, $profile->playhead()); | ||
$event = $events[0]; | ||
self::assertEquals(1, $event->playhead()); | ||
|
||
$profile->publishMessage( | ||
Message::create( | ||
$messageId, | ||
'foo' | ||
) | ||
); | ||
|
||
$events = $profile->releaseEvents(); | ||
|
||
self::assertCount(1, $events); | ||
$event = $events[0]; | ||
self::assertEquals(2, $event->playhead()); | ||
} | ||
} |
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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\Console; | ||
|
||
use Patchlevel\EventSourcing\Console\InvalidArgumentException; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
final class InvalidArgumentExceptionTest extends TestCase | ||
{ | ||
public function testException(): void | ||
{ | ||
$expectedValue = 'foo'; | ||
$exception = new InvalidArgumentException($expectedValue, 'int'); | ||
|
||
self::assertEquals('Invalid argument given: need type "int" got "string"', $exception->getMessage()); | ||
self::assertEquals($expectedValue, $exception->value()); | ||
} | ||
} |
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,58 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\Fixture; | ||
|
||
use Patchlevel\EventSourcing\Aggregate\AggregateRoot; | ||
use Patchlevel\EventSourcing\Aggregate\NonStrictApplyMethod; | ||
|
||
final class ProfileWithNonStrictApply extends AggregateRoot | ||
{ | ||
use NonStrictApplyMethod; | ||
|
||
private ProfileId $id; | ||
private Email $email; | ||
|
||
public function id(): ProfileId | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function email(): Email | ||
{ | ||
return $this->email; | ||
} | ||
|
||
public static function createProfile(ProfileId $id, Email $email): self | ||
{ | ||
$self = new self(); | ||
$self->record(ProfileCreated::raise($id, $email)); | ||
|
||
return $self; | ||
} | ||
|
||
public function publishMessage(Message $message): void | ||
{ | ||
$this->record(MessagePublished::raise( | ||
$this->id, | ||
$message, | ||
)); | ||
} | ||
|
||
public function visitProfile(ProfileId $profileId): void | ||
{ | ||
$this->record(ProfileVisited::raise($this->id, $profileId)); | ||
} | ||
|
||
protected function applyProfileCreated(ProfileCreated $event): void | ||
{ | ||
$this->id = $event->profileId(); | ||
$this->email = $event->email(); | ||
} | ||
|
||
public function aggregateRootId(): string | ||
{ | ||
return $this->id->toString(); | ||
} | ||
} |
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