Skip to content

Commit

Permalink
Refactoring the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
floriankraemer committed Jul 13, 2024
1 parent 3881931 commit 9065316
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.idea
/vendor/
/bin/
/tmp/
/.phpunit.cache/
infection.log
.env

105 changes: 105 additions & 0 deletions tests/EventTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

declare(strict_types=1);

namespace Phauthentic\EventStore\Tests;

use DateTimeImmutable;
use Phauthentic\EventStore\Event;
use Phauthentic\EventStore\EventInterface;
use PHPUnit\Framework\TestCase;

/**
*
*/
class EventTest extends TestCase
{
public function testEventCreation(): void
{
$aggregateId = 'aggregate-id-1';
$aggregateVersion = 1;
$event = 'UserRegistered';
$payload = ['user_id' => 123];
$createdAt = new DateTimeImmutable('now');
$correlationId = 'correlation-id-1';
$stream = 'user-stream';
$metaData = ['key' => 'value'];

$eventObject = new Event(
$aggregateId,
$aggregateVersion,
$event,
$payload,
$createdAt,
$correlationId,
$stream,
$metaData
);

$this->assertInstanceOf(EventInterface::class, $eventObject);
$this->assertEquals($aggregateId, $eventObject->getAggregateId());
$this->assertEquals($aggregateVersion, $eventObject->getAggregateVersion());
$this->assertEquals($event, $eventObject->getEvent());
$this->assertEquals($payload, $eventObject->getPayload());
$this->assertEquals($createdAt, $eventObject->getCreatedAt());
$this->assertEquals($correlationId, $eventObject->getCorrelationId());
$this->assertEquals($stream, $eventObject->getStream());
$this->assertEquals($metaData, $eventObject->getMetaData());
}

public function testDefaultValues(): void
{
$aggregateId = 'aggregate-id-1';
$aggregateVersion = 1;
$event = 'UserRegistered';
$payload = ['user_id' => 123];
$createdAt = new DateTimeImmutable('now');

$eventObject = new Event(
$aggregateId,
$aggregateVersion,
$event,
$payload,
$createdAt
);

$this->assertEquals('', $eventObject->getCorrelationId());
$this->assertNull($eventObject->getStream());
$this->assertEquals([], $eventObject->getMetaData());
}

public function testToArray(): void
{
$aggregateId = 'aggregate-id-1';
$aggregateVersion = 1;
$event = 'UserRegistered';
$payload = ['user_id' => 123];
$createdAt = new DateTimeImmutable('now');
$correlationId = 'correlation-id-1';
$stream = 'user-stream';
$metaData = ['key' => 'value'];

$eventObject = new Event(
$aggregateId,
$aggregateVersion,
$event,
$payload,
$createdAt,
$correlationId,
$stream,
$metaData
);

$expectedArray = [
EventInterface::STREAM => $stream,
EventInterface::AGGREGATE_ID => $aggregateId,
EventInterface::VERSION => $aggregateVersion,
EventInterface::EVENT => $event,
EventInterface::PAYLOAD => $payload,
EventInterface::CREATED_AT => $createdAt->format(EventInterface::CREATED_AT_FORMAT),
EventInterface::CORRELATION_ID => $correlationId
];

$this->assertEquals($expectedArray, $eventObject->toArray());
}
}

0 comments on commit 9065316

Please sign in to comment.