Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add failing test for serializing created_at event property #471

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions tests/EventSerializers/EventSerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@

use function PHPUnit\Framework\assertEquals;
use function PHPUnit\Framework\assertInstanceOf;
use function PHPUnit\Framework\assertStringContainsString;

use Spatie\EventSourcing\EventSerializers\EventSerializer;
use Spatie\EventSourcing\Tests\TestClasses\Events\EventWithArray;
use Spatie\EventSourcing\Tests\TestClasses\Events\EventWithCarbon;
use Spatie\EventSourcing\Tests\TestClasses\Events\EventWithDatetime;
use Spatie\EventSourcing\Tests\TestClasses\Events\EventWithDocblock;
use Spatie\EventSourcing\Tests\TestClasses\Events\EventWithoutSerializedModels;
use Spatie\EventSourcing\Tests\TestClasses\Events\EventWithCreatedAtProperty;
use Spatie\EventSourcing\Tests\TestClasses\Events\MoneyAddedEvent;
use Spatie\EventSourcing\Tests\TestClasses\EventSerializer\UpgradeSerializer;
use Spatie\EventSourcing\Tests\TestClasses\Models\Account;
Expand Down Expand Up @@ -74,6 +76,18 @@
assertInstanceOf(DateTimeImmutable::class, $normalizedEvent->value);
});

it('does not modify `created_at` event properties', function() {
$event = new EventWithCreatedAtProperty('2020-01-01 00:00:00');

$json = $this->eventSerializer->serialize($event);

assertEquals('{"created_at":"2020-01-01 00:00:00"}', $json);

$normalizedEvent = $this->eventSerializer->deserialize(get_class($event), $json, 1);

assertEquals('2020-01-01 00:00:00', $normalizedEvent->created_at);
});

it('can deserialize an event with carbon', function () {
$event = new EventWithCarbon(Carbon::now());

Expand Down
15 changes: 15 additions & 0 deletions tests/TestClasses/Events/EventWithCreatedAtProperty.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace Spatie\EventSourcing\Tests\TestClasses\Events;

use Spatie\EventSourcing\StoredEvents\ShouldBeStored;

class EventWithCreatedAtProperty extends ShouldBeStored
{
public string $created_at;

public function __construct(string $created_at)
{
$this->created_at = $created_at;
}
}
Loading