-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
8 changed files
with
193 additions
and
2 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 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,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OtherCode\ComplexHeart\Tests\Domain\Traits; | ||
|
||
|
||
use Mockery\Adapter\Phpunit\MockeryTestCase; | ||
use OtherCode\ComplexHeart\Domain\ValueObjects\UUIDValue; | ||
use OtherCode\ComplexHeart\Tests\Sample\Aggregates\User; | ||
|
||
/** | ||
* Class IsAggregateTrait | ||
* @author Dmytro <dmytro@2amigos.us> | ||
* @package OtherCode\ComplexHeart\Tests\Domain\Traits | ||
*/ | ||
class IsAggregateTraitTest extends MockeryTestCase | ||
{ | ||
public function testAggregateCanCloneItselfWithOverridesAndDomainEvents(): void | ||
{ | ||
$user = new User(UUIDValue::random(), 'user@email.com', 'John Dow'); | ||
$userCopy = $user->withEmail('new@email.com'); | ||
|
||
$this->assertEquals($user->id(), $userCopy->id()); | ||
$this->assertEquals('new@email.com', $userCopy->email()); | ||
$this->assertEquals($user->name(), $userCopy->name()); | ||
|
||
$this->assertEquals($user->getDomainEvents(), $userCopy->getDomainEvents()); | ||
} | ||
} |
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,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OtherCode\ComplexHeart\Tests\Domain\Traits; | ||
|
||
|
||
use Mockery\Adapter\Phpunit\MockeryTestCase; | ||
use OtherCode\ComplexHeart\Tests\Sample\ValueObjects\FullName; | ||
|
||
/** | ||
* Class IsModelTest | ||
* @author Dmytro <dmytro@2amigos.us> | ||
* @package OtherCode\ComplexHeart\Tests\Domain\Traits | ||
*/ | ||
class IsModelTest extends MockeryTestCase | ||
{ | ||
public function testModelCanCloneItselfWithOverrides(): void | ||
{ | ||
$name = new FullName('John', 'Dow'); | ||
$nameCopy = $name->withLastName('Smith'); | ||
|
||
$this->assertEquals($name->firstName(), $nameCopy->firstName()); | ||
$this->assertEquals('Smith', $nameCopy->lastName()); | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OtherCode\ComplexHeart\Tests\Sample\Aggregates; | ||
|
||
|
||
use OtherCode\ComplexHeart\Domain\Contracts\Aggregate; | ||
use OtherCode\ComplexHeart\Domain\Traits\IsAggregate; | ||
use OtherCode\ComplexHeart\Domain\ValueObjects\UUIDValue; | ||
|
||
/** | ||
* Class User | ||
* @author Dmytro <dmytro@2amigos.us> | ||
* @package OtherCode\ComplexHeart\Tests\Sample\Aggregates | ||
* @method UUIDValue id() | ||
* @method string email() | ||
* @method string name() | ||
*/ | ||
class User implements Aggregate | ||
{ | ||
use IsAggregate; | ||
|
||
private UUIDValue $id; | ||
private string $email; | ||
private string $name; | ||
|
||
public function __construct(UUIDValue $id, string $email, string $name) | ||
{ | ||
$this->initialize([$id, $email, $name]); | ||
$this->registerDomainEvent(new UserCreated($id->value())); | ||
} | ||
|
||
public function withEmail(string $email): self | ||
{ | ||
return $this->withOverrides( | ||
[ | ||
'email' => $email | ||
] | ||
); | ||
} | ||
|
||
public function getDomainEvents(): array | ||
{ | ||
return $this->_domainEvents; | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OtherCode\ComplexHeart\Tests\Sample\Aggregates; | ||
|
||
|
||
use OtherCode\ComplexHeart\Domain\Bus\Event; | ||
|
||
/** | ||
* Class UserCreated | ||
* @author Dmytro <dmytro@2amigos.us> | ||
* @package OtherCode\ComplexHeart\Tests\Sample\Aggregates | ||
*/ | ||
class UserCreated extends Event | ||
{ | ||
|
||
} |
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,40 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace OtherCode\ComplexHeart\Tests\Sample\ValueObjects; | ||
|
||
|
||
use OtherCode\ComplexHeart\Domain\Contracts\ValueObject; | ||
use OtherCode\ComplexHeart\Domain\Traits\HasEquality; | ||
use OtherCode\ComplexHeart\Domain\Traits\IsModel; | ||
|
||
/** | ||
* Class FullName | ||
* @author Dmytro <dmytro@2amigos.us> | ||
* @package OtherCode\ComplexHeart\Tests\Sample\ValueObjects | ||
* @method string firstName() | ||
* @method string lastName() | ||
*/ | ||
class FullName implements ValueObject | ||
{ | ||
use IsModel, HasEquality; | ||
|
||
private string $firstName; | ||
|
||
private string $lastName; | ||
|
||
public function __construct(string $firstName, string $lastName) | ||
{ | ||
$this->initialize([$firstName, $lastName]); | ||
} | ||
|
||
public function withLastName(string $lastName): self | ||
{ | ||
return $this->withOverrides( | ||
[ | ||
'lastName' => $lastName | ||
] | ||
); | ||
} | ||
} |