-
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
d80f244
commit 8ab1c60
Showing
22 changed files
with
452 additions
and
10 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
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 |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
/** @covers \Patchlevel\EventSourcing\Pipeline\Middleware\RecalculatePlayheadMiddleware */ | ||
final class RecalculatePlayheadMiddlewareTest extends TestCase | ||
{ | ||
public function testReculatePlayhead(): void | ||
public function testRecalculatePlayhead(): void | ||
{ | ||
$middleware = new RecalculatePlayheadMiddleware(); | ||
|
||
|
@@ -36,7 +36,7 @@ public function testReculatePlayhead(): void | |
self::assertSame(1, $result[0]->playhead()); | ||
} | ||
|
||
public function testReculatePlayheadWithSamePlayhead(): void | ||
public function testRecalculatePlayheadWithSamePlayhead(): void | ||
{ | ||
$middleware = new RecalculatePlayheadMiddleware(); | ||
|
||
|
@@ -54,4 +54,65 @@ public function testReculatePlayheadWithSamePlayhead(): void | |
|
||
self::assertSame([$message], $result); | ||
} | ||
public function testRecalculateMultipleMessages(): void | ||
{ | ||
$middleware = new RecalculatePlayheadMiddleware(); | ||
|
||
$event = new ProfileCreated( | ||
ProfileId::fromString('1'), | ||
Email::fromString('[email protected]'), | ||
); | ||
|
||
$message = Message::create($event) | ||
->withAggregateClass(Profile::class) | ||
->withAggregateId('1') | ||
->withPlayhead(5); | ||
$result = $middleware($message); | ||
|
||
self::assertCount(1, $result); | ||
self::assertSame(Profile::class, $result[0]->aggregateClass()); | ||
self::assertSame(1, $result[0]->playhead()); | ||
|
||
$message = Message::create($event) | ||
->withAggregateClass(Profile::class) | ||
->withAggregateId('1') | ||
->withPlayhead(8); | ||
|
||
$result = $middleware($message); | ||
|
||
self::assertCount(1, $result); | ||
self::assertSame(Profile::class, $result[0]->aggregateClass()); | ||
self::assertSame(2, $result[0]->playhead()); | ||
} | ||
public function testReset(): void | ||
{ | ||
$middleware = new RecalculatePlayheadMiddleware(); | ||
|
||
$event = new ProfileCreated( | ||
ProfileId::fromString('1'), | ||
Email::fromString('[email protected]'), | ||
); | ||
|
||
$message = Message::create($event) | ||
->withAggregateClass(Profile::class) | ||
->withAggregateId('1') | ||
->withPlayhead(5); | ||
$result = $middleware($message); | ||
|
||
self::assertCount(1, $result); | ||
self::assertSame(Profile::class, $result[0]->aggregateClass()); | ||
self::assertSame(1, $result[0]->playhead()); | ||
|
||
$message = Message::create($event) | ||
->withAggregateClass(Profile::class) | ||
->withAggregateId('1') | ||
->withPlayhead(8); | ||
|
||
$middleware->reset(); | ||
$result = $middleware($message); | ||
|
||
self::assertCount(1, $result); | ||
self::assertSame(Profile::class, $result[0]->aggregateClass()); | ||
self::assertSame(1, $result[0]->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 |
---|---|---|
|
@@ -41,4 +41,15 @@ public function testCount(): void | |
|
||
self::assertSame(1, $source->count()); | ||
} | ||
|
||
public function testCountWithIterator(): void | ||
{ | ||
$message = new Message( | ||
new ProfileCreated(ProfileId::fromString('1'), Email::fromString('[email protected]')), | ||
); | ||
|
||
$source = new InMemorySource(new \ArrayIterator([$message])); | ||
|
||
self::assertSame(1, $source->count()); | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
tests/Unit/Pipeline/Target/ProjectorRepositoryTargetTest.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,78 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\Pipeline\Target; | ||
|
||
use Patchlevel\EventSourcing\EventBus\Message; | ||
use Patchlevel\EventSourcing\Pipeline\Target\ProjectorRepositoryTarget; | ||
use Patchlevel\EventSourcing\Pipeline\Target\ProjectorTarget; | ||
use Patchlevel\EventSourcing\Pipeline\Target\StoreTarget; | ||
use Patchlevel\EventSourcing\Projection\Projector\ProjectorRepository; | ||
use Patchlevel\EventSourcing\Projection\Projector\ProjectorResolver; | ||
use Patchlevel\EventSourcing\Store\Store; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
|
||
/** @covers \Patchlevel\EventSourcing\Pipeline\Target\ProjectorRepositoryTarget */ | ||
final class ProjectorRepositoryTargetTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
public function testSave(): void | ||
{ | ||
$message = new Message( | ||
new ProfileCreated(ProfileId::fromString('1'), Email::fromString('[email protected]')), | ||
); | ||
|
||
$projector = new class { | ||
public Message|null $message = null; | ||
|
||
public function __invoke(Message $message) | ||
{ | ||
$this->message = $message; | ||
} | ||
}; | ||
|
||
$projectorRepository = $this->prophesize(ProjectorRepository::class); | ||
$projectorRepository->projectors()->shouldBeCalledOnce()->willReturn([$projector]); | ||
|
||
$projectorResolver = $this->prophesize(ProjectorResolver::class); | ||
$projectorResolver->resolveSubscribeMethod($projector, $message)->shouldBeCalledOnce()->willReturn($projector(...)); | ||
|
||
$projectorRepositoryTarget = new ProjectorRepositoryTarget($projectorRepository->reveal(), $projectorResolver->reveal()); | ||
$projectorRepositoryTarget->save($message); | ||
|
||
self::assertSame($message, $projector->message); | ||
} | ||
|
||
public function testSaveNoHit(): void | ||
{ | ||
$message = new Message( | ||
new ProfileCreated(ProfileId::fromString('1'), Email::fromString('[email protected]')), | ||
); | ||
|
||
$projector = new class { | ||
public Message|null $message = null; | ||
|
||
public function __invoke(Message $message) | ||
{ | ||
$this->message = $message; | ||
} | ||
}; | ||
|
||
$projectorRepository = $this->prophesize(ProjectorRepository::class); | ||
$projectorRepository->projectors()->shouldBeCalledOnce()->willReturn([$projector]); | ||
|
||
$projectorResolver = $this->prophesize(ProjectorResolver::class); | ||
$projectorResolver->resolveSubscribeMethod($projector, $message)->shouldBeCalledOnce()->willReturn(null); | ||
|
||
$projectorRepositoryTarget = new ProjectorRepositoryTarget($projectorRepository->reveal(), $projectorResolver->reveal()); | ||
$projectorRepositoryTarget->save($message); | ||
|
||
self::assertNull($projector->message); | ||
} | ||
} |
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,72 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Patchlevel\EventSourcing\Tests\Unit\Pipeline\Target; | ||
|
||
use Patchlevel\EventSourcing\EventBus\Message; | ||
use Patchlevel\EventSourcing\Pipeline\Target\ProjectorTarget; | ||
use Patchlevel\EventSourcing\Pipeline\Target\StoreTarget; | ||
use Patchlevel\EventSourcing\Projection\Projector\ProjectorResolver; | ||
use Patchlevel\EventSourcing\Store\Store; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; | ||
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId; | ||
use PHPUnit\Framework\TestCase; | ||
use Prophecy\PhpUnit\ProphecyTrait; | ||
|
||
/** @covers \Patchlevel\EventSourcing\Pipeline\Target\ProjectorTarget */ | ||
final class ProjectorTargetTest extends TestCase | ||
{ | ||
use ProphecyTrait; | ||
|
||
public function testSave(): void | ||
{ | ||
$message = new Message( | ||
new ProfileCreated(ProfileId::fromString('1'), Email::fromString('[email protected]')), | ||
); | ||
|
||
$projector = new class { | ||
public Message|null $message = null; | ||
|
||
public function __invoke(Message $message) | ||
{ | ||
$this->message = $message; | ||
} | ||
}; | ||
|
||
|
||
$projectorResolver = $this->prophesize(ProjectorResolver::class); | ||
$projectorResolver->resolveSubscribeMethod($projector, $message)->shouldBeCalledOnce()->willReturn($projector(...)); | ||
|
||
$projectorTarget = new ProjectorTarget($projector, $projectorResolver->reveal()); | ||
$projectorTarget->save($message); | ||
|
||
self::assertSame($message, $projector->message); | ||
} | ||
|
||
public function testSaveNoHit(): void | ||
{ | ||
$message = new Message( | ||
new ProfileCreated(ProfileId::fromString('1'), Email::fromString('[email protected]')), | ||
); | ||
|
||
$projector = new class { | ||
public Message|null $message = null; | ||
|
||
public function __invoke(Message $message) | ||
{ | ||
$this->message = $message; | ||
} | ||
}; | ||
|
||
|
||
$projectorResolver = $this->prophesize(ProjectorResolver::class); | ||
$projectorResolver->resolveSubscribeMethod($projector, $message)->shouldBeCalledOnce()->willReturn(null); | ||
|
||
$projectorTarget = new ProjectorTarget($projector, $projectorResolver->reveal()); | ||
$projectorTarget->save($message); | ||
|
||
self::assertNull($projector->message); | ||
} | ||
} |
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
Oops, something went wrong.