Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade doctrine dbal to version 3.8 #24

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
102 changes: 51 additions & 51 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
}
10 changes: 5 additions & 5 deletions src/DoctrineEventStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand Down
20 changes: 14 additions & 6 deletions tests/Integration/DoctrineEventStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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;
}
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down