Skip to content

Commit

Permalink
Merge pull request #64 from patchlevel/1.2.x-merge-up-into-1.3.x_5dZj…
Browse files Browse the repository at this point in the history
…k3NU

Merge release 1.2.1 into 1.3.x
  • Loading branch information
DanielBadura committed Jan 31, 2022
2 parents 852dfa8 + a5dc61e commit 6ccb3e8
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 44 deletions.
19 changes: 12 additions & 7 deletions src/DataCollector/EventCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use Patchlevel\EventSourcing\Aggregate\AggregateChanged;
use Patchlevel\EventSourcing\Aggregate\AggregateRoot;
use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\DataCollector\DataCollector;
use Symfony\Component\VarDumper\Cloner\Data;
use Throwable;

Expand All @@ -23,7 +23,7 @@
* }
* @psalm-property DataType $data
*/
final class EventCollector extends AbstractDataCollector
final class EventCollector extends DataCollector
{
private EventListener $eventListener;
/** @var array<class-string<AggregateRoot>, string> */
Expand Down Expand Up @@ -59,11 +59,6 @@ function (AggregateChanged $event) {
];
}

public static function getTemplate(): string
{
return '@PatchlevelEventSourcing/Collector/template.html.twig';
}

/**
* @return list<array{class: class-string<AggregateChanged>, aggregateId: string, payload: Data, playhead: int, recordedOn: string}>
*/
Expand All @@ -79,4 +74,14 @@ public function getAggregates(): array
{
return $this->data['aggregates'];
}

public function getName(): string
{
return static::class;
}

public function reset(): void
{
$this->data = [];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ private function configureProfiler(ContainerBuilder $container): void
new Reference(EventListener::class),
'%event_sourcing.aggregates%',
])
->addTag('data_collector');
->addTag('data_collector', ['template' => '@PatchlevelEventSourcing/Collector/template.html.twig']);
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/Fixtures/ProfileCreated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Patchlevel\EventSourcingBundle\Tests\Fixtures;

use Patchlevel\EventSourcing\Aggregate\AggregateChanged;

class ProfileCreated extends AggregateChanged
{
public static function raise(string $id): static
{
return new static($id);
}
}
36 changes: 0 additions & 36 deletions tests/Unit/AggregateAttributeLoaderTest.php

This file was deleted.

37 changes: 37 additions & 0 deletions tests/Unit/DataCollector/EventCollectorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types=1);

namespace Patchlevel\EventSourcingBundle\Tests\Unit\DataCollector;

use Patchlevel\EventSourcingBundle\DataCollector\EventCollector;
use Patchlevel\EventSourcingBundle\DataCollector\EventListener;
use Patchlevel\EventSourcingBundle\Tests\Fixtures\Profile;
use Patchlevel\EventSourcingBundle\Tests\Fixtures\ProfileCreated;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class EventCollectorTest extends TestCase
{
public function testCollectData(): void
{
$eventListener = new EventListener();

$collector = new EventCollector(
$eventListener,
[Profile::class => 'profile']
);

$event = ProfileCreated::raise('foo');
$eventListener($event);

$collector->collect(
new Request(),
new Response()
);

self::assertSame([Profile::class => 'profile'], $collector->getAggregates());
self::assertCount(1, $collector->getEvents());
}
}
32 changes: 32 additions & 0 deletions tests/Unit/Loader/AggregateAttributeLoaderTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Patchlevel\EventSourcingBundle\Tests\Unit\Loader;

use InvalidArgumentException;
use Patchlevel\EventSourcingBundle\Loader\AggregateAttributesLoader;
use PHPUnit\Framework\TestCase;

class AggregateAttributeLoaderTest extends TestCase
{
public function testDuplicateAggregateName()
{
$this->expectException(InvalidArgumentException::class);

$loader = new AggregateAttributesLoader();
$loader->load([
__DIR__ . '/../../Fixtures/AttributedAggregatesSameName'
]);
}

public function testLoadPathWithAttributedAggregates()
{
$loader = new AggregateAttributesLoader();
$result = $loader->load([
__DIR__ . '/../../Fixtures/AttributedAggregates'
]);

self::assertCount(2, $result);
}
}

0 comments on commit 6ccb3e8

Please sign in to comment.