Skip to content

Commit

Permalink
Merge pull request #512 from patchlevel/fix-from-now-position
Browse files Browse the repository at this point in the history
fix start position of "from now" projections
  • Loading branch information
DavidBadura authored Feb 27, 2024
2 parents 7661278 + 4b621fc commit d0bf33a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Projection/Projectionist/DefaultProjectionist.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ private function latestIndex(): int
{
$stream = $this->streamableMessageStore->load(null, 1, null, true);

return $stream->index() ?: 1;
return $stream->index() ?: 0;
}

/** @param list<Projection> $projections */
Expand Down
49 changes: 49 additions & 0 deletions tests/Unit/Projection/Projectionist/DefaultProjectionistTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,55 @@ public function handle(Message $message): void
self::assertNull($projector->message);
}

public function testBootingWithFromNowWithEmtpyStream(): void
{
$projectionId = 'test';
$projector = new #[ProjectionAttribute('test', runMode: RunMode::FromNow)]
class {
public Message|null $message = null;

#[Subscribe(ProfileVisited::class)]
public function handle(Message $message): void
{
$this->message = $message;
}
};

$projectionStore = new DummyStore([
new Projection(
$projectionId,
Projection::DEFAULT_GROUP,
RunMode::FromNow,
ProjectionStatus::Booting,
),
]);

$message1 = new Message(new ProfileVisited(ProfileId::fromString('test')));

$streamableStore = $this->prophesize(Store::class);
$streamableStore->load(null, 1, null, true)->willReturn(new ArrayStream([]))->shouldBeCalledOnce();

$projectionist = new DefaultProjectionist(
$streamableStore->reveal(),
$projectionStore,
[$projector],
);

$projectionist->boot();

self::assertEquals([
new Projection(
$projectionId,
Projection::DEFAULT_GROUP,
RunMode::FromNow,
ProjectionStatus::Active,
0,
),
], $projectionStore->updatedProjections);

self::assertNull($projector->message);
}

public function testBootingWithOnlyOnce(): void
{
$projectionId = 'test';
Expand Down

0 comments on commit d0bf33a

Please sign in to comment.