Skip to content

Commit

Permalink
imrove tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Mar 8, 2024
1 parent 677f607 commit 6f29f3f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
12 changes: 12 additions & 0 deletions tests/Integration/Projectionist/Aggregate/Profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Patchlevel\EventSourcing\Serializer\Normalizer\IdNormalizer;
use Patchlevel\EventSourcing\Tests\Integration\Projectionist\Events\NameChanged;
use Patchlevel\EventSourcing\Tests\Integration\Projectionist\Events\ProfileCreated;
use Patchlevel\EventSourcing\Tests\Integration\Projectionist\Events\Reborned;
use Patchlevel\EventSourcing\Tests\Integration\Projectionist\ProfileId;

#[Aggregate('profile')]
Expand All @@ -34,6 +35,11 @@ public function changeName(string $name): void
$this->recordThat(new NameChanged($name));
}

public function reborn(string $name): void
{
$this->recordThat(new Reborned($name));
}

#[Apply]
protected function applyProfileCreated(ProfileCreated $event): void
{
Expand All @@ -47,6 +53,12 @@ protected function applyNameChanged(NameChanged $event): void
$this->name = $event->name;
}

#[Apply]
protected function applyReborned(Reborned $event): void
{
$this->name = $event->name;
}

public function name(): string
{
return $this->name;
Expand Down
16 changes: 16 additions & 0 deletions tests/Integration/Projectionist/Events/Reborned.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Patchlevel\EventSourcing\Tests\Integration\Projectionist\Events;

use Patchlevel\EventSourcing\Attribute\Event;

#[Event('profile.reborned')]
final class Reborned
{
public function __construct(
public string $name,
) {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
use Patchlevel\EventSourcing\EventBus\Message;
use Patchlevel\EventSourcing\Repository\RepositoryManager;
use Patchlevel\EventSourcing\Tests\Integration\Projectionist\Aggregate\Profile;
use Patchlevel\EventSourcing\Tests\Integration\Projectionist\Events\NameChanged;
use Patchlevel\EventSourcing\Tests\Integration\Projectionist\Events\ProfileCreated;

use Patchlevel\EventSourcing\Tests\Integration\Projectionist\ProfileId;
use function assert;

#[Projector('profile_change_name')]
final class ChangeNameProcessor
final class ProfileProcessor
{
public function __construct(
private RepositoryManager $repositoryManager,
Expand All @@ -36,4 +38,18 @@ public function handleProfileCreated(Message $message): void

$repository->save($profile);
}

#[Subscribe(NameChanged::class)]
public function handleNameChanged(Message $message)
{
$id = ProfileId::fromString($message->aggregateId());

$repository = $this->repositoryManager->get(Profile::class);

$profile = $repository->load($id);

$profile->reborn('neo');

$repository->save($profile);
}
}
6 changes: 3 additions & 3 deletions tests/Integration/Projectionist/ProjectionistTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
use Patchlevel\EventSourcing\Store\DoctrineDbalStore;
use Patchlevel\EventSourcing\Tests\DbalManager;
use Patchlevel\EventSourcing\Tests\Integration\Projectionist\Aggregate\Profile;
use Patchlevel\EventSourcing\Tests\Integration\Projectionist\Projection\ChangeNameProcessor;
use Patchlevel\EventSourcing\Tests\Integration\Projectionist\Projection\ProfileProcessor;
use Patchlevel\EventSourcing\Tests\Integration\Projectionist\Projection\ErrorProducerProjector;
use Patchlevel\EventSourcing\Tests\Integration\Projectionist\Projection\ProfileProjector;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -323,7 +323,7 @@ public function testProcessor(): void

$projectorAccessorRepository = new TraceableProjectorAccessorRepository(
new MetadataProjectorAccessorRepository([
new ChangeNameProcessor($manager)
new ProfileProcessor($manager)
]),
$traceStack
);
Expand Down Expand Up @@ -378,7 +378,7 @@ public function testProcessor(): void
Projection::DEFAULT_GROUP,
RunMode::FromBeginning,
ProjectionStatus::Active,
2,
3,
lastSavedAt: new DateTimeImmutable('2021-01-01T00:00:00'),
),
],
Expand Down

0 comments on commit 6f29f3f

Please sign in to comment.