diff --git a/.gitignore b/.gitignore index 266ee42..ecf9bd4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /vendor/ composer.lock .php-cs-fixer.cache +.phpunit.result.cache diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 813ca70..391726d 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -10,8 +10,3 @@ parameters: count: 1 path: src/DBALEventStore.php - - - message: "#^Method Broadway\\\\EventStore\\\\Dbal\\\\DBALEventStore\\:\\:prepareVisitEventsStatement\\(\\) should return Doctrine\\\\DBAL\\\\Driver\\\\Statement but returns Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\DriverResultStatement\\|Doctrine\\\\DBAL\\\\ForwardCompatibility\\\\DriverStatement\\.$#" - count: 1 - path: src/DBALEventStore.php - diff --git a/src/DBALEventStore.php b/src/DBALEventStore.php index 8bea171..c1db3ad 100644 --- a/src/DBALEventStore.php +++ b/src/DBALEventStore.php @@ -27,11 +27,11 @@ use Broadway\Serializer\Serializer; use Broadway\UuidGenerator\Converter\BinaryUuidConverterInterface; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; -use Doctrine\DBAL\Driver\Statement; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; +use Doctrine\DBAL\Result; use Doctrine\DBAL\Schema\Schema; -use Doctrine\DBAL\Version; +use Doctrine\DBAL\Statement; /** * Event store using a relational database as storage. @@ -88,13 +88,9 @@ public function __construct( $this->payloadSerializer = $payloadSerializer; $this->metadataSerializer = $metadataSerializer; $this->tableName = $tableName; - $this->useBinary = (bool) $useBinary; + $this->useBinary = $useBinary; $this->binaryUuidConverter = $binaryUuidConverter; - if ($this->useBinary && Version::compare('2.5.0') >= 0) { - throw new \InvalidArgumentException('The Binary storage is only available with Doctrine DBAL >= 2.5.0'); - } - if ($this->useBinary && null === $binaryUuidConverter) { throw new \LogicException('binary UUID converter is required when using binary'); } @@ -108,10 +104,10 @@ public function load($id): DomainEventStream $statement = $this->prepareLoadStatement(); $statement->bindValue(1, $this->convertIdentifierToStorageValue($id)); $statement->bindValue(2, 0); - $statement->execute(); + $result = $statement->executeQuery(); $events = []; - while ($row = $statement->fetch()) { + while ($row = $result->fetchAssociative()) { $events[] = $this->deserializeEvent($row); } @@ -130,10 +126,10 @@ public function loadFromPlayhead($id, int $playhead): DomainEventStream $statement = $this->prepareLoadStatement(); $statement->bindValue(1, $this->convertIdentifierToStorageValue($id)); $statement->bindValue(2, $playhead); - $statement->execute(); + $result = $statement->executeQuery(); $events = []; - while ($row = $statement->fetch()) { + while ($row = $result->fetchAssociative()) { $events[] = $this->deserializeEvent($row); } @@ -165,7 +161,7 @@ public function append($id, DomainEventStream $eventStream): void $this->connection->rollBack(); throw new DuplicatePlayheadException($eventStream, $exception); - } catch (DBALException $exception) { + } catch (Exception $exception) { $this->connection->rollBack(); throw DBALEventStoreException::create($exception); @@ -293,17 +289,16 @@ private function convertStorageValueToIdentifier($id) public function visitEvents(Criteria $criteria, EventVisitor $eventVisitor): void { - $statement = $this->prepareVisitEventsStatement($criteria); - $statement->execute(); + $result = $this->prepareVisitEventsStatement($criteria); - while ($row = $statement->fetch()) { + while ($row = $result->fetchAssociative()) { $domainMessage = $this->deserializeEvent($row); $eventVisitor->doWithEvent($domainMessage); } } - private function prepareVisitEventsStatement(Criteria $criteria): Statement + private function prepareVisitEventsStatement(Criteria $criteria): Result { list($where, $bindValues, $bindValueTypes) = $this->prepareVisitEventsStatementWhereAndBindValues($criteria); $query = 'SELECT uuid, playhead, metadata, payload, recorded_on @@ -311,9 +306,7 @@ private function prepareVisitEventsStatement(Criteria $criteria): Statement '.$where.' ORDER BY id ASC'; - $statement = $this->connection->executeQuery($query, $bindValues, $bindValueTypes); - - return $statement; + return $this->connection->executeQuery($query, $bindValues, $bindValueTypes); } private function prepareVisitEventsStatementWhereAndBindValues(Criteria $criteria): array diff --git a/src/DBALEventStoreException.php b/src/DBALEventStoreException.php index 7d5f552..f83fed9 100644 --- a/src/DBALEventStoreException.php +++ b/src/DBALEventStoreException.php @@ -14,14 +14,14 @@ namespace Broadway\EventStore\Dbal; use Broadway\EventStore\EventStoreException; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; /** * Wraps exceptions thrown by the DBAL event store. */ class DBALEventStoreException extends EventStoreException { - public static function create(DBALException $exception): DBALEventStoreException + public static function create(Exception $exception): DBALEventStoreException { return new DBALEventStoreException('', 0, $exception); } diff --git a/test/BinaryDBALEventStoreTest.php b/test/BinaryDBALEventStoreTest.php index 5436cc2..0c7b48f 100644 --- a/test/BinaryDBALEventStoreTest.php +++ b/test/BinaryDBALEventStoreTest.php @@ -20,7 +20,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Types\Type; -use Doctrine\DBAL\Version; +use Doctrine\DBAL\Types\Types; /** * @requires extension pdo_sqlite @@ -32,10 +32,6 @@ class BinaryDBALEventStoreTest extends DBALEventStoreTest protected function setUp(): void { - if (Version::compare('2.5.0') >= 0) { - $this->markTestSkipped('Binary type is only available for Doctrine >= v2.5'); - } - $connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true]); $schemaManager = $connection->getSchemaManager(); $schema = $schemaManager->createSchema(); @@ -61,7 +57,7 @@ public function table_should_contain_binary_uuid_column() $uuidColumn = $this->table->getColumn('uuid'); $this->assertEquals(16, $uuidColumn->getLength()); - $this->assertEquals(Type::getType(Type::BINARY), $uuidColumn->getType()); + $this->assertEquals(Type::getType(Types::BINARY), $uuidColumn->getType()); $this->assertTrue($uuidColumn->getFixed()); } diff --git a/test/Management/BinaryDBALEventStoreManagementTest.php b/test/Management/BinaryDBALEventStoreManagementTest.php index abc398a..f38f3ac 100644 --- a/test/Management/BinaryDBALEventStoreManagementTest.php +++ b/test/Management/BinaryDBALEventStoreManagementTest.php @@ -17,7 +17,6 @@ use Broadway\Serializer\SimpleInterfaceSerializer; use Broadway\UuidGenerator\Converter\BinaryUuidConverter; use Doctrine\DBAL\DriverManager; -use Doctrine\DBAL\Version; /** * @requires extension pdo_sqlite @@ -29,10 +28,6 @@ class BinaryDBALEventStoreManagementTest extends DBALEventStoreManagementTest public function createEventStore() { - if (Version::compare('2.5.0') >= 0) { - $this->markTestSkipped('Binary type is only available for Doctrine >= v2.5'); - } - $connection = DriverManager::getConnection(['driver' => 'pdo_sqlite', 'memory' => true]); $schemaManager = $connection->getSchemaManager(); $schema = $schemaManager->createSchema();