From f11a30fb098b0c8c449cb425f7aaacc4b9ba81a8 Mon Sep 17 00:00:00 2001 From: Daniel Badura Date: Wed, 27 Mar 2024 15:13:45 +0100 Subject: [PATCH] Fix SA --- baseline.xml | 13 ++++ src/Store/DoctrineDbalStore.php | 6 ++ tests/Unit/Store/DoctrineDbalStoreTest.php | 87 ++++++++++++++-------- 3 files changed, 73 insertions(+), 33 deletions(-) diff --git a/baseline.xml b/baseline.xml index 7adc6fbc3..6ab928c76 100644 --- a/baseline.xml +++ b/baseline.xml @@ -286,6 +286,19 @@ + + + + + + reveal(), 'FOR UPDATE', 'SKIP LOCKED')]]> + reveal(), 'FOR UPDATE', 'SKIP LOCKED')]]> + reveal(), 'FOR UPDATE', 'SKIP LOCKED')]]> + reveal(), 'FOR UPDATE', 'SKIP LOCKED')]]> + reveal(), 'FOR UPDATE', 'SKIP LOCKED')]]> + reveal(), 'FOR UPDATE', 'SKIP LOCKED')]]> + + diff --git a/src/Store/DoctrineDbalStore.php b/src/Store/DoctrineDbalStore.php index 92954270b..437d0ca27 100644 --- a/src/Store/DoctrineDbalStore.php +++ b/src/Store/DoctrineDbalStore.php @@ -372,6 +372,12 @@ private function createTriggerFunctionName(): string return sprintf('%1$s.notify_%2$s', $tableConfig[0], $tableConfig[1]); } + /** + * @param array $columns + * @param array $placeholders + * @param list $parameters + * @param array<0|positive-int, Type> $types + */ private function executeSave(array $columns, array $placeholders, array $parameters, array $types, Connection $connection): void { $query = sprintf( diff --git a/tests/Unit/Store/DoctrineDbalStoreTest.php b/tests/Unit/Store/DoctrineDbalStoreTest.php index aa61c062d..500a52b19 100644 --- a/tests/Unit/Store/DoctrineDbalStoreTest.php +++ b/tests/Unit/Store/DoctrineDbalStoreTest.php @@ -12,13 +12,9 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Query\QueryBuilder; -use Doctrine\DBAL\Query\SelectQuery; use Doctrine\DBAL\Result; -use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Schema; -use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\SQL\Builder\DefaultSelectSQLBuilder; -use Doctrine\DBAL\SQL\Builder\SelectSQLBuilder; use Doctrine\DBAL\Statement; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; @@ -34,7 +30,6 @@ use Patchlevel\EventSourcing\Store\UniqueConstraintViolation; use Patchlevel\EventSourcing\Store\WrongQueryResult; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Email; -use Patchlevel\EventSourcing\Tests\Unit\Fixture\EmailChanged; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Header\BazHeader; use Patchlevel\EventSourcing\Tests\Unit\Fixture\Header\FooHeader; use Patchlevel\EventSourcing\Tests\Unit\Fixture\ProfileCreated; @@ -144,7 +139,7 @@ public function testLoadWithLimitAndOffsetAndIndex(): void ->fromIndex(1) ->build(), 10, - 5 + 5, ); self::assertSame(null, $stream->index()); @@ -482,8 +477,24 @@ public function testSaveWithTwoEvents(): void $innerMockedConnection->executeStatement( "INSERT INTO eventstore (aggregate, aggregate_id, playhead, event, payload, recorded_on, new_stream_start, archived, custom_headers) VALUES\n(?, ?, ?, ?, ?, ?, ?, ?, ?),\n(?, ?, ?, ?, ?, ?, ?, ?, ?)", [ - 'profile', '1', 1, 'profile_created', '', $recordedOn, false, false, [], - 'profile', '1', 2, 'profile_email_changed', '', $recordedOn, false, false, [], + 'profile', + '1', + 1, + 'profile_created', + '', + $recordedOn, + false, + false, + [], + 'profile', + '1', + 2, + 'profile_email_changed', + '', + $recordedOn, + false, + false, + [], ], [ 5 => Type::getType(Types::DATETIMETZ_IMMUTABLE), @@ -544,8 +555,24 @@ public function testSaveWithUniqueConstraintViolation(): void $innerMockedConnection->executeStatement( "INSERT INTO eventstore (aggregate, aggregate_id, playhead, event, payload, recorded_on, new_stream_start, archived, custom_headers) VALUES\n(?, ?, ?, ?, ?, ?, ?, ?, ?),\n(?, ?, ?, ?, ?, ?, ?, ?, ?)", [ - 'profile', '1', 1, 'profile_created', '', $recordedOn, false, false, [], - 'profile', '1', 1, 'profile_created', '', $recordedOn, false, false, [], + 'profile', + '1', + 1, + 'profile_created', + '', + $recordedOn, + false, + false, + [], + 'profile', + '1', + 1, + 'profile_created', + '', + $recordedOn, + false, + false, + [], ], [ 5 => Type::getType(Types::DATETIMETZ_IMMUTABLE), @@ -631,7 +658,7 @@ public function testSaveWithCustomHeaders(): void { $customHeaders = [ new FooHeader('foo'), - new BazHeader('baz') + new BazHeader('baz'), ]; $recordedOn = new DateTimeImmutable(); @@ -642,8 +669,7 @@ public function testSaveWithCustomHeaders(): void 1, $recordedOn, )) - ->withHeaders($customHeaders) - ; + ->withHeaders($customHeaders); $innerMockedConnection = $this->prophesize(Connection::class); @@ -709,7 +735,7 @@ public function testCount(): void $doctrineDbalStore = new DoctrineDbalStore( $connection->reveal(), $eventSerializer->reveal(), - $headersSerializer->reveal() + $headersSerializer->reveal(), ); $count = $doctrineDbalStore->count( @@ -751,10 +777,9 @@ public function testCountWrongResult(): void $doctrineDbalStore = new DoctrineDbalStore( $connection->reveal(), $eventSerializer->reveal(), - $headersSerializer->reveal() + $headersSerializer->reveal(), ); - $this->expectException(WrongQueryResult::class); $doctrineDbalStore->count( (new CriteriaBuilder()) @@ -779,9 +804,9 @@ public function testSetupSubscription(): void $$ LANGUAGE plpgsql; SQL, )->shouldBeCalledOnce()->willReturn(1); - $connection->executeStatement("DROP TRIGGER IF EXISTS notify_trigger ON eventstore;") + $connection->executeStatement('DROP TRIGGER IF EXISTS notify_trigger ON eventstore;') ->shouldBeCalledOnce()->willReturn(1); - $connection->executeStatement("CREATE TRIGGER notify_trigger AFTER INSERT OR UPDATE ON eventstore FOR EACH ROW EXECUTE PROCEDURE notify_eventstore();") + $connection->executeStatement('CREATE TRIGGER notify_trigger AFTER INSERT OR UPDATE ON eventstore FOR EACH ROW EXECUTE PROCEDURE notify_eventstore();') ->shouldBeCalledOnce()->willReturn(1); $abstractPlatform = $this->prophesize(PostgreSQLPlatform::class); @@ -793,10 +818,9 @@ public function testSetupSubscription(): void $doctrineDbalStore = new DoctrineDbalStore( $connection->reveal(), $eventSerializer->reveal(), - $headersSerializer->reveal() + $headersSerializer->reveal(), ); $doctrineDbalStore->setupSubscription(); - } public function testSetupSubscriptionWithOtherStoreTableName(): void @@ -812,9 +836,9 @@ public function testSetupSubscriptionWithOtherStoreTableName(): void $$ LANGUAGE plpgsql; SQL, )->shouldBeCalledOnce()->willReturn(1); - $connection->executeStatement("DROP TRIGGER IF EXISTS notify_trigger ON new.eventstore;") + $connection->executeStatement('DROP TRIGGER IF EXISTS notify_trigger ON new.eventstore;') ->shouldBeCalledOnce()->willReturn(1); - $connection->executeStatement("CREATE TRIGGER notify_trigger AFTER INSERT OR UPDATE ON new.eventstore FOR EACH ROW EXECUTE PROCEDURE new.notify_eventstore();") + $connection->executeStatement('CREATE TRIGGER notify_trigger AFTER INSERT OR UPDATE ON new.eventstore FOR EACH ROW EXECUTE PROCEDURE new.notify_eventstore();') ->shouldBeCalledOnce()->willReturn(1); $abstractPlatform = $this->prophesize(PostgreSQLPlatform::class); @@ -827,11 +851,11 @@ public function testSetupSubscriptionWithOtherStoreTableName(): void $connection->reveal(), $eventSerializer->reveal(), $headersSerializer->reveal(), - 'new.eventstore' + 'new.eventstore', ); $doctrineDbalStore->setupSubscription(); - } + public function testSetupSubscriptionNotPostgres(): void { $connection = $this->prophesize(Connection::class); @@ -845,9 +869,9 @@ public function testSetupSubscriptionNotPostgres(): void $$ LANGUAGE plpgsql; SQL, )->shouldNotBeCalled(); - $connection->executeStatement("DROP TRIGGER IF EXISTS notify_trigger ON eventstore;") + $connection->executeStatement('DROP TRIGGER IF EXISTS notify_trigger ON eventstore;') ->shouldNotBeCalled(); - $connection->executeStatement("CREATE TRIGGER notify_trigger AFTER INSERT OR UPDATE ON eventstore FOR EACH ROW EXECUTE PROCEDURE notify_eventstore();") + $connection->executeStatement('CREATE TRIGGER notify_trigger AFTER INSERT OR UPDATE ON eventstore FOR EACH ROW EXECUTE PROCEDURE notify_eventstore();') ->shouldNotBeCalled(); $abstractPlatform = $this->prophesize(AbstractPlatform::class); @@ -859,10 +883,9 @@ public function testSetupSubscriptionNotPostgres(): void $doctrineDbalStore = new DoctrineDbalStore( $connection->reveal(), $eventSerializer->reveal(), - $headersSerializer->reveal() + $headersSerializer->reveal(), ); $doctrineDbalStore->setupSubscription(); - } public function testWait(): void @@ -894,7 +917,7 @@ public function testWait(): void $doctrineDbalStore = new DoctrineDbalStore( $connection->reveal(), $eventSerializer->reveal(), - $headersSerializer->reveal() + $headersSerializer->reveal(), ); $doctrineDbalStore->wait(100); } @@ -908,7 +931,7 @@ public function testConfigureSchemaWithDifferentConnections(): void $doctrineDbalStore = new DoctrineDbalStore( $connection->reveal(), $eventSerializer->reveal(), - $headersSerializer->reveal() + $headersSerializer->reveal(), ); $schema = new Schema(); $doctrineDbalStore->configureSchema($schema, $this->prophesize(Connection::class)->reveal()); @@ -925,7 +948,7 @@ public function testConfigureSchema(): void $doctrineDbalStore = new DoctrineDbalStore( $connection->reveal(), $eventSerializer->reveal(), - $headersSerializer->reveal() + $headersSerializer->reveal(), ); $expectedSchema = new Schema(); @@ -961,14 +984,12 @@ public function testConfigureSchema(): void $table->addUniqueIndex(['aggregate', 'aggregate_id', 'playhead']); $table->addIndex(['aggregate', 'aggregate_id', 'playhead', 'archived']); - $schema = new Schema(); $doctrineDbalStore->configureSchema($schema, $connection->reveal()); self::assertEquals($expectedSchema, $schema); } - #[RequiresPhp('>= 8.2')] public function testArchiveMessages(): void {