Skip to content

Add support for doctrine/dbal ^4.0 #70

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
- "8.1"
- "8.2"
- "8.3"
dependency-versions:
- "highest"
- "lowest"
steps:
- name: "Checkout"
uses: "actions/checkout@v4"
Expand All @@ -34,6 +37,8 @@ jobs:
run: "composer validate --strict --no-interaction --ansi"
- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "${{ matrix.dependency-versions }}"
- name: "Run tests"
run: "make test"

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"require": {
"php": "^8.1",
"broadway/broadway": "^2.5",
"doctrine/dbal": "^3.8"
"doctrine/dbal": "^3.8 || ^4.0"
},
"authors": [
{
Expand Down
8 changes: 4 additions & 4 deletions src/DBALEventStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function __construct(
Serializer $metadataSerializer,
string $tableName,
bool $useBinary,
?BinaryUuidConverterInterface $binaryUuidConverter = null
?BinaryUuidConverterInterface $binaryUuidConverter = null,
) {
$this->connection = $connection;
$this->payloadSerializer = $payloadSerializer;
Expand Down Expand Up @@ -309,17 +309,17 @@ private function prepareVisitEventsStatementWhereAndBindValues(Criteria $criteri
foreach ($criteria->getAggregateRootIds() as $id) {
$bindValues['uuids'][] = $this->convertIdentifierToStorageValue($id);
}
$bindValueTypes['uuids'] = Connection::PARAM_STR_ARRAY;
$bindValueTypes['uuids'] = DbalForwardCompatHelper::getParamStrArrayConst();
} else {
$bindValues['uuids'] = $criteria->getAggregateRootIds();
$bindValueTypes['uuids'] = Connection::PARAM_STR_ARRAY;
$bindValueTypes['uuids'] = DbalForwardCompatHelper::getParamStrArrayConst();
}
}

if ($criteria->getEventTypes()) {
$criteriaTypes[] = 'type IN (:types)';
$bindValues['types'] = $criteria->getEventTypes();
$bindValueTypes['types'] = Connection::PARAM_STR_ARRAY;
$bindValueTypes['types'] = DbalForwardCompatHelper::getParamStrArrayConst();
}

if (!$criteriaTypes) {
Expand Down
33 changes: 33 additions & 0 deletions src/DbalForwardCompatHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Broadway\EventStore\Dbal;

use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;

class DbalForwardCompatHelper
{
public static function getSchemaManagerAndSchema(Connection $connection): array
{
if (method_exists($connection, 'getSchemaManager')) {
$schemaManager = $connection->getSchemaManager();
$schema = $schemaManager->createSchema();
} else {
$schemaManager = $connection->createSchemaManager();
$schema = $schemaManager->introspectSchema();
}

return [$schemaManager, $schema];
}

/**
* @return int|ArrayParameterType
*/
public static function getParamStrArrayConst()
{
return defined('\Doctrine\DBAL\Connection::PARAM_STR_ARRAY')
? Connection::PARAM_STR_ARRAY : ArrayParameterType::STRING;
}
}
3 changes: 1 addition & 2 deletions test/BinaryDBALEventStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ class BinaryDBALEventStoreTest extends DBALEventStoreTest
protected function setUp(): void
{
$connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true]);
$schemaManager = $connection->getSchemaManager();
$schema = $schemaManager->createSchema();
[$schemaManager, $schema] = DbalForwardCompatHelper::getSchemaManagerAndSchema($connection);
$this->eventStore = new DBALEventStore(
$connection,
new SimpleInterfaceSerializer(),
Expand Down
3 changes: 1 addition & 2 deletions test/DBALEventStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ class DBALEventStoreTest extends EventStoreTest
protected function setUp(): void
{
$connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true]);
$schemaManager = $connection->getSchemaManager();
$schema = $schemaManager->createSchema();
[$schemaManager, $schema] = DbalForwardCompatHelper::getSchemaManagerAndSchema($connection);
$this->eventStore = new DBALEventStore(
$connection,
new SimpleInterfaceSerializer(),
Expand Down
4 changes: 2 additions & 2 deletions test/Management/BinaryDBALEventStoreManagementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Broadway\EventStore\Dbal\Management;

use Broadway\EventStore\Dbal\DBALEventStore;
use Broadway\EventStore\Dbal\DbalForwardCompatHelper;
use Broadway\Serializer\SimpleInterfaceSerializer;
use Broadway\UuidGenerator\Converter\BinaryUuidConverter;
use Doctrine\DBAL\DriverManager;
Expand All @@ -29,8 +30,7 @@ class BinaryDBALEventStoreManagementTest extends DBALEventStoreManagementTest
public function createEventStore()
{
$connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true]);
$schemaManager = $connection->getSchemaManager();
$schema = $schemaManager->createSchema();
[$schemaManager, $schema] = DbalForwardCompatHelper::getSchemaManagerAndSchema($connection);
$eventStore = new DBALEventStore(
$connection,
new SimpleInterfaceSerializer(),
Expand Down
4 changes: 2 additions & 2 deletions test/Management/DBALEventStoreManagementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
namespace Broadway\EventStore\Dbal\Management;

use Broadway\EventStore\Dbal\DBALEventStore;
use Broadway\EventStore\Dbal\DbalForwardCompatHelper;
use Broadway\EventStore\Management\Testing\EventStoreManagementTest;
use Broadway\Serializer\SimpleInterfaceSerializer;
use Broadway\UuidGenerator\Converter\BinaryUuidConverter;
Expand All @@ -24,8 +25,7 @@ class DBALEventStoreManagementTest extends EventStoreManagementTest
public function createEventStore()
{
$connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true]);
$schemaManager = $connection->getSchemaManager();
$schema = $schemaManager->createSchema();
[$schemaManager, $schema] = DbalForwardCompatHelper::getSchemaManagerAndSchema($connection);
$eventStore = new DBALEventStore(
$connection,
new SimpleInterfaceSerializer(),
Expand Down