Skip to content

Commit

Permalink
Update code for SA
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielBadura committed Feb 5, 2024
1 parent 2235d94 commit d711f36
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 8 deletions.
19 changes: 18 additions & 1 deletion baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.19.0@06b71be009a6bd6d81b9811855d6629b9fe90e1b">
<files psalm-version="5.21.1@8c473e2437be8b6a8fd8f630f0f11a16b114c494">
<file src="src/Aggregate/AggregateRootBehaviour.php">
<UnsafeInstantiation>
<code>new static()</code>
Expand Down Expand Up @@ -188,6 +188,23 @@
<code>$name</code>
</PropertyNotSetInConstructor>
</file>
<file src="tests/Unit/EventBus/MessageTest.php">
<InvalidArgument>
<code><![CDATA[[
'foo' => 'bar',
'aggregateClass' => Profile::class,
'aggregateId' => '1',
'playhead' => 3,
'recordedOn' => $recordedAt,
'newStreamStart' => true,
'archived' => true,
]]]></code>
</InvalidArgument>
<TypeDoesNotContainType>
<code>assertSame</code>
<code>assertSame</code>
</TypeDoesNotContainType>
</file>
<file src="tests/Unit/Fixture/MessageNormalizer.php">
<MixedArgumentTypeCoercion>
<code>$value</code>
Expand Down
9 changes: 8 additions & 1 deletion src/EventBus/Message.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@
/**
* @template-covariant T of object
* @psalm-immutable
* @psalm-type Headers = array{aggregateClass?: class-string<AggregateRoot>, aggregateId?:string, playhead?:positive-int, recordedOn?: DateTimeImmutable, newStreamStart?: bool, archived?: bool}
* @psalm-type Headers = array{
* aggregateClass?: class-string<AggregateRoot>,
* aggregateId?: string,
* playhead?: positive-int,
* recordedOn?: DateTimeImmutable,
* newStreamStart?: bool,
* archived?: bool
* }
*/
final class Message
{
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Aggregate/UuidTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Patchlevel\EventSourcing\Tests\Unit\Aggregate;

use DateTimeInterface;
use Patchlevel\EventSourcing\Aggregate\Uuid;
use PHPUnit\Framework\TestCase;
use Ramsey\Uuid\Uuid as RamseyUuid;
Expand Down Expand Up @@ -40,7 +41,7 @@ public function testV7(): void
{
$factory = new class extends UuidFactory
{
public function uuid7($node = null, int|null $clockSeq = null): UuidInterface
public function uuid7(DateTimeInterface|null $dateTime = null): UuidInterface
{
return RamseyUuid::fromString('018d6a97-6aba-7104-825f-67313a77a2a4');
}
Expand Down
4 changes: 3 additions & 1 deletion tests/Unit/EventBus/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Patchlevel\EventSourcing\Tests\Unit\EventBus;

use DateTimeImmutable;
use Generator;
use Patchlevel\EventSourcing\EventBus\HeaderNotFound;
use Patchlevel\EventSourcing\EventBus\Message;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email;
Expand Down Expand Up @@ -220,7 +221,8 @@ public function testHeaderNotFound(string $headerName): void
$message->{$headerName}();
}

public static function provideHeaderNotFound()
/** @return Generator<string, array{string}> */
public static function provideHeaderNotFound(): Generator
{
yield 'aggregateClass' => ['aggregateClass'];
yield 'aggregateId' => ['aggregateId'];
Expand Down
2 changes: 2 additions & 0 deletions tests/Unit/Lock/DoctrineDbalStoreSchemaAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Patchlevel\EventSourcing\Tests\Unit\Lock;

use Closure;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Schema\Schema;
use Patchlevel\EventSourcing\Lock\DoctrineDbalStoreSchemaAdapter;
Expand All @@ -25,6 +26,7 @@ public function testConfigureSchema(): void
//$store->configureSchema($schema, Argument::type('Closure'))->shouldBeCalledOnce();

$store->configureSchema($schema, Argument::any())->shouldBeCalledOnce()->will(
/** @param array{1: Closure} $args */
static function (array $args): void {
if (!$args[1]()) {
throw new RuntimeException();
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/Snapshot/SnapshotNotConfiguredTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
namespace Patchlevel\EventSourcing\Tests\Unit\Snapshot;

use Patchlevel\EventSourcing\Snapshot\SnapshotNotConfigured;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile;
use PHPUnit\Framework\TestCase;

/** @covers \Patchlevel\EventSourcing\Snapshot\SnapshotNotConfigured */
final class SnapshotNotConfiguredTest extends TestCase
{
public function testCreate(): void
{
$exception = new SnapshotNotConfigured('Foo\Profile');
$exception = new SnapshotNotConfigured(Profile::class);

self::assertSame(
'Missing snapshot configuration for the aggregate class "Foo\Profile"',
'Missing snapshot configuration for the aggregate class "Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile"',
$exception->getMessage(),
);
self::assertSame(0, $exception->getCode());
Expand Down
5 changes: 3 additions & 2 deletions tests/Unit/Snapshot/SnapshotNotFoundTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,20 @@
use Patchlevel\EventSourcing\Aggregate\AggregateRootId;
use Patchlevel\EventSourcing\Aggregate\CustomIdBehaviour;
use Patchlevel\EventSourcing\Snapshot\SnapshotNotFound;
use Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile;
use PHPUnit\Framework\TestCase;

/** @covers \Patchlevel\EventSourcing\Snapshot\SnapshotNotFound */
final class SnapshotNotFoundTest extends TestCase
{
public function testCreate(): void
{
$exception = new SnapshotNotFound('Foo\Profile', new class ('1') implements AggregateRootId {
$exception = new SnapshotNotFound(Profile::class, new class ('1') implements AggregateRootId {
use CustomIdBehaviour;
});

self::assertSame(
'snapshot for aggregate "Foo\Profile" with the id "1" not found',
'snapshot for aggregate "Patchlevel\EventSourcing\Tests\Unit\Fixture\Profile" with the id "1" not found',
$exception->getMessage(),
);
self::assertSame(0, $exception->getCode());
Expand Down

0 comments on commit d711f36

Please sign in to comment.