This repository has been archived by the owner on Aug 23, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add HerdWasRenamed event to the model
- Loading branch information
1 parent
7256601
commit 74a45da
Showing
2 changed files
with
60 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace spec\Elewant\Herding\Model\Events; | ||
|
||
use Elewant\Herding\Model\Events\HerdWasRenamed; | ||
use Elewant\Herding\Model\HerdId; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class HerdWasRenamedSpec extends ObjectBehavior | ||
{ | ||
function it_took_place() | ||
{ | ||
$herdId = HerdId::fromString('00000000-0000-0000-0000-000000000000'); | ||
|
||
$this->beConstructedThrough( | ||
'tookPlace', | ||
[ | ||
$herdId, | ||
'new herd name', | ||
] | ||
); | ||
|
||
$this->shouldHaveType(HerdWasRenamed::class); | ||
$this->aggregateId()->shouldReturn($herdId->toString()); | ||
$this->herdId()->shouldEqual($herdId); | ||
$this->newHerdName()->shouldEqual('new herd name'); | ||
} | ||
} |
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,32 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Elewant\Herding\Model\Events; | ||
|
||
use Elewant\Herding\Model\HerdId; | ||
use Prooph\EventSourcing\AggregateChanged; | ||
|
||
class HerdWasRenamed extends AggregateChanged | ||
{ | ||
public static function tookPlace(HerdId $herdId, string $newHerdName): self | ||
{ | ||
return self::occur( | ||
$herdId->toString(), | ||
[ | ||
'newHerdName' => $newHerdName, | ||
] | ||
); | ||
} | ||
|
||
public function herdId(): HerdId | ||
{ | ||
return HerdId::fromString($this->aggregateId()); | ||
} | ||
|
||
public function newHerdName(): string | ||
{ | ||
return $this->payload['newHerdName']; | ||
} | ||
|
||
} |