Skip to content

Commit

Permalink
Fix SA
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielBadura committed Mar 27, 2024
1 parent bd1467d commit f11a30f
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 33 deletions.
13 changes: 13 additions & 0 deletions baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,19 @@
<code><![CDATA[ProfileVisited&ProfileCreated $event]]></code>
</ReservedWord>
</file>
<file src="tests/Unit/Store/DoctrineDbalStoreTest.php">
<DeprecatedMethod>
<code><![CDATA[addMethods]]></code>
</DeprecatedMethod>
<InternalMethod>
<code><![CDATA[new DefaultSelectSQLBuilder($abstractPlatform->reveal(), 'FOR UPDATE', 'SKIP LOCKED')]]></code>
<code><![CDATA[new DefaultSelectSQLBuilder($abstractPlatform->reveal(), 'FOR UPDATE', 'SKIP LOCKED')]]></code>
<code><![CDATA[new DefaultSelectSQLBuilder($abstractPlatform->reveal(), 'FOR UPDATE', 'SKIP LOCKED')]]></code>
<code><![CDATA[new DefaultSelectSQLBuilder($abstractPlatform->reveal(), 'FOR UPDATE', 'SKIP LOCKED')]]></code>
<code><![CDATA[new DefaultSelectSQLBuilder($abstractPlatform->reveal(), 'FOR UPDATE', 'SKIP LOCKED')]]></code>
<code><![CDATA[new DefaultSelectSQLBuilder($abstractPlatform->reveal(), 'FOR UPDATE', 'SKIP LOCKED')]]></code>
</InternalMethod>
</file>
<file src="tests/Unit/Subscription/Engine/DefaultSubscriptionEngineTest.php">
<PossiblyUndefinedArrayOffset>
<code><![CDATA[$update1]]></code>
Expand Down
6 changes: 6 additions & 0 deletions src/Store/DoctrineDbalStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,12 @@ private function createTriggerFunctionName(): string
return sprintf('%1$s.notify_%2$s', $tableConfig[0], $tableConfig[1]);
}

/**
* @param array<string> $columns
* @param array<string> $placeholders
* @param list<mixed> $parameters
* @param array<0|positive-int, Type> $types
*/
private function executeSave(array $columns, array $placeholders, array $parameters, array $types, Connection $connection): void
{
$query = sprintf(
Expand Down
87 changes: 54 additions & 33 deletions tests/Unit/Store/DoctrineDbalStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -144,7 +139,7 @@ public function testLoadWithLimitAndOffsetAndIndex(): void
->fromIndex(1)
->build(),
10,
5
5,
);

self::assertSame(null, $stream->index());
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -631,7 +658,7 @@ public function testSaveWithCustomHeaders(): void
{
$customHeaders = [
new FooHeader('foo'),
new BazHeader('baz')
new BazHeader('baz'),
];

$recordedOn = new DateTimeImmutable();
Expand All @@ -642,8 +669,7 @@ public function testSaveWithCustomHeaders(): void
1,
$recordedOn,
))
->withHeaders($customHeaders)
;
->withHeaders($customHeaders);

$innerMockedConnection = $this->prophesize(Connection::class);

Expand Down Expand Up @@ -709,7 +735,7 @@ public function testCount(): void
$doctrineDbalStore = new DoctrineDbalStore(
$connection->reveal(),
$eventSerializer->reveal(),
$headersSerializer->reveal()
$headersSerializer->reveal(),
);

$count = $doctrineDbalStore->count(
Expand Down Expand Up @@ -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())
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -894,7 +917,7 @@ public function testWait(): void
$doctrineDbalStore = new DoctrineDbalStore(
$connection->reveal(),
$eventSerializer->reveal(),
$headersSerializer->reveal()
$headersSerializer->reveal(),
);
$doctrineDbalStore->wait(100);
}
Expand All @@ -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());
Expand All @@ -925,7 +948,7 @@ public function testConfigureSchema(): void
$doctrineDbalStore = new DoctrineDbalStore(
$connection->reveal(),
$eventSerializer->reveal(),
$headersSerializer->reveal()
$headersSerializer->reveal(),
);

$expectedSchema = new Schema();
Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit f11a30f

Please sign in to comment.