Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
eithed committed Aug 15, 2024
1 parent 4e966d8 commit 7049cc1
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 50 deletions.
6 changes: 2 additions & 4 deletions tests/Projectors/EloquentZeroDowntimeProjectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@

class EloquentZeroDowntimeProjectorTest extends TestCase
{
/** @test */
public function it_creates_new_tables_with_the_right_sequences_and_foreign_keys()
public function test_it_creates_new_tables_with_the_right_sequences_and_foreign_keys()
{
$projector = new PostProjector();
$projector->forReplay()->useConnection('foo');
Expand All @@ -39,8 +38,7 @@ public function it_creates_new_tables_with_the_right_sequences_and_foreign_keys(
$this->assertEquals(1, $comment->id);
}

/** @test */
public function it_drops_table_and_sequences_on_removal()
public function test_it_drops_table_and_sequences_on_removal()
{
$projector = new PostProjector();
$projector->forReplay()->useConnection('foobar');
Expand Down
30 changes: 10 additions & 20 deletions tests/ReplayManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@

class ReplayManagerTest extends TestCase
{
/** @test */
public function it_throws_exception_when_replay_already_exists_on_start()
public function test_it_throws_exception_when_replay_already_exists_on_start()
{
$manager = new ReplayManager(new InMemoryReplayRepository(), new FakeProjectionist(), new FakeStoredEventRepository());
$manager->createReplay('foo', []);
Expand All @@ -27,8 +26,7 @@ public function it_throws_exception_when_replay_already_exists_on_start()
$this->assertTrue($thrown, "Exception StartReplayException expected but not thrown");
}

/** @test */
public function it_validates_if_projector_is_configured()
public function test_it_validates_if_projector_is_configured()
{
$projectionist = new FakeProjectionist();
$repo = new InMemoryReplayRepository();
Expand All @@ -42,8 +40,7 @@ public function it_validates_if_projector_is_configured()
$this->assertNull($repo->getReplayByKey('foo'));
}

/** @test */
public function it_persists_replay_with_valid_projectors()
public function test_it_persists_replay_with_valid_projectors()
{
$projectionist = new FakeProjectionist();
$projectionist->addProjector('RegisteredProjector');
Expand All @@ -59,8 +56,7 @@ public function it_persists_replay_with_valid_projectors()
$this->assertEquals(['RegisteredProjector'], $replay->projectors);
}

/** @test */
public function it_starts_a_replay()
public function test_it_starts_a_replay()
{
$repo = new InMemoryReplayRepository();
$projectionist = new FakeProjectionist();
Expand All @@ -75,8 +71,7 @@ public function it_starts_a_replay()
$this->assertEquals(0, $projectionist->replays[0]['startingFrom']);
}

/** @test */
public function it_starts_a_replay_from_last_projected_event()
public function test_it_starts_a_replay_from_last_projected_event()
{
$repo = new InMemoryReplayRepository();
$projectionist = new FakeProjectionist();
Expand All @@ -95,8 +90,7 @@ public function it_starts_a_replay_from_last_projected_event()
$this->assertEquals(101, $projectionist->replays[0]['startingFrom']);
}

/** @test */
public function it_gets_replay_lag()
public function test_it_gets_replay_lag()
{
$repo = new InMemoryReplayRepository();
$projectionist = new FakeProjectionist();
Expand All @@ -113,8 +107,7 @@ public function it_gets_replay_lag()
$this->assertEquals(44, $manager->getReplayLag('foo'));
}

/** @test */
public function it_enables_projections_when_lag_is_0()
public function test_it_enables_projections_when_lag_is_0()
{
$repo = new InMemoryReplayRepository();
$projectionist = new FakeProjectionist();
Expand All @@ -130,8 +123,7 @@ public function it_enables_projections_when_lag_is_0()
$this->assertTrue($replay->projectionsEnabled);
}

/** @test */
public function it_does_not_enable_projections_when_lag_is_not_0()
public function test_it_does_not_enable_projections_when_lag_is_not_0()
{
$repo = new InMemoryReplayRepository();
$projectionist = new FakeProjectionist();
Expand All @@ -155,8 +147,7 @@ public function it_does_not_enable_projections_when_lag_is_not_0()
$this->assertTrue($thrown, "exception not thrown");
}

/** @test */
public function it_calls_projectors_to_put_replay_live()
public function test_it_calls_projectors_to_put_replay_live()
{
$projector = new FakeProjector();

Expand All @@ -174,8 +165,7 @@ public function it_calls_projectors_to_put_replay_live()
$this->assertTrue($projector->hasBeenPutLive());
}

/** @test */
public function it_can_remove_replays()
public function test_it_can_remove_replays()
{
$projector = new FakeProjector();

Expand Down
50 changes: 24 additions & 26 deletions tests/ReplaySerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,82 +8,80 @@

class ReplaySerializerTest extends TestCase
{
/** @test
* @dataProvider provider
*/
public function it_parses_and_reconstructs_plays(Replay $replay)
/** @dataProvider provider */
public function test_it_parses_and_reconstructs_plays(Replay $replay)
{
$data = ReplaySerializer::toArray($replay);
// Make sure array can be json encoded
$data = json_decode(json_encode($data), true);

$reconstructedReplay = ReplaySerializer::fromArray($data);
$this->assertEquals($replay, $reconstructedReplay);
self::assertEquals($replay, $reconstructedReplay);
}

public function provider(): array
public static function provider(): array
{
return [
[$this->replay()],
[$this->replayWithProjectors()],
[$this->startedReplay()],
[$this->replayInProgress()],
[$this->finishedReplay()],
[$this->twoReplays()],
[$this->enabledProjections()],
[self::replay()],
[self::replayWithProjectors()],
[self::startedReplay()],
[self::replayInProgress()],
[self::finishedReplay()],
[self::twoReplays()],
[self::enabledProjections()],
];
}

private function replay(): Replay
private static function replay(): Replay
{
return new Replay('foo');
}

private function replayWithProjectors(): Replay
private static function replayWithProjectors(): Replay
{
$replay = $this->replay();
$replay = self::replay();
$replay->addProjector('foobar');
$replay->addProjector('baz');

return $replay;
}

private function startedReplay(): Replay
private static function startedReplay(): Replay
{
$replay = $this->replayWithProjectors();
$replay = self::replayWithProjectors();
$replay->started(0, Carbon::parse('2021-01-01 10:00:00'));

return $replay;
}

private function replayInProgress(): Replay
private static function replayInProgress(): Replay
{
$replay = $this->startedReplay();
$replay = self::startedReplay();
$replay->setLastProjectedEventNumber(10);

return $replay;
}

private function finishedReplay(): Replay
private static function finishedReplay(): Replay
{
$replay = $this->replayInProgress();
$replay = self::replayInProgress();
$replay->finished(Carbon::parse('2021-01-01 12:00:00'));

return $replay;
}

private function twoReplays(): Replay
private static function twoReplays(): Replay
{
$replay = $this->finishedReplay();
$replay = self::finishedReplay();
$replay->started(100, Carbon::parse('2021-01-02 14:00:00'));
$replay->finished(Carbon::parse('2021-01-02 16:00:00'));

return $replay;
}

private function enabledProjections(): Replay
private static function enabledProjections(): Replay
{
$replay = $this->replay();
$replay = self::replay();
$replay->enableProjections();

return $replay;
Expand Down

0 comments on commit 7049cc1

Please sign in to comment.