-
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
00d280c
commit 89214f4
Showing
11 changed files
with
471 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Metadata\Subscriber; | ||
|
||
use Patchlevel\EventSourcing\Metadata\MetadataException; | ||
|
||
use function sprintf; | ||
|
||
final class ArgumentTypeNotSupported extends MetadataException | ||
{ | ||
public static function missingType(string $class, string $method, string $argumentName): self | ||
{ | ||
return new self( | ||
sprintf( | ||
'Argument type for method "%s" in class "%s" is not supported. Argument "%s" must have a type.', | ||
$method, | ||
$class, | ||
$argumentName, | ||
), | ||
); | ||
} | ||
|
||
public static function onlyNamedTypeSupported(string $class, string $method, string $argumentName): self | ||
{ | ||
return new self( | ||
sprintf( | ||
'Argument type for method "%s" in class "%s" is not supported. Argument "%s" must not have a union or intersection type.', | ||
$method, | ||
$class, | ||
$argumentName, | ||
), | ||
); | ||
} | ||
} |
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
63 changes: 63 additions & 0 deletions
63
tests/Unit/Subscription/Subscriber/ArgumentResolver/AggregateIdArgumentResolverTest.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,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\Subscription\Subscriber\ArgumentResolver; | ||
|
||
use DateTimeImmutable; | ||
use Patchlevel\EventSourcing\Aggregate\AggregateHeader; | ||
use Patchlevel\EventSourcing\Message\Message; | ||
use Patchlevel\EventSourcing\Metadata\Subscriber\ArgumentMetadata; | ||
use Patchlevel\EventSourcing\Subscription\Subscriber\ArgumentResolver\AggregateIdArgumentResolver; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileVisited; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** @covers \Patchlevel\EventSourcing\Subscription\Subscriber\ArgumentResolver\AggregateIdArgumentResolver */ | ||
final class AggregateIdArgumentResolverTest extends TestCase | ||
{ | ||
public function testSupport(): void | ||
{ | ||
$resolver = new AggregateIdArgumentResolver(); | ||
|
||
self::assertTrue( | ||
$resolver->support( | ||
new ArgumentMetadata('aggregateId', 'string'), | ||
ProfileCreated::class, | ||
), | ||
); | ||
|
||
self::assertTrue( | ||
$resolver->support( | ||
new ArgumentMetadata('aggregateRootId', 'string'), | ||
ProfileCreated::class, | ||
), | ||
); | ||
|
||
self::assertFalse( | ||
$resolver->support( | ||
new ArgumentMetadata('foo', 'string'), | ||
ProfileCreated::class, | ||
), | ||
); | ||
} | ||
|
||
public function testResolve(): void | ||
{ | ||
$event = new ProfileVisited(ProfileId::fromString('1')); | ||
|
||
$resolver = new AggregateIdArgumentResolver(); | ||
$message = (new Message($event))->withHeader( | ||
new AggregateHeader('foo', 'bar', 1, new DateTimeImmutable()), | ||
); | ||
|
||
self::assertSame( | ||
'bar', | ||
$resolver->resolve( | ||
new ArgumentMetadata('foo', 'string'), | ||
$message, | ||
), | ||
); | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
tests/Unit/Subscription/Subscriber/ArgumentResolver/EventArgumentResolverTest.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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\Subscription\Subscriber\ArgumentResolver; | ||
|
||
use Patchlevel\EventSourcing\Message\Message; | ||
use Patchlevel\EventSourcing\Metadata\Subscriber\ArgumentMetadata; | ||
use Patchlevel\EventSourcing\Subscription\Subscriber\ArgumentResolver\EventArgumentResolver; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileVisited; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** @covers \Patchlevel\EventSourcing\Subscription\Subscriber\ArgumentResolver\EventArgumentResolver */ | ||
final class EventArgumentResolverTest extends TestCase | ||
{ | ||
public function testSupport(): void | ||
{ | ||
$resolver = new EventArgumentResolver(); | ||
|
||
self::assertTrue( | ||
$resolver->support( | ||
new ArgumentMetadata('foo', ProfileCreated::class), | ||
ProfileCreated::class, | ||
), | ||
); | ||
|
||
self::assertFalse( | ||
$resolver->support( | ||
new ArgumentMetadata('foo', ProfileVisited::class), | ||
ProfileCreated::class, | ||
), | ||
); | ||
} | ||
|
||
public function testResolve(): void | ||
{ | ||
$event = new ProfileVisited(ProfileId::fromString('1')); | ||
|
||
$resolver = new EventArgumentResolver(); | ||
$message = new Message($event); | ||
|
||
self::assertSame( | ||
$event, | ||
$resolver->resolve( | ||
new ArgumentMetadata('foo', ProfileVisited::class), | ||
$message, | ||
), | ||
); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
tests/Unit/Subscription/Subscriber/ArgumentResolver/MessageArgumentResolverTest.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,48 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\Subscription\Subscriber\ArgumentResolver; | ||
|
||
use Patchlevel\EventSourcing\Message\Message; | ||
use Patchlevel\EventSourcing\Metadata\Subscriber\ArgumentMetadata; | ||
use Patchlevel\EventSourcing\Subscription\Subscriber\ArgumentResolver\MessageArgumentResolver; | ||
use PHPUnit\Framework\TestCase; | ||
use stdClass; | ||
|
||
/** @covers \Patchlevel\EventSourcing\Subscription\Subscriber\ArgumentResolver\MessageArgumentResolver */ | ||
final class MessageArgumentResolverTest extends TestCase | ||
{ | ||
public function testSupport(): void | ||
{ | ||
$resolver = new MessageArgumentResolver(); | ||
|
||
self::assertTrue( | ||
$resolver->support( | ||
new ArgumentMetadata('foo', Message::class), | ||
'qux', | ||
), | ||
); | ||
|
||
self::assertFalse( | ||
$resolver->support( | ||
new ArgumentMetadata('foo', 'bar'), | ||
'qux', | ||
), | ||
); | ||
} | ||
|
||
public function testResolve(): void | ||
{ | ||
$resolver = new MessageArgumentResolver(); | ||
$message = new Message(new stdClass()); | ||
|
||
self::assertSame( | ||
$message, | ||
$resolver->resolve( | ||
new ArgumentMetadata('foo', Message::class), | ||
$message, | ||
), | ||
); | ||
} | ||
} |
Oops, something went wrong.