Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidBadura committed Feb 6, 2024
1 parent ef1cc8a commit 46328d2
Show file tree
Hide file tree
Showing 18 changed files with 70 additions and 101 deletions.
2 changes: 1 addition & 1 deletion baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@
<InvalidArgument>
<code><![CDATA[[
'foo' => 'bar',
'aggregateClass' => Profile::class,
'aggregateName' => 'profile',
'aggregateId' => '1',
'playhead' => 3,
'recordedOn' => $recordedAt,
Expand Down
2 changes: 1 addition & 1 deletion phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ parameters:
path: src/Console/DoctrineHelper.php

-
message: "#^Method Patchlevel\\\\EventSourcing\\\\EventBus\\\\Message\\:\\:headers\\(\\) should return array\\{aggregateClass\\?\\: class\\-string\\<Patchlevel\\\\EventSourcing\\\\Aggregate\\\\AggregateRoot\\>, aggregateId\\?\\: string, playhead\\?\\: int\\<1, max\\>, recordedOn\\?\\: DateTimeImmutable, newStreamStart\\?\\: bool, archived\\?\\: bool\\} but returns non\\-empty\\-array\\<string, mixed\\>\\.$#"
message: "#^Method Patchlevel\\\\EventSourcing\\\\EventBus\\\\Message\\:\\:headers\\(\\) should return array\\{aggregateName\\?\\: string, aggregateId\\?\\: string, playhead\\?\\: int\\<1, max\\>, recordedOn\\?\\: DateTimeImmutable, newStreamStart\\?\\: bool, archived\\?\\: bool\\} but returns non\\-empty\\-array\\<string, mixed\\>\\.$#"
count: 1
path: src/EventBus/Message.php

Expand Down
4 changes: 2 additions & 2 deletions src/Console/OutputStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ public function message(EventSerializer $serializer, Message $message): void

$this->horizontalTable([
'eventClass',
'aggregateClass',
'aggregateName',
'aggregateId',
'playhead',
'recordedOn',
], [
[
$event::class,
$message->aggregateClass(),
$message->aggregateName(),
$message->aggregateId(),
$message->playhead(),
$message->recordedOn()->format(DateTimeInterface::ATOM),
Expand Down
2 changes: 0 additions & 2 deletions tests/Benchmark/SimpleSetupBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Patchlevel\EventSourcing\Aggregate\AggregateRootId;
use Patchlevel\EventSourcing\EventBus\DefaultEventBus;
use Patchlevel\EventSourcing\EventBus\EventBus;
use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory;
use Patchlevel\EventSourcing\Repository\DefaultRepository;
use Patchlevel\EventSourcing\Repository\Repository;
use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector;
Expand Down Expand Up @@ -50,7 +49,6 @@ public function setUp(): void
$this->store = new DoctrineDbalStore(
$connection,
DefaultEventSerializer::createFromPaths([__DIR__ . '/BasicImplementation/Events']),
(new AttributeAggregateRootRegistryFactory())->create([__DIR__ . '/BasicImplementation/Aggregate']),
'eventstore',
);

Expand Down
2 changes: 0 additions & 2 deletions tests/Benchmark/SnapshotsBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Patchlevel\EventSourcing\Aggregate\AggregateRootId;
use Patchlevel\EventSourcing\EventBus\DefaultEventBus;
use Patchlevel\EventSourcing\EventBus\EventBus;
use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory;
use Patchlevel\EventSourcing\Repository\DefaultRepository;
use Patchlevel\EventSourcing\Repository\Repository;
use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector;
Expand Down Expand Up @@ -56,7 +55,6 @@ public function setUp(): void
$this->store = new DoctrineDbalStore(
$connection,
DefaultEventSerializer::createFromPaths([__DIR__ . '/BasicImplementation/Events']),
(new AttributeAggregateRootRegistryFactory())->create([__DIR__ . '/BasicImplementation/Aggregate']),
'eventstore',
);

Expand Down
2 changes: 0 additions & 2 deletions tests/Benchmark/SplitStreamBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use Patchlevel\EventSourcing\EventBus\Decorator\SplitStreamDecorator;
use Patchlevel\EventSourcing\EventBus\DefaultEventBus;
use Patchlevel\EventSourcing\EventBus\EventBus;
use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory;
use Patchlevel\EventSourcing\Metadata\Event\AttributeEventMetadataFactory;
use Patchlevel\EventSourcing\Repository\DefaultRepository;
use Patchlevel\EventSourcing\Repository\Repository;
Expand Down Expand Up @@ -55,7 +54,6 @@ public function setUp(): void
$this->store = new DoctrineDbalStore(
$connection,
DefaultEventSerializer::createFromPaths([__DIR__ . '/BasicImplementation/Events']),
(new AttributeAggregateRootRegistryFactory())->create([__DIR__ . '/BasicImplementation/Aggregate']),
'eventstore',
);

Expand Down
2 changes: 0 additions & 2 deletions tests/Benchmark/SyncProjectionistBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Patchlevel\EventSourcing\EventBus\DefaultEventBus;
use Patchlevel\EventSourcing\EventBus\EventBus;
use Patchlevel\EventSourcing\Lock\DoctrineDbalStoreSchemaAdapter;
use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory;
use Patchlevel\EventSourcing\Projection\Projection\Store\InMemoryStore;
use Patchlevel\EventSourcing\Projection\Projectionist\DefaultProjectionist;
use Patchlevel\EventSourcing\Projection\Projectionist\SyncProjectionistEventBusWrapper;
Expand Down Expand Up @@ -58,7 +57,6 @@ public function setUp(): void
$this->store = new DoctrineDbalStore(
$connection,
DefaultEventSerializer::createFromPaths([__DIR__ . '/BasicImplementation/Events']),
(new AttributeAggregateRootRegistryFactory())->create([__DIR__ . '/BasicImplementation/Aggregate']),
'eventstore',
);

Expand Down
2 changes: 0 additions & 2 deletions tests/Benchmark/blackfire.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Doctrine\DBAL\Driver\PDO\SQLite\Driver;
use Doctrine\DBAL\DriverManager;
use Patchlevel\EventSourcing\EventBus\DefaultEventBus;
use Patchlevel\EventSourcing\Metadata\AggregateRoot\AttributeAggregateRootRegistryFactory;
use Patchlevel\EventSourcing\Repository\DefaultRepository;
use Patchlevel\EventSourcing\Schema\DoctrineSchemaDirector;
use Patchlevel\EventSourcing\Serializer\DefaultEventSerializer;
Expand All @@ -31,7 +30,6 @@
$store = new DoctrineDbalStore(
$connection,
DefaultEventSerializer::createFromPaths([__DIR__ . '/BasicImplementation/Events']),
(new AttributeAggregateRootRegistryFactory())->create([__DIR__ . '/BasicImplementation/Aggregate']),
'eventstore',
);

Expand Down
5 changes: 2 additions & 3 deletions tests/Unit/Console/Command/OutboxInfoCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Patchlevel\EventSourcing\Serializer\Encoder\Encoder;
use Patchlevel\EventSourcing\Serializer\EventSerializer;
use Patchlevel\EventSourcing\Serializer\SerializedEvent;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileVisited;
use PHPUnit\Framework\TestCase;
Expand All @@ -31,7 +30,7 @@ public function testSuccessful(): void
$store = $this->prophesize(OutboxStore::class);
$store->retrieveOutboxMessages(null)->willReturn([
Message::create($event)
->withAggregateClass(Profile::class)
->withAggregateName('profile')
->withAggregateId('1')
->withPlayhead(1)
->withRecordedOn(new DateTimeImmutable()),
Expand Down Expand Up @@ -69,7 +68,7 @@ public function testSuccessfulWithLimit(): void
$store = $this->prophesize(OutboxStore::class);
$store->retrieveOutboxMessages(100)->willReturn([
Message::create($event)
->withAggregateClass(Profile::class)
->withAggregateName('profile')
->withAggregateId('1')
->withPlayhead(1)
->withRecordedOn(new DateTimeImmutable()),
Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/Console/Command/ShowAggregateCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testSuccessful(): void
$store->load(new Criteria(Profile::class, '1'))->willReturn(
new ArrayStream([
Message::create($event)
->withAggregateClass(Profile::class)
->withAggregateName('profile')
->withAggregateId('1')
->withPlayhead(1)
->withRecordedOn(new DateTimeImmutable()),
Expand Down Expand Up @@ -214,7 +214,7 @@ public function testInteractiveSuccessful(): void
$store->load(new Criteria(Profile::class, '1'))->willReturn(
new ArrayStream([
Message::create($event)
->withAggregateClass(Profile::class)
->withAggregateName('profile')
->withAggregateId('1')
->withPlayhead(1)
->withRecordedOn(new DateTimeImmutable()),
Expand Down
3 changes: 1 addition & 2 deletions tests/Unit/Console/OutputStyleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Patchlevel\EventSourcing\Serializer\EventSerializer;
use Patchlevel\EventSourcing\Serializer\SerializedEvent;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId;
use PHPUnit\Framework\TestCase;
Expand Down Expand Up @@ -41,7 +40,7 @@ public function testWrite(): void
));

$message = Message::create($event)
->withAggregateClass(Profile::class)
->withAggregateName('profile')
->withAggregateId('1')
->withPlayhead(1)
->withRecordedOn(new DateTimeImmutable());
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/EventBus/HeaderNotFoundTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
/** @covers \Patchlevel\EventSourcing\EventBus\HeaderNotFound */
final class HeaderNotFoundTest extends TestCase
{
public function testAggregateClass(): void
public function testAggregateName(): void
{
self::assertSame(
'message header "aggregateClass" is not defined',
HeaderNotFound::aggregateClass()->getMessage(),
'message header "aggregateName" is not defined',
HeaderNotFound::aggregateName()->getMessage(),
);
}

Expand Down
15 changes: 7 additions & 8 deletions tests/Unit/EventBus/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use Patchlevel\EventSourcing\EventBus\HeaderNotFound;
use Patchlevel\EventSourcing\EventBus\Message;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId;
use PHPUnit\Framework\Attributes\DataProvider;
Expand All @@ -34,9 +33,9 @@ public function testCreateMessageWithAggregateHeader(): void
{
$message = Message::create(new class {
})
->withAggregateClass(Profile::class);
->withAggregateName('profile');

self::assertSame(Profile::class, $message->aggregateClass());
self::assertSame('profile', $message->aggregateName());
}

public function testCreateMessageWithAggregateIdHeader(): void
Expand Down Expand Up @@ -143,7 +142,7 @@ public function testAllHeaders(): void

$message = Message::create(new class {
})
->withAggregateClass(Profile::class)
->withAggregateName('profile')
->withAggregateId('1')
->withPlayhead(3)
->withRecordedOn($recordedAt)
Expand All @@ -154,7 +153,7 @@ public function testAllHeaders(): void
self::assertSame(
[
'foo' => 'bar',
'aggregateClass' => Profile::class,
'aggregateName' => 'profile',
'aggregateId' => '1',
'playhead' => 3,
'recordedOn' => $recordedAt,
Expand Down Expand Up @@ -187,7 +186,7 @@ public function testCreateWithAllHeaders(): void
},
[
'foo' => 'bar',
'aggregateClass' => Profile::class,
'aggregateName' => 'profile',
'aggregateId' => '1',
'playhead' => 3,
'recordedOn' => $recordedAt,
Expand All @@ -199,7 +198,7 @@ public function testCreateWithAllHeaders(): void
self::assertSame(
[
'foo' => 'bar',
'aggregateClass' => Profile::class,
'aggregateName' => 'profile',
'aggregateId' => '1',
'playhead' => 3,
'recordedOn' => $recordedAt,
Expand All @@ -224,7 +223,7 @@ public function testHeaderNotFound(string $headerName): void
/** @return Generator<string, array{string}> */
public static function provideHeaderNotFound(): Generator
{
yield 'aggregateClass' => ['aggregateClass'];
yield 'aggregateName' => ['aggregateName'];
yield 'aggregateId' => ['aggregateId'];
yield 'playhead' => ['playhead'];
yield 'recordedOn' => ['recordedOn'];
Expand Down
15 changes: 3 additions & 12 deletions tests/Unit/Outbox/DoctrineOutboxStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,11 @@
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Types\Types;
use Patchlevel\EventSourcing\EventBus\Message;
use Patchlevel\EventSourcing\Metadata\AggregateRoot\AggregateRootRegistry;
use Patchlevel\EventSourcing\Outbox\DoctrineOutboxStore;
use Patchlevel\EventSourcing\Serializer\EventSerializer;
use Patchlevel\EventSourcing\Serializer\SerializedEvent;
use Patchlevel\EventSourcing\Store\WrongQueryResult;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileId;
use PHPUnit\Framework\TestCase;
Expand All @@ -36,7 +34,7 @@ public function testSaveOutboxMessage(): void
{
$recordedOn = new DateTimeImmutable();
$message = Message::create(new ProfileCreated(ProfileId::fromString('1'), Email::fromString('s')))
->withAggregateClass(Profile::class)
->withAggregateName('profile')
->withAggregateId('1')
->withPlayhead(1)
->withRecordedOn($recordedOn)
Expand Down Expand Up @@ -73,7 +71,6 @@ public function testSaveOutboxMessage(): void
$doctrineOutboxStore = new DoctrineOutboxStore(
$mockedConnection->reveal(),
$serializer->reveal(),
new AggregateRootRegistry(['profile' => Profile::class]),
);

$doctrineOutboxStore->saveOutboxMessage($message);
Expand All @@ -83,7 +80,7 @@ public function testMarkOutboxMessageConsumed(): void
{
$recordedOn = new DateTimeImmutable();
$message = Message::create(new ProfileCreated(ProfileId::fromString('1'), Email::fromString('s')))
->withAggregateClass(Profile::class)
->withAggregateName('profile')
->withAggregateId('1')
->withPlayhead(1)
->withRecordedOn($recordedOn)
Expand All @@ -110,7 +107,6 @@ public function testMarkOutboxMessageConsumed(): void
$doctrineOutboxStore = new DoctrineOutboxStore(
$mockedConnection->reveal(),
$serializer->reveal(),
new AggregateRootRegistry(['profile' => Profile::class]),
);

$doctrineOutboxStore->markOutboxMessageConsumed($message);
Expand All @@ -132,7 +128,6 @@ public function testCountOutboxMessages(): void
$doctrineOutboxStore = new DoctrineOutboxStore(
$connection->reveal(),
$serializer->reveal(),
new AggregateRootRegistry(['profile' => Profile::class]),
);

$result = $doctrineOutboxStore->countOutboxMessages();
Expand All @@ -155,7 +150,6 @@ public function testCountOutboxMessagesFailure(): void
$doctrineOutboxStore = new DoctrineOutboxStore(
$connection->reveal(),
$serializer->reveal(),
new AggregateRootRegistry(['profile' => Profile::class]),
);

$this->expectException(WrongQueryResult::class);
Expand Down Expand Up @@ -183,7 +177,6 @@ public function testRetrieveOutboxMessagesNoResult(): void
$doctrineOutboxStore = new DoctrineOutboxStore(
$connection->reveal(),
$serializer->reveal(),
new AggregateRootRegistry(['profile' => Profile::class]),
);

$messages = $doctrineOutboxStore->retrieveOutboxMessages();
Expand All @@ -195,7 +188,7 @@ public function testRetrieveOutboxMessages(): void
$recordedOn = new DateTimeImmutable();
$event = new ProfileCreated(ProfileId::fromString('1'), Email::fromString('s'));
$message = Message::create($event)
->withAggregateClass(Profile::class)
->withAggregateName('profile')
->withAggregateId('1')
->withPlayhead(1)
->withRecordedOn($recordedOn)
Expand Down Expand Up @@ -233,7 +226,6 @@ public function testRetrieveOutboxMessages(): void
$doctrineOutboxStore = new DoctrineOutboxStore(
$connection->reveal(),
$serializer->reveal(),
new AggregateRootRegistry(['profile' => Profile::class]),
);

$messages = $doctrineOutboxStore->retrieveOutboxMessages();
Expand All @@ -248,7 +240,6 @@ public function testConfigureSchema(): void
$doctrineOutboxStore = new DoctrineOutboxStore(
$connection->reveal(),
$serializer->reveal(),
new AggregateRootRegistry(['profile' => Profile::class]),
);

$table = $this->prophesize(Table::class);
Expand Down
Loading

0 comments on commit 46328d2

Please sign in to comment.