Skip to content

Commit

Permalink
revert aggregate changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Dec 2, 2021
1 parent a7dce99 commit 9cf20d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
3 changes: 1 addition & 2 deletions src/Aggregate/AggregateChanged.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Patchlevel\EventSourcing\Aggregate;

use DateTimeImmutable;
use Patchlevel\EventSourcing\Clock;

use function json_decode;
use function json_encode;
Expand Down Expand Up @@ -123,6 +122,6 @@ public function serialize(): array

protected function createRecordDate(): DateTimeImmutable
{
return Clock::createDateTimeImmutable();
return new DateTimeImmutable();
}
}
37 changes: 18 additions & 19 deletions tests/Unit/Aggregate/AggregateChangedTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use DateTimeImmutable;
use Error;
use Patchlevel\EventSourcing\Aggregate\AggregateException;
use Patchlevel\EventSourcing\Clock;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId;
Expand All @@ -17,16 +16,6 @@

class AggregateChangedTest extends TestCase
{
protected function setUp(): void
{
Clock::reset();
}

protected function tearDown(): void
{
Clock::reset();
}

public function testCreateEvent(): void
{
$id = ProfileId::fromString('1');
Expand All @@ -50,9 +39,6 @@ public function testCreateEvent(): void

public function testRecordNow(): void
{
$currentDate = new DateTimeImmutable('2020-01-01 12:00:00');
Clock::freeze($currentDate);

$id = ProfileId::fromString('1');
$email = Email::fromString('d.a.badura@gmail.com');

Expand All @@ -62,7 +48,7 @@ public function testRecordNow(): void
self::assertEquals($id, $recordedEvent->profileId());
self::assertEquals($email, $recordedEvent->email());
self::assertEquals(1, $recordedEvent->playhead());
self::assertEquals($currentDate, $recordedEvent->recordedOn());
self::assertInstanceOf(DateTimeImmutable::class, $recordedEvent->recordedOn());
self::assertEquals(
[
'profileId' => '1',
Expand All @@ -88,14 +74,14 @@ public function testEventAlreadyBeenRecorded(): void

public function testSerialize(): void
{
$currentDate = new DateTimeImmutable('2020-01-01 12:00:00');
Clock::freeze($currentDate);

$id = ProfileId::fromString('1');
$email = Email::fromString('d.a.badura@gmail.com');

$event = ProfileCreated::raise($id, $email);

$beforeRecording = new DateTimeImmutable();
$recordedEvent = $event->recordNow(1);
$afterRecording = new DateTimeImmutable();

$serializedEvent = $recordedEvent->serialize();

Expand All @@ -117,7 +103,11 @@ public function testSerialize(): void
self::assertEquals('{"profileId":"1","email":"d.a.badura@gmail.com"}', $serializedEvent['payload']);

self::assertArrayHasKey('recordedOn', $serializedEvent);
self::assertEquals($currentDate, $serializedEvent['recordedOn']);
self::assertDateTimeImmutableBetween(
$beforeRecording,
$afterRecording,
$serializedEvent['recordedOn'],
);
}

public function testSerializeNotRecorded(): void
Expand Down Expand Up @@ -200,4 +190,13 @@ public function testDeserializeAndSerialize(): void
$event->payload()
);
}

private static function assertDateTimeImmutableBetween(
DateTimeImmutable $fromExpected,
DateTimeImmutable $toExpected,
DateTimeImmutable $actual
): void {
self::assertGreaterThanOrEqual($fromExpected, $actual);
self::assertLessThanOrEqual($toExpected, $actual);
}
}

0 comments on commit 9cf20d1

Please sign in to comment.