-
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 #490 from patchlevel/add-more-tests
Add more tests
- Loading branch information
Showing
64 changed files
with
1,734 additions
and
99 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
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,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\Aggregate; | ||
|
||
use Patchlevel\EventSourcing\Aggregate\AggregateRootIdNotSupported; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** @covers \Patchlevel\EventSourcing\Aggregate\AggregateRootIdNotSupported */ | ||
final class AggregateRootIdNotSupportedTest extends TestCase | ||
{ | ||
public function testCreate(): void | ||
{ | ||
$exception = new AggregateRootIdNotSupported(Profile::class, 1); | ||
|
||
self::assertSame( | ||
'aggregate root id in class "Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile" must be instance of "Patchlevel\EventSourcing\Aggregate\AggregateRootId", got "int"', | ||
$exception->getMessage(), | ||
); | ||
self::assertSame(0, $exception->getCode()); | ||
} | ||
} |
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\Aggregate; | ||
|
||
use Patchlevel\EventSourcing\Aggregate\AggregateRootIdNotSupported; | ||
use Patchlevel\EventSourcing\Aggregate\ApplyMethodNotFound; | ||
use Patchlevel\EventSourcing\Aggregate\BasicAggregateRoot; | ||
use Patchlevel\EventSourcing\Aggregate\MetadataNotPossible; | ||
|
@@ -16,10 +17,16 @@ | |
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileInvalid; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithBrokenId; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileWithSuppressAll; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** @covers \Patchlevel\EventSourcing\Aggregate\BasicAggregateRoot */ | ||
/** | ||
* @covers \Patchlevel\EventSourcing\Aggregate\BasicAggregateRoot | ||
* @covers \Patchlevel\EventSourcing\Aggregate\AggregateRootBehaviour | ||
* @covers \Patchlevel\EventSourcing\Aggregate\AggregateRootAttributeBehaviour | ||
* @covers \Patchlevel\EventSourcing\Aggregate\AggregateRootMetadataAwareBehaviour | ||
*/ | ||
final class AggregateRootTest extends TestCase | ||
{ | ||
public function testApplyMethod(): void | ||
|
@@ -162,4 +169,24 @@ public function testMetadataNotPossible(): void | |
|
||
BasicAggregateRoot::metadata(); | ||
} | ||
|
||
public function testCachedAggregateId(): void | ||
{ | ||
$profileId = ProfileId::fromString('1'); | ||
$email = Email::fromString('[email protected]'); | ||
|
||
$profile = Profile::createProfile($profileId, $email); | ||
$id = $profile->aggregateRootId(); | ||
|
||
self::assertSame($profileId, $id); | ||
self::assertSame($id, $profile->aggregateRootId()); | ||
} | ||
|
||
public function testInvalidAggregateId(): void | ||
{ | ||
$aggregate = ProfileWithBrokenId::create(); | ||
|
||
$this->expectException(AggregateRootIdNotSupported::class); | ||
$aggregate->aggregateRootId(); | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\Aggregate; | ||
|
||
use Patchlevel\EventSourcing\Aggregate\CustomId; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** @covers \Patchlevel\EventSourcing\Aggregate\CustomId */ | ||
final class CustomIdTest extends TestCase | ||
{ | ||
public function testFromString(): void | ||
{ | ||
$id = CustomId::fromString('1'); | ||
|
||
self::assertSame('1', $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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\Aggregate; | ||
|
||
use Patchlevel\EventSourcing\Aggregate\MetadataNotPossible; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** @covers \Patchlevel\EventSourcing\Aggregate\MetadataNotPossible */ | ||
final class MetadataNotPossibleTest extends TestCase | ||
{ | ||
public function testCreate(): void | ||
{ | ||
$exception = new MetadataNotPossible(); | ||
|
||
self::assertSame( | ||
'Metadata method must be called on the concrete implementation', | ||
$exception->getMessage(), | ||
); | ||
self::assertSame(0, $exception->getCode()); | ||
} | ||
} |
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,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\Aggregate; | ||
|
||
use DateTimeInterface; | ||
use Patchlevel\EventSourcing\Aggregate\Uuid; | ||
use PHPUnit\Framework\TestCase; | ||
use Ramsey\Uuid\Type\Hexadecimal; | ||
use Ramsey\Uuid\Uuid as RamseyUuid; | ||
use Ramsey\Uuid\UuidFactory; | ||
use Ramsey\Uuid\UuidInterface; | ||
|
||
/** @covers \Patchlevel\EventSourcing\Aggregate\Uuid */ | ||
final class UuidTest extends TestCase | ||
{ | ||
public function testFromString(): void | ||
{ | ||
$id = Uuid::fromString('1eec1e5c-e397-6644-9aed-0242ac110002'); | ||
|
||
self::assertSame('1eec1e5c-e397-6644-9aed-0242ac110002', $id->toString()); | ||
} | ||
|
||
public function testV6(): void | ||
{ | ||
$factory = new class extends UuidFactory | ||
{ | ||
public function uuid6(Hexadecimal|null $node = null, int|null $clockSeq = null): UuidInterface | ||
{ | ||
return RamseyUuid::fromString('1eec1e5c-e397-6644-9aed-0242ac110002'); | ||
} | ||
}; | ||
|
||
RamseyUuid::setFactory($factory); | ||
$id = Uuid::v6(); | ||
|
||
self::assertSame('1eec1e5c-e397-6644-9aed-0242ac110002', $id->toString()); | ||
} | ||
|
||
public function testV7(): void | ||
{ | ||
$factory = new class extends UuidFactory | ||
{ | ||
public function uuid7(DateTimeInterface|null $dateTime = null): UuidInterface | ||
{ | ||
return RamseyUuid::fromString('018d6a97-6aba-7104-825f-67313a77a2a4'); | ||
} | ||
}; | ||
|
||
RamseyUuid::setFactory($factory); | ||
$id = Uuid::v7(); | ||
|
||
self::assertSame('018d6a97-6aba-7104-825f-67313a77a2a4', $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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\Attribute; | ||
|
||
use Patchlevel\EventSourcing\Attribute\Aggregate; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** @covers \Patchlevel\EventSourcing\Attribute\Aggregate */ | ||
final class AggregateTest extends TestCase | ||
{ | ||
public function testInstantiate(): void | ||
{ | ||
$attribute = new Aggregate('foo'); | ||
|
||
self::assertSame('foo', $attribute->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,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\Attribute; | ||
|
||
use Patchlevel\EventSourcing\Attribute\Apply; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** @covers \Patchlevel\EventSourcing\Attribute\Apply */ | ||
final class ApplyTest extends TestCase | ||
{ | ||
public function testInstantiate(): void | ||
{ | ||
$attribute = new Apply(Profile::class); | ||
|
||
self::assertSame(Profile::class, $attribute->eventClass); | ||
} | ||
} |
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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\Attribute; | ||
|
||
use Patchlevel\EventSourcing\Attribute\Event; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** @covers \Patchlevel\EventSourcing\Attribute\Event */ | ||
final class EventTest extends TestCase | ||
{ | ||
public function testInstantiate(): void | ||
{ | ||
$attribute = new Event('foo'); | ||
|
||
self::assertSame('foo', $attribute->name); | ||
} | ||
} |
Oops, something went wrong.