diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 2ff13a7..695326b 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -66,7 +66,7 @@ jobs: - name: Run tests (SQLIte) run: composer run-script test env: - DB_DSN: "sqlite:///events_test.sqlite" + DB_DSN: "pdo-sqlite:///events_test.sqlite" - name: Run tests (MySQL) run: composer run-script test diff --git a/composer.json b/composer.json index 850b690..9ead0bb 100644 --- a/composer.json +++ b/composer.json @@ -1,54 +1,54 @@ { - "name": "neos/eventstore-doctrineadapter", - "description": "Doctrine DBAL based implementation for the neos/eventstore", - "type": "library", - "license": "MIT", - "funding": [ - { - "type": "other", - "url": "https://www.neos.io/community/participate/supporting-neos.html" - } - ], - "require": { - "php": "^8.1", - "neos/eventstore": "^1", - "doctrine/dbal": "^3", - "webmozart/assert": "^1.10", - "psr/clock": "^1" - }, - "require-dev": { - "roave/security-advisories": "dev-latest", - "phpstan/phpstan": "^1.10", - "squizlabs/php_codesniffer": "^4.0.x-dev", - "phpunit/phpunit": "^10", - "brianium/paratest": "^7.2" - }, - "autoload": { - "psr-4": { - "Neos\\EventStore\\DoctrineAdapter\\": "src/" - } - }, - "autoload-dev": { - "psr-4": { - "Neos\\EventStore\\DoctrineAdapter\\Tests\\": "tests/", - "Neos\\EventStore\\Tests\\": "vendor/neos/eventstore/tests/" - } - }, - "scripts": { - "test:phpstan": "phpstan", - "test:cs": "phpcs --colors src", - "test:cs:fix": "phpcbf --colors src", - "test:integration": "phpunit tests/Integration --exclude-group=parallel", - "test:consistency": [ - "Neos\\EventStore\\DoctrineAdapter\\Tests\\Integration\\DoctrineEventStoreTest::consistency_prepare", - "paratest tests/Integration --group=parallel --functional --processes 10", - "Neos\\EventStore\\DoctrineAdapter\\Tests\\Integration\\DoctrineEventStoreTest::consistency_validateEvents" - ], - "test": [ - "@test:phpstan", - "@test:cs", - "@test:integration", - "@test:consistency" - ] + "name": "neos/eventstore-doctrineadapter", + "description": "Doctrine DBAL based implementation for the neos/eventstore", + "type": "library", + "license": "MIT", + "funding": [ + { + "type": "other", + "url": "https://www.neos.io/community/participate/supporting-neos.html" + } + ], + "require": { + "php": "^8.1", + "neos/eventstore": "^1", + "doctrine/dbal": "^3.8", + "webmozart/assert": "^1.10", + "psr/clock": "^1" + }, + "require-dev": { + "roave/security-advisories": "dev-latest", + "phpstan/phpstan": "^1.10", + "squizlabs/php_codesniffer": "^4.0.x-dev", + "phpunit/phpunit": "^10", + "brianium/paratest": "^7.2" + }, + "autoload": { + "psr-4": { + "Neos\\EventStore\\DoctrineAdapter\\": "src/" } + }, + "autoload-dev": { + "psr-4": { + "Neos\\EventStore\\DoctrineAdapter\\Tests\\": "tests/", + "Neos\\EventStore\\Tests\\": "vendor/neos/eventstore/tests/" + } + }, + "scripts": { + "test:phpstan": "phpstan", + "test:cs": "phpcs --colors src", + "test:cs:fix": "phpcbf --colors src", + "test:integration": "phpunit tests/Integration --exclude-group=parallel", + "test:consistency": [ + "Neos\\EventStore\\DoctrineAdapter\\Tests\\Integration\\DoctrineEventStoreTest::consistency_prepare", + "paratest tests/Integration --group=parallel --functional --processes 10", + "Neos\\EventStore\\DoctrineAdapter\\Tests\\Integration\\DoctrineEventStoreTest::consistency_validateEvents" + ], + "test": [ + "@test:phpstan", + "@test:cs", + "@test:integration", + "@test:consistency" + ] + } } diff --git a/src/DoctrineEventStore.php b/src/DoctrineEventStore.php index f9ac057..a43f737 100644 --- a/src/DoctrineEventStore.php +++ b/src/DoctrineEventStore.php @@ -3,6 +3,7 @@ namespace Neos\EventStore\DoctrineAdapter; use DateTimeImmutable; +use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\Exception as DriverException; use Doctrine\DBAL\Exception as DbalException; @@ -14,7 +15,6 @@ use Doctrine\DBAL\Result; use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\Column; -use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\Type; @@ -75,7 +75,7 @@ public function load(VirtualStreamName|StreamName $streamName, EventStreamFilter }, }; if ($filter !== null && $filter->eventTypes !== null) { - $queryBuilder->andWhere('type IN (:eventTypes)')->setParameter('eventTypes', $filter->eventTypes->toStringArray(), Connection::PARAM_STR_ARRAY); + $queryBuilder->andWhere('type IN (:eventTypes)')->setParameter('eventTypes', $filter->eventTypes->toStringArray(), ArrayParameterType::STRING); } return BatchEventStream::create(DoctrineEventStream::create($queryBuilder), 100); } @@ -169,12 +169,12 @@ private function determineRequiredSqlStatements(): array assert($schemaManager !== null); $platform = $this->connection->getDatabasePlatform(); assert($platform !== null); - if (!$schemaManager->tablesExist($this->eventTableName)) { + if (!$schemaManager->tablesExist([$this->eventTableName])) { return $platform->getCreateTableSQL($this->createEventStoreSchema($schemaManager)->getTable($this->eventTableName)); } $tableSchema = $schemaManager->introspectTable($this->eventTableName); $fromSchema = new Schema([$tableSchema], [], $schemaManager->createSchemaConfig()); - $schemaDiff = (new Comparator())->compareSchemas($fromSchema, $this->createEventStoreSchema($schemaManager)); + $schemaDiff = $schemaManager->createComparator()->compareSchemas($fromSchema, $this->createEventStoreSchema($schemaManager)); return $platform->getAlterSchemaSQL($schemaDiff); } @@ -259,7 +259,7 @@ private function getStreamVersion(StreamName $streamName): MaybeVersion ->from($this->eventTableName) ->where('stream = :streamName') ->setParameter('streamName', $streamName->value) - ->execute(); + ->executeQuery(); if (!$result instanceof Result) { throw new \RuntimeException(sprintf('Failed to determine stream version of stream "%s"', $streamName->value), 1651153859); } diff --git a/tests/Integration/DoctrineEventStoreTest.php b/tests/Integration/DoctrineEventStoreTest.php index 973e53a..3fe0713 100644 --- a/tests/Integration/DoctrineEventStoreTest.php +++ b/tests/Integration/DoctrineEventStoreTest.php @@ -7,6 +7,7 @@ use Doctrine\DBAL\Exception as DbalException; use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; +use Doctrine\DBAL\Tools\DsnParser; use Neos\EventStore\DoctrineAdapter\DoctrineEventStore; use Neos\EventStore\EventStoreInterface; use Neos\EventStore\Model\EventStore\StatusType; @@ -26,7 +27,8 @@ protected static function createEventStore(): EventStoreInterface protected static function resetEventStore(): void { $connection = self::connection(); - if (!$connection->getSchemaManager()->tablesExist([self::eventTableName()])) { + $schemaManager = $connection->createSchemaManager(); + if (!$schemaManager->tablesExist([self::eventTableName()])) { return; } if ($connection->getDatabasePlatform() instanceof SqlitePlatform) { @@ -44,9 +46,9 @@ public static function connection(): Connection if (self::$connection === null) { $dsn = getenv('DB_DSN'); if (!is_string($dsn)) { - $dsn = 'sqlite:///events_test.sqlite'; + $dsn = 'pdo-sqlite:///events_test.sqlite'; } - self::$connection = DriverManager::getConnection(['url' => $dsn]); + self::$connection = self::getConnectionFromDsn($dsn); } return self::$connection; } @@ -56,9 +58,15 @@ public static function eventTableName(): string return 'events_test'; } + private static function getConnectionFromDsn(string $dsn): Connection + { + $dsnParser = new DsnParser(); + return DriverManager::getConnection($dsnParser->parse($dsn)); + } + public function test_setup_throws_exception_if_database_connection_fails(): void { - $connection = DriverManager::getConnection(['url' => 'mysql://invalid-connection']); + $connection = self::getConnectionFromDsn('pdo-mysql://invalid-connection'); $eventStore = new DoctrineEventStore($connection, self::eventTableName()); $this->expectException(DbalException::class); @@ -67,14 +75,14 @@ public function test_setup_throws_exception_if_database_connection_fails(): void public function test_status_returns_error_status_if_database_connection_fails(): void { - $connection = DriverManager::getConnection(['url' => 'mysql://invalid-connection']); + $connection = self::getConnectionFromDsn('pdo-mysql://invalid-connection'); $eventStore = new DoctrineEventStore($connection, self::eventTableName()); self::assertSame($eventStore->status()->type, StatusType::ERROR); } public function test_status_returns_setup_required_status_if_event_table_is_missing(): void { - $connection = DriverManager::getConnection(['url' => 'sqlite:///:memory:']); + $connection = self::getConnectionFromDsn('pdo-sqlite:///:memory:'); $eventStore = new DoctrineEventStore($connection, self::eventTableName()); self::assertSame($eventStore->status()->type, StatusType::SETUP_REQUIRED); }