diff --git a/composer.json b/composer.json index 1e5ddefee7e..84dd9236806 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,7 @@ "doctrine/cache": "^1.9.1", "doctrine/collections": "^1.5", "doctrine/common": "^3.0", - "doctrine/dbal": "^2.10.0", + "doctrine/dbal": "^2.12.0 || ^3.0", "doctrine/event-manager": "^1.1", "doctrine/inflector": "^1.4|^2.0", "doctrine/instantiator": "^1.3", diff --git a/lib/Doctrine/ORM/Id/SequenceGenerator.php b/lib/Doctrine/ORM/Id/SequenceGenerator.php index 9d8e9eb75aa..f12907e129f 100644 --- a/lib/Doctrine/ORM/Id/SequenceGenerator.php +++ b/lib/Doctrine/ORM/Id/SequenceGenerator.php @@ -77,7 +77,7 @@ public function generate(EntityManager $em, $entity) $sql = $conn->getDatabasePlatform()->getSequenceNextValSQL($this->_sequenceName); // Using `query` to force usage of the master server in MasterSlaveConnection - $this->_nextValue = (int) $conn->query($sql)->fetchColumn(); + $this->_nextValue = (int) $conn->query($sql)->fetchOne(); $this->_maxValue = $this->_nextValue + $this->_allocationSize; } diff --git a/lib/Doctrine/ORM/Id/TableGenerator.php b/lib/Doctrine/ORM/Id/TableGenerator.php index 02385f51158..a5ad3847719 100644 --- a/lib/Doctrine/ORM/Id/TableGenerator.php +++ b/lib/Doctrine/ORM/Id/TableGenerator.php @@ -82,7 +82,7 @@ public function generate( if ($conn->getTransactionNestingLevel() === 0) { // use select for update $sql = $conn->getDatabasePlatform()->getTableHiLoCurrentValSql($this->_tableName, $this->_sequenceName); - $currentLevel = $conn->fetchColumn($sql); + $currentLevel = $conn->fetchOne($sql); if ($currentLevel != null) { $this->_nextValue = $currentLevel; diff --git a/lib/Doctrine/ORM/Id/UuidGenerator.php b/lib/Doctrine/ORM/Id/UuidGenerator.php index 7cac5ccf40f..ec53b83d027 100644 --- a/lib/Doctrine/ORM/Id/UuidGenerator.php +++ b/lib/Doctrine/ORM/Id/UuidGenerator.php @@ -37,6 +37,6 @@ public function generate(EntityManager $em, $entity) $conn = $em->getConnection(); $sql = 'SELECT ' . $conn->getDatabasePlatform()->getGuidExpression(); - return $conn->query($sql)->fetchColumn(0); + return $conn->query($sql)->fetchOne(); } } diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 8ac93cc1372..bec2c151633 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -19,6 +19,7 @@ namespace Doctrine\ORM\Internal\Hydration; +use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Types\Type; @@ -90,7 +91,7 @@ abstract class AbstractHydrator /** * The statement that provides the data to hydrate. * - * @var \Doctrine\DBAL\Driver\Statement + * @var \Doctrine\DBAL\Driver\Statement|\Doctrine\DBAL\Driver\Result */ protected $_stmt; @@ -147,11 +148,12 @@ public function iterate($stmt, $resultSetMapping, array $hints = []) /** * Initiates a row-by-row hydration. * + * @param Statement|Result * @param mixed[] $hints * * @return iterable */ - public function toIterable(Statement $stmt, ResultSetMapping $resultSetMapping, array $hints = []) : iterable + public function toIterable($stmt, ResultSetMapping $resultSetMapping, array $hints = []) : iterable { $this->_stmt = $stmt; $this->_rsm = $resultSetMapping; @@ -166,7 +168,7 @@ public function toIterable(Statement $stmt, ResultSetMapping $resultSetMapping, $result = []; while (true) { - $row = $this->_stmt->fetch(FetchMode::ASSOCIATIVE); + $row = $this->_stmt->fetchAssociative(); if ($row === false || $row === null) { $this->cleanup(); @@ -214,7 +216,7 @@ public function hydrateAll($stmt, $resultSetMapping, array $hints = []) */ public function hydrateRow() { - $row = $this->_stmt->fetch(PDO::FETCH_ASSOC); + $row = $this->_stmt->fetchAssociative(); if ($row === false || $row === null) { $this->cleanup(); @@ -259,7 +261,11 @@ protected function prepare() */ protected function cleanup() { - $this->_stmt->closeCursor(); + if ($this->_stmt instanceof Statement) { + $this->_stmt->closeCursor(); + } else { + $this->_stmt->free(); + } $this->_stmt = null; $this->_rsm = null; diff --git a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php index c26b99be38c..ae0f8008217 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php @@ -83,7 +83,7 @@ protected function hydrateAllData() { $result = []; - while ($data = $this->_stmt->fetch(PDO::FETCH_ASSOC)) { + while ($data = $this->_stmt->fetchAssociative()) { $this->hydrateRowData($data, $result); } diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index 5048216cf7b..f8b27c38db5 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -158,7 +158,7 @@ protected function hydrateAllData() { $result = []; - while ($row = $this->_stmt->fetch(PDO::FETCH_ASSOC)) { + while ($row = $this->_stmt->fetchAssociative()) { $this->hydrateRowData($row, $result); } diff --git a/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php index 56ce39bdc3c..e7959bb0b13 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php @@ -37,7 +37,7 @@ protected function hydrateAllData() { $result = []; - while ($data = $this->_stmt->fetch(\PDO::FETCH_ASSOC)) { + while ($data = $this->_stmt->fetchAssociative()) { $this->hydrateRowData($data, $result); } diff --git a/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php index 4f16cb03c06..773a17bdfb0 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php @@ -19,6 +19,7 @@ namespace Doctrine\ORM\Internal\Hydration; +use Doctrine\ORM\Utility\SQLResultCaser; use PDO; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query; @@ -66,7 +67,7 @@ protected function hydrateAllData() { $result = []; - while ($row = $this->_stmt->fetch(PDO::FETCH_ASSOC)) { + while ($row = $this->_stmt->fetchAssociative()) { $this->hydrateRowData($row, $result); } @@ -86,7 +87,7 @@ protected function hydrateRowData(array $row, array &$result) // We need to find the correct entity class name if we have inheritance in resultset if ($this->class->inheritanceType !== ClassMetadata::INHERITANCE_TYPE_NONE) { - $discrColumnName = $this->_platform->getSQLResultCasing($this->class->discriminatorColumn['name']); + $discrColumnName = SQLResultCaser::casing($this->_platform, $this->class->discriminatorColumn['name']); // Find mapped discriminator column from the result set. if ($metaMappingDiscrColumnName = array_search($discrColumnName, $this->_rsm->metaMappings)) { diff --git a/lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php index b9caeb11b83..1b04707dd42 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php @@ -36,7 +36,7 @@ class SingleScalarHydrator extends AbstractHydrator */ protected function hydrateAllData() { - $data = $this->_stmt->fetchAll(\PDO::FETCH_ASSOC); + $data = $this->_stmt->fetchAllAssociative(); $numRows = count($data); if ($numRows === 0) { diff --git a/lib/Doctrine/ORM/Mapping/AnsiQuoteStrategy.php b/lib/Doctrine/ORM/Mapping/AnsiQuoteStrategy.php index d18c8be7c72..7c8db668f15 100644 --- a/lib/Doctrine/ORM/Mapping/AnsiQuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/AnsiQuoteStrategy.php @@ -20,6 +20,7 @@ namespace Doctrine\ORM\Mapping; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\ORM\Utility\SQLResultCaser; /** * ANSI compliant quote strategy, this strategy does not apply any quote. @@ -91,6 +92,6 @@ public function getIdentifierColumnNames(ClassMetadata $class, AbstractPlatform */ public function getColumnAlias($columnName, $counter, AbstractPlatform $platform, ClassMetadata $class = null) { - return $platform->getSQLResultCasing($columnName . '_' . $counter); + return SQLResultCaser::casing($platform, $columnName . '_' . $counter); } } diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php index 67d7a80b3ca..2fa02dfafa5 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php @@ -624,13 +624,22 @@ private function completeIdGeneratorMapping(ClassMetadataInfo $class) { $idGenType = $class->generatorType; if ($idGenType == ClassMetadata::GENERATOR_TYPE_AUTO) { + if ($this->getTargetPlatform()->supportsIdentityColumns()) { + $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY); + } else if ($this->getTargetPlatform()->supportsSequences()) { + $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_SEQUENCE); + } else { + $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_TABLE); + } + /* + * @todo WIP if ($this->getTargetPlatform()->prefersSequences()) { $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_SEQUENCE); } else if ($this->getTargetPlatform()->prefersIdentityColumns()) { $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY); } else { $class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_TABLE); - } + }*/ } // Create & assign an appropriate ID generator instance diff --git a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php index ade44a0624c..5753155c863 100644 --- a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php @@ -20,6 +20,7 @@ namespace Doctrine\ORM\Mapping; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\ORM\Utility\SQLResultCaser; /** * A set of rules for determining the physical column, alias and table quotes @@ -159,6 +160,6 @@ public function getColumnAlias($columnName, $counter, AbstractPlatform $platform $columnName = preg_replace('/[^A-Za-z0-9_]/', '', $columnName); $columnName = is_numeric($columnName) ? '_' . $columnName : $columnName; - return $platform->getSQLResultCasing($columnName); + return SQLResultCaser::casing($platform, $columnName); } } diff --git a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php index 6e0df1f16bf..6b6b32462da 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php @@ -25,6 +25,7 @@ use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use Doctrine\Inflector\Inflector; use Doctrine\Inflector\InflectorFactory; use Doctrine\ORM\Mapping\ClassMetadataInfo; @@ -428,27 +429,27 @@ private function buildFieldMapping($tableName, Column $column) // Type specific elements switch ($fieldMapping['type']) { - case Type::TARRAY: - case Type::BLOB: - case Type::GUID: - case Type::JSON_ARRAY: - case Type::OBJECT: - case Type::SIMPLE_ARRAY: - case Type::STRING: - case Type::TEXT: + case Types::ARRAY: + case Types::BLOB: + case Types::GUID: + case Types::JSON: + case Types::OBJECT: + case Types::SIMPLE_ARRAY: + case Types::STRING: + case Types::TEXT: $fieldMapping['length'] = $column->getLength(); $fieldMapping['options']['fixed'] = $column->getFixed(); break; - case Type::DECIMAL: - case Type::FLOAT: + case Types::DECIMAL: + case Types::FLOAT: $fieldMapping['precision'] = $column->getPrecision(); $fieldMapping['scale'] = $column->getScale(); break; - case Type::INTEGER: - case Type::BIGINT: - case Type::SMALLINT: + case Types::INTEGER: + case Types::BIGINT: + case Types::SMALLINT: $fieldMapping['options']['unsigned'] = $column->getUnsigned(); break; } diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index 2cd6c3f6f22..805c57bf7c5 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -20,6 +20,7 @@ namespace Doctrine\ORM\Persisters\Collection; use Doctrine\Common\Collections\Criteria; +use Doctrine\DBAL\LockMode; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Persisters\SqlValueVisitor; use Doctrine\ORM\PersistentCollection; @@ -164,7 +165,7 @@ public function count(PersistentCollection $collection) . $joinTargetEntitySQL . ' WHERE ' . implode(' AND ', $conditions); - return $this->conn->fetchColumn($sql, $params, 0, $types); + return $this->conn->fetchOne($sql, $params, $types); } /** @@ -196,7 +197,7 @@ public function containsKey(PersistentCollection $collection, $key) $sql = 'SELECT 1 FROM ' . $quotedJoinTable . ' WHERE ' . implode(' AND ', $whereClauses); - return (bool) $this->conn->fetchColumn($sql, $params, 0, $types); + return (bool) $this->conn->fetchOne($sql, $params, $types); } /** @@ -216,7 +217,7 @@ public function contains(PersistentCollection $collection, $element) $sql = 'SELECT 1 FROM ' . $quotedJoinTable . ' WHERE ' . implode(' AND ', $whereClauses); - return (bool) $this->conn->fetchColumn($sql, $params, 0, $types); + return (bool) $this->conn->fetchOne($sql, $params, $types); } /** diff --git a/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php index 1409b0e3216..28b4a43e7dc 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php @@ -20,6 +20,7 @@ namespace Doctrine\ORM\Persisters\Collection; use Doctrine\Common\Collections\Criteria; +use Doctrine\DBAL\LockMode; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\Utility\PersisterHelper; diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index ec08ac839e6..6c3bb323e37 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -25,6 +25,8 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\LockMode; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; +use Doctrine\DBAL\Result; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\MappingException; @@ -284,7 +286,7 @@ public function executeInserts() } } - $stmt->execute(); + $result = $stmt->execute(); if ($isPostInsertId) { $generatedId = $idGenerator->generate($this->em, $entity); @@ -304,7 +306,11 @@ public function executeInserts() } } - $stmt->closeCursor(); + if (method_exists($stmt, 'closeCursor')) { + $stmt->closeCursor(); + } else { + $result->free(); + } $this->queuedInserts = []; return $postInsertIds; @@ -351,10 +357,9 @@ protected function fetchVersionValue($versionedClass, array $id) $flatId = $this->identifierFlattener->flattenIdentifier($versionedClass, $id); - $value = $this->conn->fetchColumn( + $value = $this->conn->fetchOne( $sql, array_values($flatId), - 0, $this->extractIdentifierTypes($id, $versionedClass) ); @@ -499,13 +504,13 @@ protected final function updateTable($entity, $quotedTableName, array $updateDat $params[] = $this->class->reflFields[$versionField]->getValue($entity); switch ($versionFieldType) { - case Type::SMALLINT: - case Type::INTEGER: - case Type::BIGINT: + case Types::SMALLINT: + case Types::INTEGER: + case Types::BIGINT: $set[] = $versionColumn . ' = ' . $versionColumn . ' + 1'; break; - case Type::DATETIME: + case Types::DATETIME_MUTABLE: $set[] = $versionColumn . ' = CURRENT_TIMESTAMP'; break; } @@ -856,7 +861,7 @@ public function count($criteria = []) ? $this->expandCriteriaParameters($criteria) : $this->expandParameters($criteria); - return (int) $this->conn->executeQuery($sql, $params, $types)->fetchColumn(); + return (int) $this->conn->executeQuery($sql, $params, $types)->fetchOne(); } /** @@ -1119,7 +1124,7 @@ public function getSelectSQL($criteria, $assoc = null, $lockMode = null, $limit $from = ' FROM ' . $tableName . ' '. $tableAlias; $join = $this->currentPersisterContext->selectJoinSql . $joinSql; $where = ($conditionSql ? ' WHERE ' . $conditionSql : ''); - $lock = $this->platform->appendLockHint($from, $lockMode); + $lock = $this->platform->appendLockHint($from, class_exists(Result::class) ? (int) $lockMode : $lockMode); $query = $select . $lock . $join @@ -1588,7 +1593,7 @@ protected function getLockTablesSql($lockMode) 'FROM ' . $this->quoteStrategy->getTableName($this->class, $this->platform) . ' ' . $this->getSQLTableAlias($this->class->name), - $lockMode + class_exists(Result::class) ? (int) $lockMode : $lockMode ); } @@ -2048,7 +2053,7 @@ public function exists($entity, Criteria $extraConditions = null) $sql .= ' AND ' . $filterSql; } - return (bool) $this->conn->fetchColumn($sql, $params, 0, $types); + return (bool) $this->conn->fetchOne($sql, $params, $types); } /** diff --git a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php index c37611e92d6..b87bd60e81e 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php @@ -26,6 +26,8 @@ use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Utility\PersisterHelper; +use Doctrine\ORM\Utility\SQLResultCaser; +use Doctrine\DBAL\Result; use function array_combine; use function array_reverse; @@ -146,6 +148,8 @@ public function executeInserts() // Prepare statements for sub tables. $subTableStmts = []; + // Prepare results for sub tables. + $subTableResults = []; if ($rootClass !== $this->class) { $subTableStmts[$this->class->getTableName()] = $this->conn->prepare($this->getInsertSQL()); @@ -174,7 +178,7 @@ public function executeInserts() $rootTableStmt->bindValue($paramIndex++, $value, $this->columnTypes[$columnName]); } - $rootTableStmt->execute(); + $rootTableResult = $rootTableStmt->execute(); if ($isPostInsertId) { $generatedId = $idGenerator->generate($this->em, $entity); @@ -212,14 +216,22 @@ public function executeInserts() } } - $stmt->execute(); + $subTableResults[] = $stmt->execute(); } } - $rootTableStmt->closeCursor(); + if (method_exists($rootTableStmt, 'closeCursor')) { + $rootTableStmt->closeCursor(); - foreach ($subTableStmts as $stmt) { - $stmt->closeCursor(); + foreach ($subTableStmts as $stmt) { + $stmt->closeCursor(); + } + } else { + $rootTableResult->free(); + + foreach ($subTableResults as $subTableResult) { + $subTableResult->free(); + } } $this->queuedInserts = []; @@ -365,7 +377,7 @@ public function getSelectSQL($criteria, $assoc = null, $lockMode = null, $limit $tableName = $this->quoteStrategy->getTableName($this->class, $this->platform); $from = ' FROM ' . $tableName . ' ' . $baseTableAlias; $where = $conditionSql != '' ? ' WHERE ' . $conditionSql : ''; - $lock = $this->platform->appendLockHint($from, $lockMode); + $lock = $this->platform->appendLockHint($from, class_exists(Result::class) ? (int) $lockMode : $lockMode); $columnList = $this->getSelectColumnsSQL(); $query = 'SELECT ' . $columnList . $lock @@ -450,7 +462,7 @@ protected function getSelectColumnsSQL() $discrColumn = $this->class->discriminatorColumn['name']; $discrColumnType = $this->class->discriminatorColumn['type']; $baseTableAlias = $this->getSQLTableAlias($this->class->name); - $resultColumnName = $this->platform->getSQLResultCasing($discrColumn); + $resultColumnName = SQLResultCaser::casing($this->platform, $discrColumn); $this->currentPersisterContext->rsm->addEntityResult($this->class->name, 'r'); $this->currentPersisterContext->rsm->setDiscriminatorColumn('r', $resultColumnName); diff --git a/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php b/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php index 4b8352b350c..6c0bfbe8f7b 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php @@ -22,6 +22,7 @@ use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\Common\Collections\Criteria; use Doctrine\ORM\Utility\PersisterHelper; +use Doctrine\ORM\Utility\SQLResultCaser; /** * Persister for entities that participate in a hierarchy mapped with the @@ -63,7 +64,7 @@ protected function getSelectColumnsSQL() $columnList[] = $tableAlias . '.' . $discrColumn; - $resultColumnName = $this->platform->getSQLResultCasing($discrColumn); + $resultColumnName = SQLResultCaser::casing($this->platform, $discrColumn); $this->currentPersisterContext->rsm->setDiscriminatorColumn('r', $resultColumnName); $this->currentPersisterContext->rsm->addMetaResult('r', $resultColumnName, $discrColumn, false, $discrColumnType); diff --git a/lib/Doctrine/ORM/Query/AST/Functions/CountFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/CountFunction.php index 500edbee537..c2a1df494e7 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/CountFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/CountFunction.php @@ -20,6 +20,7 @@ namespace Doctrine\ORM\Query\AST\Functions; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Query\AST\TypedExpression; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; @@ -56,6 +57,6 @@ public function parse(Parser $parser): void public function getReturnType() : Type { - return Type::getType(Type::INTEGER); + return Type::getType(Types::INTEGER); } } diff --git a/lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php index 1405b342dd3..1edee170d5c 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/LengthFunction.php @@ -20,6 +20,7 @@ namespace Doctrine\ORM\Query\AST\Functions; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Query\AST\TypedExpression; use Doctrine\ORM\Query\Lexer; @@ -65,6 +66,6 @@ public function parse(\Doctrine\ORM\Query\Parser $parser) public function getReturnType() : Type { - return Type::getType(Type::INTEGER); + return Type::getType(Types::INTEGER); } } diff --git a/lib/Doctrine/ORM/Query/AST/Functions/TrimFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/TrimFunction.php index f26616ed86e..df33bf22163 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/TrimFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/TrimFunction.php @@ -19,6 +19,7 @@ namespace Doctrine\ORM\Query\AST\Functions; +use Doctrine\DBAL\Platforms\TrimMode; use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\SqlWalker; @@ -110,18 +111,18 @@ public function parse(Parser $parser) private function getTrimMode() { if ($this->leading) { - return AbstractPlatform::TRIM_LEADING; + return TrimMode::LEADING; } if ($this->trailing) { - return AbstractPlatform::TRIM_TRAILING; + return TrimMode::TRAILING; } if ($this->both) { - return AbstractPlatform::TRIM_BOTH; + return TrimMode::BOTH; } - return AbstractPlatform::TRIM_UNSPECIFIED; + return TrimMode::UNSPECIFIED; } /** diff --git a/lib/Doctrine/ORM/Query/ParameterTypeInferer.php b/lib/Doctrine/ORM/Query/ParameterTypeInferer.php index 07b78f008bd..b3519336a23 100644 --- a/lib/Doctrine/ORM/Query/ParameterTypeInferer.php +++ b/lib/Doctrine/ORM/Query/ParameterTypeInferer.php @@ -21,6 +21,7 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; /** * Provides an enclosed support for parameter inferring. @@ -36,7 +37,7 @@ class ParameterTypeInferer { /** * Infers type of a given value, returning a compatible constant: - * - Type (\Doctrine\DBAL\Types\Type::*) + * - Type (\Doctrine\DBAL\Types\Types::*) * - Connection (\Doctrine\DBAL\Connection::PARAM_*) * * @param mixed $value Parameter value. @@ -46,19 +47,20 @@ class ParameterTypeInferer public static function inferType($value) { if (is_int($value)) { - return Type::INTEGER; + return Types::INTEGER; + return Types::INTEGER; } if (is_bool($value)) { - return Type::BOOLEAN; + return Types::BOOLEAN; } if ($value instanceof \DateTime || $value instanceof \DateTimeInterface) { - return Type::DATETIME; + return Types::DATETIME_MUTABLE; } if ($value instanceof \DateInterval) { - return Type::DATEINTERVAL; + return Types::DATEINTERVAL; } if (is_array($value)) { diff --git a/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php b/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php index 5fe71d6b181..97550f8e871 100644 --- a/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php +++ b/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php @@ -23,6 +23,7 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Mapping\MappingException; use Doctrine\ORM\Utility\PersisterHelper; +use Doctrine\ORM\Utility\SQLResultCaser; use function explode; /** @@ -152,7 +153,7 @@ protected function addAllClassFields($class, $alias, $columnAliasMap = []) foreach ($classMetadata->getColumnNames() as $columnName) { $propertyName = $classMetadata->getFieldName($columnName); - $columnAlias = $platform->getSQLResultCasing($columnAliasMap[$columnName]); + $columnAlias = SQLResultCaser::casing($platform, $columnAliasMap[$columnName]); if (isset($this->fieldMappings[$columnAlias])) { throw new \InvalidArgumentException("The column '$columnName' conflicts with another column in the mapper."); @@ -168,7 +169,7 @@ protected function addAllClassFields($class, $alias, $columnAliasMap = []) foreach ($associationMapping['joinColumns'] as $joinColumn) { $columnName = $joinColumn['name']; - $columnAlias = $platform->getSQLResultCasing($columnAliasMap[$columnName]); + $columnAlias = SQLResultCaser::casing($platform, $columnAliasMap[$columnName]); $columnType = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); if (isset($this->metaMappings[$columnAlias])) { diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 63f3c7ae272..1306e2a53ca 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -27,6 +27,7 @@ use Doctrine\ORM\Query; use Doctrine\ORM\Utility\HierarchyDiscriminatorResolver; use Doctrine\ORM\Utility\PersisterHelper; +use Doctrine\DBAL\Result; use function trim; /** @@ -920,10 +921,11 @@ private function generateRangeVariableDeclarationSQL($rangeVariableDeclaration, $this->rootAliases[] = $dqlAlias; } + $lockMode = $this->query->getHint(Query::HINT_LOCK_MODE); $sql = $this->platform->appendLockHint( $this->quoteStrategy->getTableName($class, $this->platform) . ' ' . $this->getSQLTableAlias($class->getTableName(), $dqlAlias), - $this->query->getHint(Query::HINT_LOCK_MODE) + class_exists(Result::class) ? (int) $lockMode : $lockMode ); if ( ! $class->isInheritanceTypeJoined()) { diff --git a/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php b/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php index a84db75f416..a544a119e01 100644 --- a/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php +++ b/lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php @@ -91,13 +91,16 @@ public static function createApplication(HelperSet $helperSet, array $commands = */ public static function addCommands(Application $cli) : void { - $cli->addCommands( - [ + if (class_exists(DBALConsole\Command\ImportCommand::class)) { + $cli->addCommands([ // DBAL Commands new DBALConsole\Command\ImportCommand(), new DBALConsole\Command\ReservedWordsCommand(), new DBALConsole\Command\RunSqlCommand(), - + ]); + } + $cli->addCommands( + [ // ORM Commands new Command\ClearCache\CollectionRegionCommand(), new Command\ClearCache\EntityRegionCommand(), diff --git a/lib/Doctrine/ORM/Tools/EntityGenerator.php b/lib/Doctrine/ORM/Tools/EntityGenerator.php index ff3820a55e1..70c907ba2af 100644 --- a/lib/Doctrine/ORM/Tools/EntityGenerator.php +++ b/lib/Doctrine/ORM/Tools/EntityGenerator.php @@ -21,6 +21,7 @@ use Doctrine\Common\Collections\Collection; use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use Doctrine\Inflector\Inflector; use Doctrine\Inflector\InflectorFactory; use Doctrine\ORM\Mapping\ClassMetadataInfo; @@ -162,21 +163,21 @@ class EntityGenerator * @var array */ protected $typeAlias = [ - Type::DATETIMETZ => '\DateTime', - Type::DATETIME => '\DateTime', - Type::DATE => '\DateTime', - Type::TIME => '\DateTime', - Type::OBJECT => '\stdClass', - Type::INTEGER => 'int', - Type::BIGINT => 'int', - Type::SMALLINT => 'int', - Type::TEXT => 'string', - Type::BLOB => 'string', - Type::DECIMAL => 'string', - Type::GUID => 'string', - Type::JSON_ARRAY => 'array', - Type::SIMPLE_ARRAY => 'array', - Type::BOOLEAN => 'bool', + Types::DATETIMETZ_MUTABLE => '\DateTime', + Types::DATETIME_MUTABLE => '\DateTime', + Types::DATE_MUTABLE => '\DateTime', + Types::TIME_MUTABLE => '\DateTime', + Types::OBJECT => '\stdClass', + Types::INTEGER => 'int', + Types::BIGINT => 'int', + Types::SMALLINT => 'int', + Types::TEXT => 'string', + Types::BLOB => 'string', + Types::DECIMAL => 'string', + Types::GUID => 'string', + Types::JSON => 'array', + Types::SIMPLE_ARRAY => 'array', + Types::BOOLEAN => 'bool', ]; /** diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php index 5f00fdce88d..bac16463ebb 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php @@ -21,8 +21,10 @@ use Doctrine\DBAL\Platforms\DB2Platform; use Doctrine\DBAL\Platforms\OraclePlatform; +use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; use Doctrine\DBAL\Platforms\SQLAnywherePlatform; +use Doctrine\DBAL\Platforms\SQLServer2012Platform; use Doctrine\DBAL\Platforms\SQLServerPlatform; use Doctrine\ORM\Query\AST\OrderByClause; use Doctrine\ORM\Query\AST\PartialObjectExpression; @@ -129,7 +131,9 @@ public function __construct($query, $parserResult, array $queryComponents) private function platformSupportsRowNumber() { return $this->platform instanceof PostgreSqlPlatform + || $this->platform instanceof PostgreSQL94Platform || $this->platform instanceof SQLServerPlatform + || $this->platform instanceof SQLServer2012Platform || $this->platform instanceof OraclePlatform || $this->platform instanceof SQLAnywherePlatform || $this->platform instanceof DB2Platform diff --git a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php index d6c50e23107..9ca879e8413 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/Paginator.php +++ b/lib/Doctrine/ORM/Tools/Pagination/Paginator.php @@ -25,6 +25,7 @@ use Doctrine\ORM\Query\Parser; use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\QueryBuilder; +use Doctrine\ORM\Utility\SQLResultCaser; use function array_map; use function array_sum; @@ -259,7 +260,7 @@ private function getCountQuery() $platform = $countQuery->getEntityManager()->getConnection()->getDatabasePlatform(); // law of demeter win $rsm = new ResultSetMapping(); - $rsm->addScalarResult($platform->getSQLResultCasing('dctrn_count'), 'count'); + $rsm->addScalarResult(SQLResultCaser::casing($platform, 'dctrn_count'), 'count'); $countQuery->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, CountOutputWalker::class); $countQuery->setResultSetMapping($rsm); diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index a1906bb8639..2e69388f036 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -733,7 +733,7 @@ private function gatherRelationJoinColumns( $blacklistedFks[$compositeName] = true; } elseif ( ! isset($blacklistedFks[$compositeName])) { $addedFks[$compositeName] = ['foreignTableName' => $foreignTableName, 'foreignColumns' => $foreignColumns]; - $theJoinTable->addUnnamedForeignKeyConstraint( + $theJoinTable->addForeignKeyConstraint( $foreignTableName, $localColumns, $foreignColumns, diff --git a/lib/Doctrine/ORM/Utility/SQLResultCaser.php b/lib/Doctrine/ORM/Utility/SQLResultCaser.php new file mode 100644 index 00000000000..37be0f4c3a4 --- /dev/null +++ b/lib/Doctrine/ORM/Utility/SQLResultCaser.php @@ -0,0 +1,25 @@ +_generatorType = $type; - } -} diff --git a/tests/Doctrine/Tests/Mocks/ConnectionMock.php b/tests/Doctrine/Tests/Mocks/ConnectionMock.php index af8fc252e99..a9f9a360d2f 100644 --- a/tests/Doctrine/Tests/Mocks/ConnectionMock.php +++ b/tests/Doctrine/Tests/Mocks/ConnectionMock.php @@ -4,198 +4,395 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver\Statement; +use Doctrine\DBAL\Result; /** * Mock class for Connection. */ -class ConnectionMock extends Connection -{ - /** - * @var mixed - */ - private $_fetchOneResult; - - /** - * @var \Exception|null - */ - private $_fetchOneException; - - /** - * @var Statement|null - */ - private $_queryResult; - - /** - * @var DatabasePlatformMock - */ - private $_platformMock; - - /** - * @var int - */ - private $_lastInsertId = 0; - - /** - * @var array - */ - private $_inserts = []; - - /** - * @var array - */ - private $_executeUpdates = []; - - /** - * @param array $params - * @param \Doctrine\DBAL\Driver $driver - * @param \Doctrine\DBAL\Configuration|null $config - * @param \Doctrine\Common\EventManager|null $eventManager - */ - public function __construct(array $params, $driver, $config = null, $eventManager = null) +if (class_exists(Result::class)) { + class ConnectionMock extends Connection { - $this->_platformMock = new DatabasePlatformMock(); + /** + * @var mixed + */ + private $_fetchOneResult; - parent::__construct($params, $driver, $config, $eventManager); + /** + * @var \Exception|null + */ + private $_fetchOneException; - // Override possible assignment of platform to database platform mock - $this->_platform = $this->_platformMock; - } + /** + * @var Result|null + */ + private $_queryResult; - /** - * {@inheritdoc} - */ - public function getDatabasePlatform() - { - return $this->_platformMock; - } + /** + * @var DatabasePlatformMock + */ + private $_platformMock; - /** - * {@inheritdoc} - */ - public function insert($tableName, array $data, array $types = []) - { - $this->_inserts[$tableName][] = $data; - } + /** + * @var int + */ + private $_lastInsertId = 0; - /** - * {@inheritdoc} - */ - public function executeUpdate($query, array $params = [], array $types = []) - { - $this->_executeUpdates[] = ['query' => $query, 'params' => $params, 'types' => $types]; - } + /** + * @var array + */ + private $_inserts = []; - /** - * {@inheritdoc} - */ - public function lastInsertId($seqName = null) - { - return $this->_lastInsertId; - } + /** + * @var array + */ + private $_executeUpdates = []; - /** - * {@inheritdoc} - */ - public function fetchColumn($statement, array $params = [], $colnum = 0, array $types = []) - { - if (null !== $this->_fetchOneException) { - throw $this->_fetchOneException; + /** + * @param array $params + * @param \Doctrine\DBAL\Driver $driver + * @param \Doctrine\DBAL\Configuration|null $config + * @param \Doctrine\Common\EventManager|null $eventManager + */ + public function __construct(array $params, $driver, $config = null, $eventManager = null) + { + $this->_platformMock = new DatabasePlatformMock(); + + parent::__construct($params, $driver, $config, $eventManager); + + // Override possible assignment of platform to database platform mock + $this->_platform = $this->_platformMock; } - return $this->_fetchOneResult; - } + /** + * {@inheritdoc} + */ + public function getDatabasePlatform() + { + return $this->_platformMock; + } - /** - * {@inheritdoc} - */ - public function query() : Statement - { - return $this->_queryResult; - } + /** + * {@inheritdoc} + */ + public function insert($tableName, array $data, array $types = []) + { + $this->_inserts[$tableName][] = $data; + } - /** - * {@inheritdoc} - */ - public function quote($input, $type = null) - { - if (is_string($input)) { - return "'" . $input . "'"; + /** + * {@inheritdoc} + */ + public function executeUpdate($query, array $params = [], array $types = []): int + { + $this->_executeUpdates[] = ['query' => $query, 'params' => $params, 'types' => $types]; + + return 0; } - return $input; - } - /* Mock API */ + /** + * {@inheritdoc} + */ + public function lastInsertId($seqName = null) + { + return $this->_lastInsertId; + } - /** - * @param mixed $fetchOneResult - * - * @return void - */ - public function setFetchOneResult($fetchOneResult) - { - $this->_fetchOneResult = $fetchOneResult; - } + /** + * {@inheritdoc} + */ + public function fetchOne($statement, array $params = [], array $types = []) + { + if (null !== $this->_fetchOneException) { + throw $this->_fetchOneException; + } - /** - * @param \Exception|null $exception - * - * @return void - */ - public function setFetchOneException(\Exception $exception = null) - { - $this->_fetchOneException = $exception; - } + return $this->_fetchOneResult; + } - /** - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - * - * @return void - */ - public function setDatabasePlatform($platform) - { - $this->_platformMock = $platform; - } + /** + * {@inheritdoc} + */ + public function query(string $sql): Result + { + return $this->_queryResult; + } - /** - * @param int $id - * - * @return void - */ - public function setLastInsertId($id) - { - $this->_lastInsertId = $id; - } + /** + * {@inheritdoc} + */ + public function quote($input, $type = null) + { + if (is_string($input)) { + return "'" . $input . "'"; + } + return $input; + } - /** - * @param Statement $result - */ - public function setQueryResult(Statement $result) - { - $this->_queryResult = $result; - } + /* Mock API */ - /** - * @return array - */ - public function getInserts() - { - return $this->_inserts; - } + /** + * @param mixed $fetchOneResult + * + * @return void + */ + public function setFetchOneResult($fetchOneResult) + { + $this->_fetchOneResult = $fetchOneResult; + } - /** - * @return array - */ - public function getExecuteUpdates() - { - return $this->_executeUpdates; - } + /** + * @param \Exception|null $exception + * + * @return void + */ + public function setFetchOneException(\Exception $exception = null) + { + $this->_fetchOneException = $exception; + } + + /** + * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform + * + * @return void + */ + public function setDatabasePlatform($platform) + { + $this->_platformMock = $platform; + } + + /** + * @param int $id + * + * @return void + */ + public function setLastInsertId($id) + { + $this->_lastInsertId = $id; + } + + /** + * @param Result $result + */ + public function setQueryResult(Result $result) + { + $this->_queryResult = $result; + } + + /** + * @return array + */ + public function getInserts() + { + return $this->_inserts; + } + + /** + * @return array + */ + public function getExecuteUpdates() + { + return $this->_executeUpdates; + } - /** - * @return void - */ - public function reset() + /** + * @return void + */ + public function reset() + { + $this->_inserts = []; + $this->_lastInsertId = 0; + } + } +} else { + class ConnectionMock extends Connection { - $this->_inserts = []; - $this->_lastInsertId = 0; + /** + * @var mixed + */ + private $_fetchOneResult; + + /** + * @var \Exception|null + */ + private $_fetchOneException; + + /** + * @var Statement|null + */ + private $_queryResult; + + /** + * @var DatabasePlatformMock + */ + private $_platformMock; + + /** + * @var int + */ + private $_lastInsertId = 0; + + /** + * @var array + */ + private $_inserts = []; + + /** + * @var array + */ + private $_executeUpdates = []; + + /** + * @param array $params + * @param \Doctrine\DBAL\Driver $driver + * @param \Doctrine\DBAL\Configuration|null $config + * @param \Doctrine\Common\EventManager|null $eventManager + */ + public function __construct(array $params, $driver, $config = null, $eventManager = null) + { + $this->_platformMock = new DatabasePlatformMock(); + + parent::__construct($params, $driver, $config, $eventManager); + + // Override possible assignment of platform to database platform mock + $this->_platform = $this->_platformMock; + } + + /** + * {@inheritdoc} + */ + public function getDatabasePlatform() + { + return $this->_platformMock; + } + + /** + * {@inheritdoc} + */ + public function insert($tableName, array $data, array $types = []) + { + $this->_inserts[$tableName][] = $data; + } + + /** + * {@inheritdoc} + */ + public function executeUpdate($query, array $params = [], array $types = []) + { + $this->_executeUpdates[] = ['query' => $query, 'params' => $params, 'types' => $types]; + } + + /** + * {@inheritdoc} + */ + public function lastInsertId($seqName = null) + { + return $this->_lastInsertId; + } + + /** + * {@inheritdoc} + */ + public function fetchColumn($statement, array $params = [], $colnum = 0, array $types = []) + { + if (null !== $this->_fetchOneException) { + throw $this->_fetchOneException; + } + + return $this->_fetchOneResult; + } + + /** + * {@inheritdoc} + */ + public function query(): Statement + { + return $this->_queryResult; + } + + /** + * {@inheritdoc} + */ + public function quote($input, $type = null) + { + if (is_string($input)) { + return "'" . $input . "'"; + } + return $input; + } + + /* Mock API */ + + /** + * @param mixed $fetchOneResult + * + * @return void + */ + public function setFetchOneResult($fetchOneResult) + { + $this->_fetchOneResult = $fetchOneResult; + } + + /** + * @param \Exception|null $exception + * + * @return void + */ + public function setFetchOneException(\Exception $exception = null) + { + $this->_fetchOneException = $exception; + } + + /** + * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform + * + * @return void + */ + public function setDatabasePlatform($platform) + { + $this->_platformMock = $platform; + } + + /** + * @param int $id + * + * @return void + */ + public function setLastInsertId($id) + { + $this->_lastInsertId = $id; + } + + /** + * @param Statement $result + */ + public function setQueryResult(Statement $result) + { + $this->_queryResult = $result; + } + + /** + * @return array + */ + public function getInserts() + { + return $this->_inserts; + } + + /** + * @return array + */ + public function getExecuteUpdates() + { + return $this->_executeUpdates; + } + + /** + * @return void + */ + public function reset() + { + $this->_inserts = []; + $this->_lastInsertId = 0; + } } } diff --git a/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php b/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php index 60807af5ba4..34f24b6de45 100644 --- a/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php +++ b/tests/Doctrine/Tests/Mocks/DatabasePlatformMock.php @@ -3,152 +3,330 @@ namespace Doctrine\Tests\Mocks; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Result; /** * Mock class for DatabasePlatform. */ -class DatabasePlatformMock extends AbstractPlatform -{ - /** - * @var string - */ - private $_sequenceNextValSql = ""; - - /** - * @var bool - */ - private $_prefersIdentityColumns = true; - - /** - * @var bool - */ - private $_prefersSequences = false; - - /** - * {@inheritdoc} - */ - public function prefersIdentityColumns() +if (class_exists(Result::class)) { + class DatabasePlatformMock extends AbstractPlatform { - return $this->_prefersIdentityColumns; - } + /** + * @var string + */ + private $_sequenceNextValSql = ""; - /** - * {@inheritdoc} - */ - public function prefersSequences() - { - return $this->_prefersSequences; - } + /** + * @var bool + */ + private $_prefersIdentityColumns = true; - /** - * {@inheritdoc} - */ - public function getSequenceNextValSQL($sequenceName) - { - return $this->_sequenceNextValSql; - } + /** + * @var bool + */ + private $_prefersSequences = false; - /** - * {@inheritdoc} - */ - public function getBooleanTypeDeclarationSQL(array $field) - { - } + /** + * {@inheritdoc} + */ + public function prefersIdentityColumns() + { + return $this->_prefersIdentityColumns; + } - /** - * {@inheritdoc} - */ - public function getIntegerTypeDeclarationSQL(array $field) - { - } + /** + * {@inheritdoc} + */ + public function supportsIdentityColumns() + { + return $this->_prefersIdentityColumns; + } - /** - * {@inheritdoc} - */ - public function getBigIntTypeDeclarationSQL(array $field) - { - } + /** + * {@inheritdoc} + */ + public function supportsSequences() + { + return $this->_prefersSequences; + } - /** - * {@inheritdoc} - */ - public function getSmallIntTypeDeclarationSQL(array $field) - { - } + /** + * {@inheritdoc} + */ + public function getSequenceNextValSQL($sequenceName) + { + return $this->_sequenceNextValSql; + } - /** - * {@inheritdoc} - */ - protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) - { - } + /** + * {@inheritdoc} + */ + public function getBooleanTypeDeclarationSQL(array $field) + { + } - /** - * {@inheritdoc} - */ - public function getVarcharTypeDeclarationSQL(array $field) - { - } + /** + * {@inheritdoc} + */ + public function getIntegerTypeDeclarationSQL(array $field) + { + } - /** - * {@inheritdoc} - */ - public function getClobTypeDeclarationSQL(array $field) - { - } + /** + * {@inheritdoc} + */ + public function getBigIntTypeDeclarationSQL(array $field) + { + } - /* MOCK API */ + /** + * {@inheritdoc} + */ + public function getSmallIntTypeDeclarationSQL(array $field) + { + } - /** - * @param bool $bool - * - * @return void - */ - public function setPrefersIdentityColumns($bool) - { - $this->_prefersIdentityColumns = $bool; - } + /** + * {@inheritdoc} + */ + protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) + { + } - /** - * @param bool $bool - * - * @return void - */ - public function setPrefersSequences($bool) - { - $this->_prefersSequences = $bool; - } + /** + * {@inheritdoc} + */ + public function getVarcharTypeDeclarationSQL(array $field) + { + } - /** - * @param string $sql - * - * @return void - */ - public function setSequenceNextValSql($sql) - { - $this->_sequenceNextValSql = $sql; - } + /** + * {@inheritdoc} + */ + public function getClobTypeDeclarationSQL(array $field) + { + } - /** - * {@inheritdoc} - */ - public function getName() - { - return 'mock'; - } + public function getCurrentDatabaseExpression(): string + { + return "''"; + } - /** - * {@inheritdoc} - */ - protected function initializeDoctrineTypeMappings() - { - } + /* MOCK API */ + + /** + * @param bool $bool + * + * @return void + */ + public function setPrefersIdentityColumns($bool) + { + $this->_prefersIdentityColumns = $bool; + } + + /** + * @param bool $bool + * + * @return void + */ + public function setPrefersSequences($bool) + { + $this->_prefersSequences = $bool; + } + + /** + * @param string $sql + * + * @return void + */ + public function setSequenceNextValSql($sql) + { + $this->_sequenceNextValSql = $sql; + } - /** - * {@inheritdoc} - */ - public function getBlobTypeDeclarationSQL(array $field) + /** + * {@inheritdoc} + */ + public function getName() + { + return 'mock'; + } + + /** + * {@inheritdoc} + */ + protected function initializeDoctrineTypeMappings() + { + } + + /** + * {@inheritdoc} + */ + public function getBlobTypeDeclarationSQL(array $field) + { + throw DBALException::notSupported(__METHOD__); + } + } +} else { + class DatabasePlatformMock extends AbstractPlatform { - throw DBALException::notSupported(__METHOD__); + /** + * @var string + */ + private $_sequenceNextValSql = ""; + + /** + * @var bool + */ + private $_prefersIdentityColumns = true; + + /** + * @var bool + */ + private $_prefersSequences = false; + + /** + * {@inheritdoc} + */ + public function prefersIdentityColumns() + { + return $this->_prefersIdentityColumns; + } + + /** + * {@inheritdoc} + */ + public function prefersSequences() + { + return $this->_prefersSequences; + } + + /** + * {@inheritdoc} + */ + public function supportsIdentityColumns() + { + return $this->_prefersIdentityColumns; + } + + /** + * {@inheritdoc} + */ + public function supportsSequences() + { + return $this->_prefersSequences; + } + + /** + * {@inheritdoc} + */ + public function getSequenceNextValSQL($sequenceName) + { + return $this->_sequenceNextValSql; + } + + /** + * {@inheritdoc} + */ + public function getBooleanTypeDeclarationSQL(array $field) + { + } + + /** + * {@inheritdoc} + */ + public function getIntegerTypeDeclarationSQL(array $field) + { + } + + /** + * {@inheritdoc} + */ + public function getBigIntTypeDeclarationSQL(array $field) + { + } + + /** + * {@inheritdoc} + */ + public function getSmallIntTypeDeclarationSQL(array $field) + { + } + + /** + * {@inheritdoc} + */ + protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) + { + } + + /** + * {@inheritdoc} + */ + public function getVarcharTypeDeclarationSQL(array $field) + { + } + + /** + * {@inheritdoc} + */ + public function getClobTypeDeclarationSQL(array $field) + { + } + + /* MOCK API */ + + /** + * @param bool $bool + * + * @return void + */ + public function setPrefersIdentityColumns($bool) + { + $this->_prefersIdentityColumns = $bool; + } + + /** + * @param bool $bool + * + * @return void + */ + public function setPrefersSequences($bool) + { + $this->_prefersSequences = $bool; + } + + /** + * @param string $sql + * + * @return void + */ + public function setSequenceNextValSql($sql) + { + $this->_sequenceNextValSql = $sql; + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return 'mock'; + } + + /** + * {@inheritdoc} + */ + protected function initializeDoctrineTypeMappings() + { + } + + /** + * {@inheritdoc} + */ + public function getBlobTypeDeclarationSQL(array $field) + { + throw DBALException::notSupported(__METHOD__); + } } } diff --git a/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php b/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php index af1a4977f49..9a5777c99e1 100644 --- a/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php +++ b/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php @@ -3,102 +3,203 @@ namespace Doctrine\Tests\Mocks; use Doctrine\DBAL\Driver\Connection; +use Doctrine\DBAL\Result; +use Doctrine\DBAL\Driver\Statement; /** * Mock class for DriverConnection. */ -class DriverConnectionMock implements Connection -{ - /** - * @var \Doctrine\DBAL\Driver\Statement - */ - private $statementMock; - - /** - * @return \Doctrine\DBAL\Driver\Statement - */ - public function getStatementMock() +if (class_exists(Result::class)) { + class DriverConnectionMock implements Connection { - return $this->statementMock; - } + /** + * @var \Doctrine\DBAL\Driver\Statement + */ + private $statementMock; - /** - * @param \Doctrine\DBAL\Driver\Statement $statementMock - */ - public function setStatementMock($statementMock) - { - $this->statementMock = $statementMock; - } + /** + * @return \Doctrine\DBAL\Driver\Statement + */ + public function getStatementMock() + { + return $this->statementMock; + } - /** - * {@inheritdoc} - */ - public function prepare($prepareString) - { - return $this->statementMock ?: new StatementMock(); - } + /** + * @param \Doctrine\DBAL\Driver\Statement $statementMock + */ + public function setStatementMock($statementMock) + { + $this->statementMock = $statementMock; + } - /** - * {@inheritdoc} - */ - public function query() - { - return $this->statementMock ?: new StatementMock(); - } + /** + * {@inheritdoc} + */ + public function prepare($prepareString): Statement + { + return $this->statementMock ?: new StatementMock(); + } - /** - * {@inheritdoc} - */ - public function quote($input, $type=\PDO::PARAM_STR) - { - } + /** + * {@inheritdoc} + */ + public function query(string $sql): \Doctrine\DBAL\Driver\Result + { + return $this->statementMock ? $this->statementMock->execute() : new ResultMock(); + } - /** - * {@inheritdoc} - */ - public function exec($statement) - { - } + /** + * {@inheritdoc} + */ + public function quote($input, $type=\PDO::PARAM_STR) + { + } - /** - * {@inheritdoc} - */ - public function lastInsertId($name = null) - { - } + /** + * {@inheritdoc} + */ + public function exec($statement): int + { + } - /** - * {@inheritdoc} - */ - public function beginTransaction() - { - } + /** + * {@inheritdoc} + */ + public function lastInsertId($name = null) + { + } - /** - * {@inheritdoc} - */ - public function commit() - { - } + /** + * {@inheritdoc} + */ + public function beginTransaction() + { + } - /** - * {@inheritdoc} - */ - public function rollBack() - { - } + /** + * {@inheritdoc} + */ + public function commit() + { + } - /** - * {@inheritdoc} - */ - public function errorCode() - { - } + /** + * {@inheritdoc} + */ + public function rollBack() + { + } - /** - * {@inheritdoc} - */ - public function errorInfo() + /** + * {@inheritdoc} + */ + public function errorCode() + { + } + + /** + * {@inheritdoc} + */ + public function errorInfo() + { + } + } +} else { + class DriverConnectionMock implements Connection { + /** + * @var \Doctrine\DBAL\Driver\Statement + */ + private $statementMock; + + /** + * @return \Doctrine\DBAL\Driver\Statement + */ + public function getStatementMock() + { + return $this->statementMock; + } + + /** + * @param \Doctrine\DBAL\Driver\Statement $statementMock + */ + public function setStatementMock($statementMock) + { + $this->statementMock = $statementMock; + } + + /** + * {@inheritdoc} + */ + public function prepare($prepareString) + { + return $this->statementMock ?: new StatementMock(); + } + + /** + * {@inheritdoc} + */ + public function query() + { + return $this->statementMock ?: new StatementMock(); + } + + /** + * {@inheritdoc} + */ + public function quote($input, $type=\PDO::PARAM_STR) + { + } + + /** + * {@inheritdoc} + */ + public function exec($statement) + { + } + + /** + * {@inheritdoc} + */ + public function lastInsertId($name = null) + { + } + + /** + * {@inheritdoc} + */ + public function beginTransaction() + { + } + + /** + * {@inheritdoc} + */ + public function commit() + { + } + + /** + * {@inheritdoc} + */ + public function rollBack() + { + } + + /** + * {@inheritdoc} + */ + public function errorCode() + { + } + + /** + * {@inheritdoc} + */ + public function errorInfo() + { + } } } + diff --git a/tests/Doctrine/Tests/Mocks/DriverMock.php b/tests/Doctrine/Tests/Mocks/DriverMock.php index 21ae4e3bbab..e971849edba 100644 --- a/tests/Doctrine/Tests/Mocks/DriverMock.php +++ b/tests/Doctrine/Tests/Mocks/DriverMock.php @@ -4,95 +4,202 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver; +use Doctrine\DBAL\Driver\API\ExceptionConverter; use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Result; use Doctrine\DBAL\Schema\AbstractSchemaManager; /** * Mock class for Driver. */ -class DriverMock implements Driver -{ - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform|null - */ - private $_platformMock; - - /** - * @var \Doctrine\DBAL\Schema\AbstractSchemaManager|null - */ - private $_schemaManagerMock; - - /** - * {@inheritdoc} - */ - public function connect(array $params, $username = null, $password = null, array $driverOptions = []) +if (class_exists(Result::class)) { + class DriverMock implements Driver { - return new DriverConnectionMock(); - } + /** + * @var \Doctrine\DBAL\Platforms\AbstractPlatform|null + */ + private $_platformMock; - /** - * {@inheritdoc} - */ - public function getDatabasePlatform() - { - if ( ! $this->_platformMock) { - $this->_platformMock = new DatabasePlatformMock; + /** + * @var \Doctrine\DBAL\Schema\AbstractSchemaManager|null + */ + private $_schemaManagerMock; + + /** + * @var \Doctrine\DBAL\Driver\API\ExceptionConverter|null + */ + private $_exceptionConverterMock; + + /** + * {@inheritdoc} + */ + public function connect(array $params, $username = null, $password = null, array $driverOptions = []) + { + return new DriverConnectionMock(); } - return $this->_platformMock; - } - /** - * {@inheritdoc} - */ - public function getSchemaManager(Connection $conn) - { - if ($this->_schemaManagerMock == null) { - return new SchemaManagerMock($conn); + /** + * {@inheritdoc} + */ + public function getDatabasePlatform() + { + if (!$this->_platformMock) { + $this->_platformMock = new DatabasePlatformMock; + } + return $this->_platformMock; } - return $this->_schemaManagerMock; - } + /** + * {@inheritdoc} + */ + public function getSchemaManager(Connection $conn, AbstractPlatform $platform) + { + if ($this->_schemaManagerMock == null) { + return new SchemaManagerMock($conn, $platform); + } - /* MOCK API */ + return $this->_schemaManagerMock; + } - /** - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - * - * @return void - */ - public function setDatabasePlatform(AbstractPlatform $platform) - { - $this->_platformMock = $platform; - } + public function getExceptionConverter(): ExceptionConverter + { + if ($this->_exceptionConverterMock == null) { + return new ExceptionConverterMock(); + } - /** - * @param \Doctrine\DBAL\Schema\AbstractSchemaManager $sm - * - * @return void - */ - public function setSchemaManager(AbstractSchemaManager $sm) - { - $this->_schemaManagerMock = $sm; - } + return $this->_exceptionConverterMock; + } - /** - * {@inheritdoc} - */ - public function getName() - { - return 'mock'; - } + /* MOCK API */ - /** - * {@inheritdoc} - */ - public function getDatabase(Connection $conn) - { - return; - } + /** + * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform + * + * @return void + */ + public function setDatabasePlatform(AbstractPlatform $platform) + { + $this->_platformMock = $platform; + } - public function convertExceptionCode(\Exception $exception) + /** + * @param \Doctrine\DBAL\Schema\AbstractSchemaManager $sm + * + * @return void + */ + public function setSchemaManager(AbstractSchemaManager $sm) + { + $this->_schemaManagerMock = $sm; + } + + /** + * @param \Doctrine\DBAL\Driver\API\ExceptionConverter $exceptionConverter + * + * @return void + */ + public function setExceptionConverter(ExceptionConverter $exceptionConverter) + { + $this->_exceptionConverterMock = $exceptionConverter; + } + + /** + * {@inheritdoc} + */ + public function getDatabase(Connection $conn) + { + return; + } + + public function convertExceptionCode(\Exception $exception) + { + return 0; + } + } +} else { + class DriverMock implements Driver { - return 0; + /** + * @var \Doctrine\DBAL\Platforms\AbstractPlatform|null + */ + private $_platformMock; + + /** + * @var \Doctrine\DBAL\Schema\AbstractSchemaManager|null + */ + private $_schemaManagerMock; + + /** + * {@inheritdoc} + */ + public function connect(array $params, $username = null, $password = null, array $driverOptions = []) + { + return new DriverConnectionMock(); + } + + /** + * {@inheritdoc} + */ + public function getDatabasePlatform() + { + if (!$this->_platformMock) { + $this->_platformMock = new DatabasePlatformMock; + } + return $this->_platformMock; + } + + /** + * {@inheritdoc} + */ + public function getSchemaManager(Connection $conn) + { + if ($this->_schemaManagerMock == null) { + return new SchemaManagerMock($conn); + } + + return $this->_schemaManagerMock; + } + + /* MOCK API */ + + /** + * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform + * + * @return void + */ + public function setDatabasePlatform(AbstractPlatform $platform) + { + $this->_platformMock = $platform; + } + + /** + * @param \Doctrine\DBAL\Schema\AbstractSchemaManager $sm + * + * @return void + */ + public function setSchemaManager(AbstractSchemaManager $sm) + { + $this->_schemaManagerMock = $sm; + } + + /** + * {@inheritdoc} + */ + public function getName() + { + return 'mock'; + } + + /** + * {@inheritdoc} + */ + public function getDatabase(Connection $conn) + { + return; + } + + public function convertExceptionCode(\Exception $exception) + { + return 0; + } } } diff --git a/tests/Doctrine/Tests/Mocks/ExceptionConverterMock.php b/tests/Doctrine/Tests/Mocks/ExceptionConverterMock.php new file mode 100644 index 00000000000..36d1d979a02 --- /dev/null +++ b/tests/Doctrine/Tests/Mocks/ExceptionConverterMock.php @@ -0,0 +1,22 @@ + */ -class HydratorMockStatement implements \IteratorAggregate, Statement -{ - /** - * @var array - */ - private $_resultSet; - - /** - * Creates a new mock statement that will serve the provided fake result set to clients. - * - * @param array $resultSet The faked SQL result set. - */ - public function __construct(array $resultSet) +if (class_exists(Result::class)) { + class HydratorMockStatement implements \IteratorAggregate, Statement { - $this->_resultSet = $resultSet; + /** + * @var array + */ + private $_resultSet; + + /** + * Creates a new mock statement that will serve the provided fake result set to clients. + * + * @param array $resultSet The faked SQL result set. + */ + public function __construct(array $resultSet) + { + $this->_resultSet = $resultSet; + } + + /** + * {@inheritdoc} + */ + public function bindValue($param, $value, $type = null) + { + } + + /** + * {@inheritdoc} + */ + public function bindParam($column, &$variable, $type = null, $length = null) + { + } + + /** + * {@inheritdoc} + */ + public function execute($params = null): \Doctrine\DBAL\Driver\Result + { + } + + /** + * {@inheritdoc} + */ + public function getIterator() + { + return new \ArrayIterator($this->_resultSet); + } } - - /** - * Fetches all rows from the result set. - * - * @param int|null $fetchMode - * @param int|null $fetchArgument - * @param array|null $ctorArgs - * @return array - */ - public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) - { - return $this->_resultSet; - } - - /** - * {@inheritdoc} - */ - public function fetchColumn($columnNumber = 0) - { - $row = current($this->_resultSet); - if ( ! is_array($row)) return false; - $val = array_shift($row); - return $val !== null ? $val : false; - } - - /** - * {@inheritdoc} - */ - public function fetch($fetchStyle = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) - { - $current = current($this->_resultSet); - next($this->_resultSet); - return $current; - } - - /** - * {@inheritdoc} - */ - public function closeCursor() - { - return true; - } - - /** - * {@inheritdoc} - */ - public function bindValue($param, $value, $type = null) - { - } - - /** - * {@inheritdoc} - */ - public function bindParam($column, &$variable, $type = null, $length = null) - { - } - - /** - * {@inheritdoc} - */ - public function columnCount() - { - } - - /** - * {@inheritdoc} - */ - public function errorCode() - { - } - - /** - * {@inheritdoc} - */ - public function errorInfo() - { - } - - /** - * {@inheritdoc} - */ - public function execute($params = null) - { - } - - /** - * {@inheritdoc} - */ - public function rowCount() - { - } - - /** - * {@inheritdoc} - */ - public function getIterator() - { - return $this->_resultSet; - } - - /** - * {@inheritdoc} - */ - public function setFetchMode($fetchStyle, $arg2 = null, $arg3 = null) +} else { + class HydratorMockStatement implements \IteratorAggregate, Statement { + /** + * @var array + */ + private $_resultSet; + + /** + * Creates a new mock statement that will serve the provided fake result set to clients. + * + * @param array $resultSet The faked SQL result set. + */ + public function __construct(array $resultSet) + { + $this->_resultSet = $resultSet; + } + + /** + * Fetches all rows from the result set. + * + * @param int|null $fetchMode + * @param int|null $fetchArgument + * @param array|null $ctorArgs + * @return array + */ + public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) + { + return $this->_resultSet; + } + + /** + * Fetches all rows from the result set. + * + * @param int|null $fetchArgument + * @param array|null $ctorArgs + * @return array + */ + public function fetchAllAssociative($fetchArgument = null, $ctorArgs = null) + { + return $this->_resultSet; + } + + /** + * {@inheritdoc} + */ + public function fetchColumn($columnNumber = 0) + { + $row = current($this->_resultSet); + if ( ! is_array($row)) return false; + $val = array_shift($row); + return $val !== null ? $val : false; + } + + /** + * {@inheritdoc} + */ + public function fetch($fetchStyle = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + { + $current = current($this->_resultSet); + next($this->_resultSet); + return $current; + } + + /** + * {@inheritdoc} + */ + public function fetchAssociative($cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + { + $current = current($this->_resultSet); + next($this->_resultSet); + return $current; + } + + /** + * {@inheritdoc} + */ + public function closeCursor() + { + return true; + } + + /** + * {@inheritdoc} + */ + public function bindValue($param, $value, $type = null) + { + } + + /** + * {@inheritdoc} + */ + public function bindParam($column, &$variable, $type = null, $length = null) + { + } + + /** + * {@inheritdoc} + */ + public function columnCount() + { + } + + /** + * {@inheritdoc} + */ + public function errorCode() + { + } + + /** + * {@inheritdoc} + */ + public function errorInfo() + { + } + + /** + * {@inheritdoc} + */ + public function execute($params = null) + { + } + + /** + * {@inheritdoc} + */ + public function rowCount() + { + } + + /** + * {@inheritdoc} + */ + public function getIterator() + { + return new \ArrayIterator($this->_resultSet); + } + + /** + * {@inheritdoc} + */ + public function setFetchMode($fetchStyle, $arg2 = null, $arg3 = null) + { + } } } diff --git a/tests/Doctrine/Tests/Mocks/ResultMock.php b/tests/Doctrine/Tests/Mocks/ResultMock.php new file mode 100644 index 00000000000..f91d0d2c82f --- /dev/null +++ b/tests/Doctrine/Tests/Mocks/ResultMock.php @@ -0,0 +1,76 @@ +_resultSet = $resultSet; + } + + public function fetchNumeric() + { + // TODO: Implement fetchNumeric() method. + } + + public function fetchAssociative() + { + $current = current($this->_resultSet); + next($this->_resultSet); + return $current; + } + + public function fetchOne() + { + $current = current($this->_resultSet); + if ($current) { + next($this->_resultSet); + return reset($current); + } + + return false; + } + + public function fetchAllNumeric(): array + { + // TODO: Implement fetchAllNumeric() method. + } + + public function fetchAllAssociative(): array + { + return $this->_resultSet; + } + + public function fetchFirstColumn(): array + { + // TODO: Implement fetchFirstColumn() method. + } + + public function rowCount(): int + { + // TODO: Implement rowCount() method. + } + + public function columnCount(): int + { + // TODO: Implement columnCount() method. + } + + public function free(): void + { + // TODO: Implement free() method. + } +} diff --git a/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php b/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php index 5de33a049ec..479c403cb20 100644 --- a/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php +++ b/tests/Doctrine/Tests/Mocks/SchemaManagerMock.php @@ -15,7 +15,7 @@ class SchemaManagerMock extends AbstractSchemaManager */ public function __construct(Connection $conn) { - parent::__construct($conn); + parent::__construct($conn, $conn->getDatabasePlatform()); } /** diff --git a/tests/Doctrine/Tests/Mocks/SequenceMock.php b/tests/Doctrine/Tests/Mocks/SequenceMock.php deleted file mode 100644 index fc6c10f41a4..00000000000 --- a/tests/Doctrine/Tests/Mocks/SequenceMock.php +++ /dev/null @@ -1,35 +0,0 @@ -_sequenceNumber++; - } - - /* Mock API */ - - /** - * @return void - */ - public function reset() - { - $this->_sequenceNumber = 0; - } -} diff --git a/tests/Doctrine/Tests/Mocks/StatementArrayMock.php b/tests/Doctrine/Tests/Mocks/StatementArrayMock.php deleted file mode 100644 index 0f1747c42dc..00000000000 --- a/tests/Doctrine/Tests/Mocks/StatementArrayMock.php +++ /dev/null @@ -1,65 +0,0 @@ -_result = $result; - } - - public function getIterator() - { - return new \ArrayIterator($this->_result); - } - - public function columnCount() - { - $row = reset($this->_result); - if ($row) { - return count($row); - } else { - return 0; - } - } - - public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) - { - return $this->_result; - } - - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) - { - $current = current($this->_result); - next($this->_result); - - return $current; - } - - public function fetchColumn($columnIndex = 0) - { - $current = current($this->_result); - if ($current) { - next($this->_result); - return reset($current); - } - - return false; - } - - public function rowCount() - { - return count($this->_result); - } -} diff --git a/tests/Doctrine/Tests/Mocks/StatementMock.php b/tests/Doctrine/Tests/Mocks/StatementMock.php index efba7d841b4..70bca268ae4 100644 --- a/tests/Doctrine/Tests/Mocks/StatementMock.php +++ b/tests/Doctrine/Tests/Mocks/StatementMock.php @@ -3,100 +3,202 @@ namespace Doctrine\Tests\Mocks; use Doctrine\DBAL\Driver\Statement; +use Doctrine\DBAL\Result; /** * This class is a mock of the Statement interface. * * @author Alexander */ -class StatementMock implements \IteratorAggregate, Statement -{ - /** - * {@inheritdoc} - */ - public function bindValue($param, $value, $type = null) +if (class_exists(Result::class)) { + class StatementMock implements \IteratorAggregate, Statement { - } + /** + * @var ResultMock + */ + private $_resultMock; - /** - * {@inheritdoc} - */ - public function bindParam($column, &$variable, $type = null, $length = null) - { - } + public function __construct(array $resultSet = []) + { + $this->_resultMock = new ResultMock($resultSet); + } - /** - * {@inheritdoc} - */ - public function errorCode() - { - } + /** + * {@inheritdoc} + */ + public function bindValue($param, $value, $type = null) + { + } - /** - * {@inheritdoc} - */ - public function errorInfo(){} + /** + * {@inheritdoc} + */ + public function bindParam($column, &$variable, $type = null, $length = null) + { + } - /** - * {@inheritdoc} - */ - public function execute($params = null) - { - } + /** + * {@inheritdoc} + */ + public function execute($params = null): \Doctrine\DBAL\Driver\Result + { + return $this->_resultMock; + } - /** - * {@inheritdoc} - */ - public function rowCount() - { + /** + * {@inheritdoc} + */ + public function getIterator() + { + } } - - /** - * {@inheritdoc} - */ - public function closeCursor() +} else { + class StatementMock implements \IteratorAggregate, Statement { - } + /** + * @var array + */ + private $_resultSet; - /** - * {@inheritdoc} - */ - public function columnCount() - { - } + public function __construct(array $resultSet = []) + { + $this->_resultSet = $resultSet; + } - /** - * {@inheritdoc} - */ - public function setFetchMode($fetchStyle, $arg2 = null, $arg3 = null) - { - } + /** + * {@inheritdoc} + */ + public function bindValue($param, $value, $type = null) + { + } - /** - * {@inheritdoc} - */ - public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) - { - } + /** + * {@inheritdoc} + */ + public function bindParam($column, &$variable, $type = null, $length = null) + { + } - /** - * {@inheritdoc} - */ - public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) - { - } + /** + * {@inheritdoc} + */ + public function errorCode() + { + } - /** - * {@inheritdoc} - */ - public function fetchColumn($columnIndex = 0) - { - } + /** + * {@inheritdoc} + */ + public function errorInfo(){} - /** - * {@inheritdoc} - */ - public function getIterator() - { + /** + * {@inheritdoc} + */ + public function execute($params = null) + { + } + + /** + * {@inheritdoc} + */ + public function rowCount() + { + return count($this->_resultSet); + } + + /** + * {@inheritdoc} + */ + public function closeCursor() + { + } + + /** + * {@inheritdoc} + */ + public function columnCount() + { + $row = reset($this->_resultSet); + if ($row) { + return count($row); + } else { + return 0; + } + } + + /** + * {@inheritdoc} + */ + public function setFetchMode($fetchStyle, $arg2 = null, $arg3 = null) + { + } + + /** + * {@inheritdoc} + */ + public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) + { + return $this->fetchAllAssociative($fetchArgument, $ctorArgs); + } + + /** + * {@inheritdoc} + */ + public function fetchAllAssociative($fetchArgument = null, $ctorArgs = null) + { + return $this->_resultSet; + } + + /** + * {@inheritdoc} + */ + public function fetch($fetchMode = null, $cursorOrientation = \PDO::FETCH_ORI_NEXT, $cursorOffset = 0) + { + $current = current($this->_resultSet); + next($this->_resultSet); + + return $current; + } + + /** + * {@inheritdoc} + */ + public function fetchAssociative($fetchArgument = null, $ctorArgs = null) + { + $current = current($this->_resultSet); + next($this->_resultSet); + + return $current; + } + + /** + * {@inheritdoc} + */ + public function fetchColumn($columnIndex = 0) + { + return $this->fetchOne(); + } + + /** + * {@inheritdoc} + */ + public function fetchOne() + { + $current = current($this->_resultSet); + if ($current) { + next($this->_resultSet); + return reset($current); + } + + return false; + } + + /** + * {@inheritdoc} + */ + public function getIterator() + { + return new \ArrayIterator($this->_resultSet); + } } } diff --git a/tests/Doctrine/Tests/Mocks/TaskMock.php b/tests/Doctrine/Tests/Mocks/TaskMock.php deleted file mode 100644 index f6ce095add1..00000000000 --- a/tests/Doctrine/Tests/Mocks/TaskMock.php +++ /dev/null @@ -1,70 +0,0 @@ - - */ -class TaskMock extends \Doctrine\Common\Cli\Tasks\AbstractTask -{ - /** - * Since instances of this class can be created elsewhere all instances - * register themselves in this array for later inspection. - * - * @var array (TaskMock) - */ - static public $instances = []; - - /** - * @var int - */ - private $runCounter = 0; - - /** - * Constructor of Task Mock Object. - * Makes sure the object can be inspected later. - * - * @param AbstractNamespace $namespace CLI Namespace, passed to parent constructor. - */ - function __construct(AbstractNamespace $namespace) - { - self::$instances[] = $this; - - parent::__construct($namespace); - } - - /** - * Returns the number of times run() was called on this object. - * - * @return int - */ - public function getRunCounter() - { - return $this->runCounter; - } - - /* Mock API */ - - /** - * Method invoked by CLI to run task. - * - * @return void - */ - public function run() - { - $this->runCounter++; - } - - /** - * Method supposed to generate the CLI Task Documentation. - * - * @return void - */ - public function buildDocumentation() - { - } -} diff --git a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php index a928e18b34b..1de497cdbe1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/BasicFunctionalTest.php @@ -131,7 +131,7 @@ public function testBasicOneToOne() // Check that the foreign key has been set $userId = $this->_em->getConnection()->executeQuery( "SELECT user_id FROM cms_addresses WHERE id=?", [$address->id] - )->fetchColumn(); + )->fetchOne(); $this->assertTrue(is_numeric($userId)); $this->_em->clear(); @@ -202,13 +202,13 @@ public function testOneToManyOrphanRemoval() $this->_em->flush(); // Check that there are just 2 phonenumbers left - $count = $this->_em->getConnection()->fetchColumn("SELECT COUNT(*) FROM cms_phonenumbers"); + $count = $this->_em->getConnection()->fetchOne("SELECT COUNT(*) FROM cms_phonenumbers"); $this->assertEquals(2, $count); // only 2 remaining // check that clear() removes the others via orphan removal $user->getPhonenumbers()->clear(); $this->_em->flush(); - $this->assertEquals(0, $this->_em->getConnection()->fetchColumn("select count(*) from cms_phonenumbers")); + $this->assertEquals(0, $this->_em->getConnection()->fetchOne("select count(*) from cms_phonenumbers")); } public function testBasicQuery() @@ -664,7 +664,7 @@ public function testRemoveEntityByReference() $this->_em->flush(); $this->_em->clear(); - $this->assertEquals(0, $this->_em->getConnection()->fetchColumn("select count(*) from cms_users")); + $this->assertEquals(0, $this->_em->getConnection()->fetchOne("select count(*) from cms_users")); //$this->_em->getConnection()->getConfiguration()->setSQLLogger(null); } @@ -721,12 +721,12 @@ public function testOneToOneNullUpdate() $this->_em->persist($user); $this->_em->flush(); - $this->assertEquals(1, $this->_em->getConnection()->fetchColumn("select 1 from cms_addresses where user_id = ".$user->id)); + $this->assertEquals(1, $this->_em->getConnection()->fetchOne("select 1 from cms_addresses where user_id = ".$user->id)); $address->user = null; $this->_em->flush(); - $this->assertNotEquals(1, $this->_em->getConnection()->fetchColumn("select 1 from cms_addresses where user_id = ".$user->id)); + $this->assertNotEquals(1, $this->_em->getConnection()->fetchOne("select 1 from cms_addresses where user_id = ".$user->id)); } /** @@ -833,14 +833,14 @@ public function testOneToOneOrphanRemoval() $this->_em->flush(); - $this->assertEquals(0, $this->_em->getConnection()->fetchColumn("select count(*) from cms_addresses")); + $this->assertEquals(0, $this->_em->getConnection()->fetchOne("select count(*) from cms_addresses")); // check orphan removal through replacement $user->address = $address; $address->user = $user; $this->_em->flush(); - $this->assertEquals(1, $this->_em->getConnection()->fetchColumn("select count(*) from cms_addresses")); + $this->assertEquals(1, $this->_em->getConnection()->fetchOne("select count(*) from cms_addresses")); // remove $address to free up unique key id $this->_em->remove($address); @@ -855,7 +855,7 @@ public function testOneToOneOrphanRemoval() $user->address = $newAddress; $this->_em->flush(); - $this->assertEquals(1, $this->_em->getConnection()->fetchColumn("select count(*) from cms_addresses")); + $this->assertEquals(1, $this->_em->getConnection()->fetchOne("select count(*) from cms_addresses")); } public function testGetPartialReferenceToUpdateObjectWithoutLoadingIt() diff --git a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php index d69c00109ee..c7c9c8cc777 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php @@ -20,6 +20,7 @@ use Doctrine\Tests\Models\DDC3899\DDC3899FixContract; use Doctrine\Tests\Models\DDC3899\DDC3899User; use Doctrine\Tests\OrmFunctionalTestCase; +use Doctrine\ORM\Utility\SQLResultCaser; /** * NativeQueryTest @@ -52,8 +53,8 @@ public function testBasicNativeQuery() $rsm = new ResultSetMapping; $rsm->addEntityResult(CmsUser::class, 'u'); - $rsm->addFieldResult('u', $this->platform->getSQLResultCasing('id'), 'id'); - $rsm->addFieldResult('u', $this->platform->getSQLResultCasing('name'), 'name'); + $rsm->addFieldResult('u', SQLResultCaser::casing($this->platform, 'id'), 'id'); + $rsm->addFieldResult('u', SQLResultCaser::casing($this->platform, 'name'), 'name'); $query = $this->_em->createNativeQuery('SELECT id, name FROM cms_users WHERE username = ?', $rsm); $query->setParameter(1, 'romanb'); @@ -87,11 +88,11 @@ public function testBasicNativeQueryWithMetaResult() $rsm = new ResultSetMapping; $rsm->addEntityResult(CmsAddress::class, 'a'); - $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('id'), 'id'); - $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('country'), 'country'); - $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('zip'), 'zip'); - $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('city'), 'city'); - $rsm->addMetaResult('a', $this->platform->getSQLResultCasing('user_id'), 'user_id', false, 'integer'); + $rsm->addFieldResult('a', SQLResultCaser::casing($this->platform, 'id'), 'id'); + $rsm->addFieldResult('a', SQLResultCaser::casing($this->platform, 'country'), 'country'); + $rsm->addFieldResult('a', SQLResultCaser::casing($this->platform, 'zip'), 'zip'); + $rsm->addFieldResult('a', SQLResultCaser::casing($this->platform, 'city'), 'city'); + $rsm->addMetaResult('a', SQLResultCaser::casing($this->platform, 'user_id'), 'user_id', false, 'integer'); $query = $this->_em->createNativeQuery('SELECT a.id, a.country, a.zip, a.city, a.user_id FROM cms_addresses a WHERE a.id = ?', $rsm); $query->setParameter(1, $addr->id); @@ -126,11 +127,11 @@ public function testJoinedOneToManyNativeQuery() $rsm = new ResultSetMapping; $rsm->addEntityResult(CmsUser::class, 'u'); - $rsm->addFieldResult('u', $this->platform->getSQLResultCasing('id'), 'id'); - $rsm->addFieldResult('u', $this->platform->getSQLResultCasing('name'), 'name'); - $rsm->addFieldResult('u', $this->platform->getSQLResultCasing('status'), 'status'); + $rsm->addFieldResult('u', SQLResultCaser::casing($this->platform, 'id'), 'id'); + $rsm->addFieldResult('u', SQLResultCaser::casing($this->platform, 'name'), 'name'); + $rsm->addFieldResult('u', SQLResultCaser::casing($this->platform, 'status'), 'status'); $rsm->addJoinedEntityResult(CmsPhonenumber::class, 'p', 'u', 'phonenumbers'); - $rsm->addFieldResult('p', $this->platform->getSQLResultCasing('phonenumber'), 'phonenumber'); + $rsm->addFieldResult('p', SQLResultCaser::casing($this->platform, 'phonenumber'), 'phonenumber'); $query = $this->_em->createNativeQuery('SELECT id, name, status, phonenumber FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username = ?', $rsm); $query->setParameter(1, 'romanb'); @@ -171,14 +172,14 @@ public function testJoinedOneToOneNativeQuery() $rsm = new ResultSetMapping; $rsm->addEntityResult(CmsUser::class, 'u'); - $rsm->addFieldResult('u', $this->platform->getSQLResultCasing('id'), 'id'); - $rsm->addFieldResult('u', $this->platform->getSQLResultCasing('name'), 'name'); - $rsm->addFieldResult('u', $this->platform->getSQLResultCasing('status'), 'status'); + $rsm->addFieldResult('u', SQLResultCaser::casing($this->platform, 'id'), 'id'); + $rsm->addFieldResult('u', SQLResultCaser::casing($this->platform, 'name'), 'name'); + $rsm->addFieldResult('u', SQLResultCaser::casing($this->platform, 'status'), 'status'); $rsm->addJoinedEntityResult(CmsAddress::class, 'a', 'u', 'address'); - $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('a_id'), 'id'); - $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('country'), 'country'); - $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('zip'), 'zip'); - $rsm->addFieldResult('a', $this->platform->getSQLResultCasing('city'), 'city'); + $rsm->addFieldResult('a', SQLResultCaser::casing($this->platform, 'a_id'), 'id'); + $rsm->addFieldResult('a', SQLResultCaser::casing($this->platform, 'country'), 'country'); + $rsm->addFieldResult('a', SQLResultCaser::casing($this->platform, 'zip'), 'zip'); + $rsm->addFieldResult('a', SQLResultCaser::casing($this->platform, 'city'), 'city'); $query = $this->_em->createNativeQuery('SELECT u.id, u.name, u.status, a.id AS a_id, a.country, a.zip, a.city FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.username = ?', $rsm); $query->setParameter(1, 'romanb'); @@ -807,8 +808,8 @@ public function testGenerateSelectClauseWithDiscriminatorColumn() $rsm = new ResultSetMappingBuilder($this->_em, ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT); $rsm->addEntityResult(DDC3899User::class, 'u'); $rsm->addJoinedEntityResult(DDC3899FixContract::class, 'c', 'u', 'contracts'); - $rsm->addFieldResult('u', $this->platform->getSQLResultCasing('id'), 'id'); - $rsm->setDiscriminatorColumn('c', $this->platform->getSQLResultCasing('discr')); + $rsm->addFieldResult('u', 'id', 'id'); + $rsm->setDiscriminatorColumn('c', 'discr'); $selectClause = $rsm->generateSelectClause(['u' => 'u1', 'c' => 'c1']); diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php index 91f81a72dad..0b22d4f254d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManyBidirectionalAssociationTest.php @@ -235,7 +235,7 @@ public function assertFeatureForeignKeyIs($value, ECommerceFeature $feature) { $foreignKey = $this->_em->getConnection()->executeQuery( 'SELECT product_id FROM ecommerce_features WHERE id=?', [$feature->getId()] - )->fetchColumn(); + )->fetchOne(); $this->assertEquals($value, $foreignKey); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php index be85a103921..cee5e0ff826 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToManySelfReferentialAssociationTest.php @@ -117,7 +117,7 @@ private function _createFixture() public function assertForeignKeyIs($value, ECommerceCategory $child) { $foreignKey = $this->_em->getConnection()->executeQuery('SELECT parent_id FROM ecommerce_categories WHERE id=?', [$child->getId()] - )->fetchColumn(); + )->fetchOne(); $this->assertEquals($value, $foreignKey); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php index 83691e886ee..efd25087103 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php @@ -146,7 +146,7 @@ protected function _createFixture() public function assertCartForeignKeyIs($value) { $foreignKey = $this->_em->getConnection()->executeQuery('SELECT customer_id FROM ecommerce_carts WHERE id=?', [$this->cart->getId()] - )->fetchColumn(); + )->fetchOne(); $this->assertEquals($value, $foreignKey); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php index cf15e7d6e04..6ade096c91a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneSelfReferentialAssociationTest.php @@ -122,7 +122,7 @@ public function assertLoadingOfAssociation($customer) public function assertForeignKeyIs($value) { $foreignKey = $this->_em->getConnection()->executeQuery('SELECT mentor_id FROM ecommerce_customers WHERE id=?', [$this->customer->getId()] - )->fetchColumn(); + )->fetchOne(); $this->assertEquals($value, $foreignKey); } diff --git a/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php index 2d967167a8d..9ddffbff2b8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php @@ -102,7 +102,7 @@ public function assertForeignKeyIs($value) { $foreignKey = $this->_em->getConnection()->executeQuery( 'SELECT shipping_id FROM ecommerce_products WHERE id=?', [$this->product->getId()] - )->fetchColumn(); + )->fetchOne(); $this->assertEquals($value, $foreignKey); } diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index 35b5459fc6b..0f2844e1845 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -4,7 +4,7 @@ use Doctrine\Common\Cache\ArrayCache; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Types\Type as DBALType; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Configuration; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Mapping\ClassMetadata; @@ -238,7 +238,7 @@ public function testSQLFilterGetSetParameter() $filter = new MyLocaleFilter($em); - $filter->setParameter('locale', 'en', DBALType::STRING); + $filter->setParameter('locale', 'en', Types::STRING); $this->assertEquals("'en'", $filter->getParameter('locale')); } @@ -316,16 +316,16 @@ public function testSQLFilterToString() $filterCollection = $this->addMockFilterCollection($em); $filter = new MyLocaleFilter($em); - $filter->setParameter('locale', 'en', DBALType::STRING); - $filter->setParameter('foo', 'bar', DBALType::STRING); + $filter->setParameter('locale', 'en', Types::STRING); + $filter->setParameter('foo', 'bar', Types::STRING); $filter2 = new MyLocaleFilter($em); - $filter2->setParameter('foo', 'bar', DBALType::STRING); - $filter2->setParameter('locale', 'en', DBALType::STRING); + $filter2->setParameter('foo', 'bar', Types::STRING); + $filter2->setParameter('locale', 'en', Types::STRING); $parameters = [ - 'foo' => ['value' => 'bar', 'type' => DBALType::STRING], - 'locale' => ['value' => 'en', 'type' => DBALType::STRING], + 'foo' => ['value' => 'bar', 'type' => Types::STRING], + 'locale' => ['value' => 'en', 'type' => Types::STRING], ]; $this->assertEquals(serialize($parameters), ''.$filter); @@ -365,7 +365,7 @@ public function testQueryGeneration_DependsOnFilters() $conf = $this->_em->getConfiguration(); $conf->addFilter("country", "\Doctrine\Tests\ORM\Functional\CMSCountryFilter"); $this->_em->getFilters()->enable("country") - ->setParameter("country", "en", DBALType::STRING); + ->setParameter("country", "en", Types::STRING); $this->assertNotEquals($firstSQLQuery, $query->getSQL()); } @@ -464,7 +464,7 @@ public function testToOneFilter() $conf = $this->_em->getConfiguration(); $conf->addFilter("country", "\Doctrine\Tests\ORM\Functional\CMSCountryFilter"); - $this->_em->getFilters()->enable("country")->setParameter("country", "Germany", DBALType::STRING); + $this->_em->getFilters()->enable("country")->setParameter("country", "Germany", Types::STRING); // We get one user after enabling the filter $this->assertEquals(1, count($query->getResult())); @@ -480,7 +480,7 @@ public function testManyToManyFilter() $conf = $this->_em->getConfiguration(); $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter"); - $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", DBALType::STRING); + $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", Types::STRING); // We get one user after enabling the filter $this->assertEquals(1, count($query->getResult())); @@ -497,7 +497,7 @@ public function testWhereFilter() $conf = $this->_em->getConfiguration(); $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter"); - $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", DBALType::STRING); + $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", Types::STRING); // We get one user after enabling the filter $this->assertEquals(1, count($query->getResult())); @@ -513,7 +513,7 @@ public function testWhereOrFilter() $conf = $this->_em->getConfiguration(); $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter"); - $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", DBALType::STRING); + $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "bar_%", Types::STRING); // We get one user after enabling the filter $this->assertEquals(1, count($query->getResult())); @@ -532,7 +532,7 @@ private function useCMSArticleTopicFilter() { $conf = $this->_em->getConfiguration(); $conf->addFilter("article_topic", "\Doctrine\Tests\ORM\Functional\CMSArticleTopicFilter"); - $this->_em->getFilters()->enable("article_topic")->setParameter("topic", "Test1", DBALType::STRING); + $this->_em->getFilters()->enable("article_topic")->setParameter("topic", "Test1", Types::STRING); } public function testOneToMany_ExtraLazyCountWithFilter() @@ -579,7 +579,7 @@ private function useCMSGroupPrefixFilter() { $conf = $this->_em->getConfiguration(); $conf->addFilter("group_prefix", "\Doctrine\Tests\ORM\Functional\CMSGroupPrefixFilter"); - $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "foo%", DBALType::STRING); + $this->_em->getFilters()->enable("group_prefix")->setParameter("prefix", "foo%", Types::STRING); } public function testManyToMany_ExtraLazyCountWithFilter() @@ -758,7 +758,7 @@ public function testSingleTableInheritance_FilterOnlyOnRootTableWhenFetchingSubE $conf->addFilter("completed_contract", "\Doctrine\Tests\ORM\Functional\CompletedContractFilter"); $this->_em->getFilters() ->enable("completed_contract") - ->setParameter("completed", true, DBALType::BOOLEAN); + ->setParameter("completed", true, Types::BOOLEAN); $this->assertEquals(1, count($this->_em->getRepository(CompanyFlexUltraContract::class)->findAll())); $this->assertEquals(1, count($this->_em->createQuery("SELECT cfc FROM Doctrine\Tests\Models\Company\CompanyFlexUltraContract cfc")->getResult())); @@ -775,7 +775,7 @@ public function testSingleTableInheritance_FilterOnlyOnRootTableWhenFetchingRoot $conf->addFilter("completed_contract", "\Doctrine\Tests\ORM\Functional\CompletedContractFilter"); $this->_em->getFilters() ->enable("completed_contract") - ->setParameter("completed", true, DBALType::BOOLEAN); + ->setParameter("completed", true, Types::BOOLEAN); $this->assertEquals(2, count($this->_em->getRepository(CompanyFlexContract::class)->findAll())); $this->assertEquals(2, count($this->_em->createQuery("SELECT cfc FROM Doctrine\Tests\Models\Company\CompanyFlexContract cfc")->getResult())); @@ -834,7 +834,7 @@ private function useCompletedContractFilter() $conf->addFilter("completed_contract", "\Doctrine\Tests\ORM\Functional\CompletedContractFilter"); $this->_em->getFilters() ->enable("completed_contract") - ->setParameter("completed", true, DBALType::BOOLEAN); + ->setParameter("completed", true, Types::BOOLEAN); } public function testManyToMany_ExtraLazyCountWithFilterOnSTI() @@ -896,7 +896,7 @@ private function usePersonNameFilter($name) $conf->addFilter("person_name", "\Doctrine\Tests\ORM\Functional\CompanyPersonNameFilter"); $this->_em->getFilters() ->enable("person_name") - ->setParameter("name", $name, DBALType::STRING); + ->setParameter("name", $name, Types::STRING); } public function testManyToMany_ExtraLazyCountWithFilterOnCTI() diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php index d38fcb51b45..828cf1e4c93 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php @@ -21,7 +21,7 @@ protected function setUp() : void $conn = $this->_em->getConnection(); - if (strpos($conn->getDriver()->getName(), "sqlite") !== false) { + if ($conn->getDriver() instanceof \Doctrine\DBAL\Driver\PDO\SQLite\Driver) { $this->markTestSkipped('SQLite does not support ALTER TABLE statements.'); } $this->schemaTool = new Tools\SchemaTool($this->_em); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php index 53cca994671..1493c3b366a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC117Test.php @@ -269,8 +269,8 @@ public function testOneToOneCascadeRemove() */ public function testOneToOneCascadePersist() { - if ( ! $this->_em->getConnection()->getDatabasePlatform()->prefersSequences()) { - $this->markTestSkipped('Test only works with databases that prefer sequences as ID strategy.'); + if ( ! $this->_em->getConnection()->getDatabasePlatform()->supportsSequences()) { + $this->markTestSkipped('Test only works with databases that support sequences as ID strategy.'); } $this->article1 = new DDC117Article("Foo"); diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php index 2dccf237b31..156399ed3a1 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php @@ -4,6 +4,8 @@ use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Result; +use Doctrine\DBAL\Statement; use Doctrine\ORM\EntityManager; use Doctrine\ORM\Tools\ToolsException; use Doctrine\Tests\OrmFunctionalTestCase; @@ -98,327 +100,584 @@ class DDC3634JTIChildEntity extends DDC3634JTIBaseEntity { } -class DDC3634LastInsertIdMockingConnection extends Connection -{ - /** - * @var Connection - */ - private $realConnection; - - /** - * @var int - */ - private $identifier; - - /** - * @param int $identifier - * @param Connection $realConnection - */ - public function __construct($identifier, Connection $realConnection) - { - $this->realConnection = $realConnection; - $this->identifier = $identifier; - } +if (class_exists(Result::class)) { + class DDC3634LastInsertIdMockingConnection extends Connection + { + /** + * @var Connection + */ + private $realConnection; + + /** + * @var int + */ + private $identifier; + + /** + * @param int $identifier + * @param Connection $realConnection + */ + public function __construct($identifier, Connection $realConnection) + { + $this->realConnection = $realConnection; + $this->identifier = $identifier; + } - private function forwardCall() - { - $trace = debug_backtrace(0, 2)[1]; + private function forwardCall() + { + $trace = debug_backtrace(0, 2)[1]; - return call_user_func_array([$this->realConnection, $trace['function']], $trace['args']); - } + return call_user_func_array([$this->realConnection, $trace['function']], $trace['args']); + } - public function getParams() - { - return $this->forwardCall(); - } + public function getParams() + { + return $this->forwardCall(); + } - public function getDatabase() - { - return $this->forwardCall(); - } + public function getDatabase() + { + return $this->forwardCall(); + } - public function getHost() - { - return $this->forwardCall(); - } + public function getDriver() + { + return $this->forwardCall(); + } - public function getPort() - { - return $this->forwardCall(); - } + public function getConfiguration() + { + return $this->forwardCall(); + } - public function getUsername() - { - return $this->forwardCall(); - } + public function getEventManager() + { + return $this->forwardCall(); + } - public function getPassword() - { - return $this->forwardCall(); - } + public function getDatabasePlatform() + { + return $this->forwardCall(); + } - public function getDriver() - { - return $this->forwardCall(); - } + public function getExpressionBuilder() + { + return $this->forwardCall(); + } - public function getConfiguration() - { - return $this->forwardCall(); - } + public function connect() + { + return $this->forwardCall(); + } - public function getEventManager() - { - return $this->forwardCall(); - } + public function isAutoCommit() + { + return $this->forwardCall(); + } - public function getDatabasePlatform() - { - return $this->forwardCall(); - } + public function setAutoCommit($autoCommit) + { + return $this->forwardCall(); + } - public function getExpressionBuilder() - { - return $this->forwardCall(); - } + public function isConnected() + { + return $this->forwardCall(); + } - public function connect() - { - return $this->forwardCall(); - } + public function isTransactionActive() + { + return $this->forwardCall(); + } - public function isAutoCommit() - { - return $this->forwardCall(); - } + public function delete($tableExpression, array $identifier, array $types = []) + { + return $this->forwardCall(); + } - public function setAutoCommit($autoCommit) - { - return $this->forwardCall(); - } + public function close() + { + return $this->forwardCall(); + } - public function setFetchMode($fetchMode) - { - return $this->forwardCall(); - } + public function setTransactionIsolation($level) + { + return $this->forwardCall(); + } - public function fetchAssoc($statement, array $params = [], array $types = []) - { - return $this->forwardCall(); - } + public function getTransactionIsolation() + { + return $this->forwardCall(); + } - public function fetchArray($statement, array $params = [], array $types = []) - { - return $this->forwardCall(); - } + public function update($tableExpression, array $data, array $identifier, array $types = []) + { + return $this->forwardCall(); + } - public function fetchColumn($statement, array $params = [], $column = 0, array $types = []) - { - return $this->forwardCall(); - } + public function insert($tableExpression, array $data, array $types = []) + { + return $this->forwardCall(); + } - public function isConnected() - { - return $this->forwardCall(); - } + public function quoteIdentifier($str) + { + return $this->forwardCall(); + } - public function isTransactionActive() - { - return $this->forwardCall(); - } + public function quote($input, $type = null) + { + return $this->forwardCall(); + } - public function delete($tableExpression, array $identifier, array $types = []) - { - return $this->forwardCall(); - } + public function prepare($statement): Statement + { + return $this->forwardCall(); + } - public function close() - { - return $this->forwardCall(); - } + public function executeQuery($query, array $params = [], $types = [], QueryCacheProfile $qcp = null): Result + { + return $this->forwardCall(); + } - public function setTransactionIsolation($level) - { - return $this->forwardCall(); - } + public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qcp): Result + { + return $this->forwardCall(); + } - public function getTransactionIsolation() - { - return $this->forwardCall(); - } + public function query(string $sql): Result + { + return $this->forwardCall(); + } - public function update($tableExpression, array $data, array $identifier, array $types = []) - { - return $this->forwardCall(); - } + public function executeUpdate($query, array $params = [], array $types = []): int + { + return $this->forwardCall(); + } - public function insert($tableExpression, array $data, array $types = []) - { - return $this->forwardCall(); - } + public function exec($statement): int + { + return $this->forwardCall(); + } - public function quoteIdentifier($str) - { - return $this->forwardCall(); - } + public function getTransactionNestingLevel() + { + return $this->forwardCall(); + } - public function quote($input, $type = null) - { - return $this->forwardCall(); - } + public function lastInsertId($seqName = null) + { + return $this->identifier; + } - public function fetchAll($sql, array $params = [], $types = []) - { - return $this->forwardCall(); - } + public function transactional(\Closure $func) + { + return $this->forwardCall(); + } - public function prepare($statement) - { - return $this->forwardCall(); - } + public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints) + { + return $this->forwardCall(); + } - public function executeQuery($query, array $params = [], $types = [], QueryCacheProfile $qcp = null) - { - return $this->forwardCall(); - } + public function getNestTransactionsWithSavepoints() + { + return $this->forwardCall(); + } - public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qcp) - { - return $this->forwardCall(); - } + protected function _getNestedTransactionSavePointName() + { + return $this->forwardCall(); + } - public function project($query, array $params, \Closure $function) - { - return $this->forwardCall(); - } + public function beginTransaction() + { + return $this->forwardCall(); + } - public function query() - { - return $this->forwardCall(); - } + public function commit() + { + return $this->forwardCall(); + } - public function executeUpdate($query, array $params = [], array $types = []) - { - return $this->forwardCall(); - } + public function rollBack() + { + return $this->forwardCall(); + } - public function exec($statement) - { - return $this->forwardCall(); - } + public function createSavepoint($savepoint) + { + return $this->forwardCall(); + } - public function getTransactionNestingLevel() - { - return $this->forwardCall(); - } + public function releaseSavepoint($savepoint) + { + return $this->forwardCall(); + } - public function errorCode() - { - return $this->forwardCall(); - } + public function rollbackSavepoint($savepoint) + { + return $this->forwardCall(); + } - public function errorInfo() - { - return $this->forwardCall(); - } + public function getWrappedConnection() + { + return $this->forwardCall(); + } - public function lastInsertId($seqName = null) - { - return $this->identifier; - } + public function getSchemaManager() + { + return $this->forwardCall(); + } - public function transactional(\Closure $func) - { - return $this->forwardCall(); - } + public function setRollbackOnly() + { + return $this->forwardCall(); + } - public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints) - { - return $this->forwardCall(); - } + public function isRollbackOnly() + { + return $this->forwardCall(); + } - public function getNestTransactionsWithSavepoints() - { - return $this->forwardCall(); - } + public function convertToDatabaseValue($value, $type) + { + return $this->forwardCall(); + } - protected function _getNestedTransactionSavePointName() - { - return $this->forwardCall(); - } + public function convertToPHPValue($value, $type) + { + return $this->forwardCall(); + } - public function beginTransaction() - { - return $this->forwardCall(); + public function createQueryBuilder() + { + return $this->forwardCall(); + } } +} else { + class DDC3634LastInsertIdMockingConnection extends Connection + { + /** + * @var Connection + */ + private $realConnection; + + /** + * @var int + */ + private $identifier; + + /** + * @param int $identifier + * @param Connection $realConnection + */ + public function __construct($identifier, Connection $realConnection) + { + $this->realConnection = $realConnection; + $this->identifier = $identifier; + } - public function commit() - { - return $this->forwardCall(); - } + private function forwardCall() + { + $trace = debug_backtrace(0, 2)[1]; - public function rollBack() - { - return $this->forwardCall(); - } + return call_user_func_array([$this->realConnection, $trace['function']], $trace['args']); + } - public function createSavepoint($savepoint) - { - return $this->forwardCall(); - } + public function getParams() + { + return $this->forwardCall(); + } - public function releaseSavepoint($savepoint) - { - return $this->forwardCall(); - } + public function getDatabase() + { + return $this->forwardCall(); + } - public function rollbackSavepoint($savepoint) - { - return $this->forwardCall(); - } + public function getHost() + { + return $this->forwardCall(); + } - public function getWrappedConnection() - { - return $this->forwardCall(); - } + public function getPort() + { + return $this->forwardCall(); + } - public function getSchemaManager() - { - return $this->forwardCall(); - } + public function getUsername() + { + return $this->forwardCall(); + } - public function setRollbackOnly() - { - return $this->forwardCall(); - } + public function getPassword() + { + return $this->forwardCall(); + } - public function isRollbackOnly() - { - return $this->forwardCall(); - } + public function getDriver() + { + return $this->forwardCall(); + } - public function convertToDatabaseValue($value, $type) - { - return $this->forwardCall(); - } + public function getConfiguration() + { + return $this->forwardCall(); + } - public function convertToPHPValue($value, $type) - { - return $this->forwardCall(); - } + public function getEventManager() + { + return $this->forwardCall(); + } - public function resolveParams(array $params, array $types) - { - return $this->forwardCall(); - } + public function getDatabasePlatform() + { + return $this->forwardCall(); + } - public function createQueryBuilder() - { - return $this->forwardCall(); - } + public function getExpressionBuilder() + { + return $this->forwardCall(); + } - public function ping() - { - return $this->forwardCall(); + public function connect() + { + return $this->forwardCall(); + } + + public function isAutoCommit() + { + return $this->forwardCall(); + } + + public function setAutoCommit($autoCommit) + { + return $this->forwardCall(); + } + + public function setFetchMode($fetchMode) + { + return $this->forwardCall(); + } + + public function fetchAssoc($statement, array $params = [], array $types = []) + { + return $this->forwardCall(); + } + + public function fetchArray($statement, array $params = [], array $types = []) + { + return $this->forwardCall(); + } + + public function fetchOne($statement, array $params = [], $column = 0, array $types = []) + { + return $this->forwardCall(); + } + + public function isConnected() + { + return $this->forwardCall(); + } + + public function isTransactionActive() + { + return $this->forwardCall(); + } + + public function delete($tableExpression, array $identifier, array $types = []) + { + return $this->forwardCall(); + } + + public function close() + { + return $this->forwardCall(); + } + + public function setTransactionIsolation($level) + { + return $this->forwardCall(); + } + + public function getTransactionIsolation() + { + return $this->forwardCall(); + } + + public function update($tableExpression, array $data, array $identifier, array $types = []) + { + return $this->forwardCall(); + } + + public function insert($tableExpression, array $data, array $types = []) + { + return $this->forwardCall(); + } + + public function quoteIdentifier($str) + { + return $this->forwardCall(); + } + + public function quote($input, $type = null) + { + return $this->forwardCall(); + } + + public function fetchAll($sql, array $params = [], $types = []) + { + return $this->forwardCall(); + } + + public function prepare($statement) + { + return $this->forwardCall(); + } + + public function executeQuery($query, array $params = [], $types = [], QueryCacheProfile $qcp = null) + { + return $this->forwardCall(); + } + + public function executeCacheQuery($query, $params, $types, QueryCacheProfile $qcp) + { + return $this->forwardCall(); + } + + public function project($query, array $params, \Closure $function) + { + return $this->forwardCall(); + } + + public function query() + { + return $this->forwardCall(); + } + + public function executeUpdate($query, array $params = [], array $types = []) + { + return $this->forwardCall(); + } + + public function exec($statement) + { + return $this->forwardCall(); + } + + public function getTransactionNestingLevel() + { + return $this->forwardCall(); + } + + public function errorCode() + { + return $this->forwardCall(); + } + + public function errorInfo() + { + return $this->forwardCall(); + } + + public function lastInsertId($seqName = null) + { + return $this->identifier; + } + + public function transactional(\Closure $func) + { + return $this->forwardCall(); + } + + public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints) + { + return $this->forwardCall(); + } + + public function getNestTransactionsWithSavepoints() + { + return $this->forwardCall(); + } + + protected function _getNestedTransactionSavePointName() + { + return $this->forwardCall(); + } + + public function beginTransaction() + { + return $this->forwardCall(); + } + + public function commit() + { + return $this->forwardCall(); + } + + public function rollBack() + { + return $this->forwardCall(); + } + + public function createSavepoint($savepoint) + { + return $this->forwardCall(); + } + + public function releaseSavepoint($savepoint) + { + return $this->forwardCall(); + } + + public function rollbackSavepoint($savepoint) + { + return $this->forwardCall(); + } + + public function getWrappedConnection() + { + return $this->forwardCall(); + } + + public function getSchemaManager() + { + return $this->forwardCall(); + } + + public function setRollbackOnly() + { + return $this->forwardCall(); + } + + public function isRollbackOnly() + { + return $this->forwardCall(); + } + + public function convertToDatabaseValue($value, $type) + { + return $this->forwardCall(); + } + + public function convertToPHPValue($value, $type) + { + return $this->forwardCall(); + } + + public function resolveParams(array $params, array $types) + { + return $this->forwardCall(); + } + + public function createQueryBuilder() + { + return $this->forwardCall(); + } + + public function ping() + { + return $this->forwardCall(); + } } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php index dc4b31669e7..238a949bfc4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC422Test.php @@ -39,7 +39,7 @@ public function testIssue() $this->assertFalse($customer->contacts->isInitialized()); $this->_em->flush(); - $this->assertEquals(1, $this->_em->getConnection()->fetchColumn("select count(*) from ddc422_customers_contacts")); + $this->assertEquals(1, $this->_em->getConnection()->fetchOne("select count(*) from ddc422_customers_contacts")); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php index 9c5ea5cda69..7c8f2e13252 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC425Test.php @@ -1,7 +1,8 @@ _em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); $num = $this->_em->createQuery('DELETE '.__NAMESPACE__.'\DDC425Entity e WHERE e.someDatetimeField > ?1') - ->setParameter(1, new DateTime, Type::DATETIME) + ->setParameter(1, new DateTime, Types::DATETIME_MUTABLE) ->getResult(); $this->assertEquals(0, $num); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php index 0205f99d92e..128263560e4 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC832Test.php @@ -14,8 +14,6 @@ protected function setUp() : void $this->markTestSkipped('Doesnt run on Oracle.'); } - $this->_em->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger()); - try { $this->_schemaTool->createSchema( [ diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6362Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6362Test.php index 40259653d53..7783a34b84e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6362Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/GH6362Test.php @@ -2,10 +2,11 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\Tests\Mocks\HydratorMockStatement; +use Doctrine\Tests\Mocks\ResultMock; use Doctrine\Tests\OrmFunctionalTestCase; use Doctrine\ORM\Query; use Doctrine\ORM\Query\ResultSetMapping; -use Doctrine\Tests\Mocks\HydratorMockStatement; final class GH6362Test extends OrmFunctionalTestCase { @@ -66,7 +67,7 @@ public function testInheritanceJoinAlias() ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); diff --git a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php index 0771e30da4e..840b6ec9047 100644 --- a/tests/Doctrine/Tests/ORM/Functional/TypeTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/TypeTest.php @@ -2,8 +2,7 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\DBAL\Types\Type as DBALType; -use Doctrine\ORM\Mapping\AssociationMapping; +use Doctrine\DBAL\Types\Types; use Doctrine\Tests\Models\Generic\BooleanModel; use Doctrine\Tests\Models\Generic\DateTimeModel; use Doctrine\Tests\Models\Generic\DecimalModel; @@ -143,7 +142,7 @@ public function testDqlQueryBindDateTimeInstance() $this->_em->clear(); $dateTimeDb = $this->_em->createQuery('SELECT d FROM Doctrine\Tests\Models\Generic\DateTimeModel d WHERE d.datetime = ?1') - ->setParameter(1, $date, DBALType::DATETIME) + ->setParameter(1, $date, Types::DATETIME_MUTABLE) ->getSingleResult(); $this->assertInstanceOf(\DateTime::class, $dateTimeDb->datetime); @@ -165,7 +164,7 @@ public function testDqlQueryBuilderBindDateTimeInstance() ->select('d') ->from(DateTimeModel::class, 'd') ->where('d.datetime = ?1') - ->setParameter(1, $date, DBALType::DATETIME) + ->setParameter(1, $date, Types::DATETIME_MUTABLE) ->getQuery()->getSingleResult(); $this->assertInstanceOf(\DateTime::class, $dateTimeDb->datetime); diff --git a/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php b/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php index b51d5a133f1..d2b9b4db71c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/TypeValueSqlTest.php @@ -45,7 +45,7 @@ public function testUpperCaseStringType() $entity = $this->_em->find('\Doctrine\Tests\Models\CustomType\CustomTypeUpperCase', $id); $this->assertEquals('foo', $entity->lowerCaseString, 'Entity holds lowercase string'); - $this->assertEquals('FOO', $this->_em->getConnection()->fetchColumn("select lowerCaseString from customtype_uppercases where id=".$entity->id.""), 'Database holds uppercase string'); + $this->assertEquals('FOO', $this->_em->getConnection()->fetchOne("select lowerCaseString from customtype_uppercases where id=".$entity->id.""), 'Database holds uppercase string'); } /** @@ -67,7 +67,7 @@ public function testUpperCaseStringTypeWhenColumnNameIsDefined() $entity = $this->_em->find('\Doctrine\Tests\Models\CustomType\CustomTypeUpperCase', $id); $this->assertEquals('foo', $entity->namedLowerCaseString, 'Entity holds lowercase string'); - $this->assertEquals('FOO', $this->_em->getConnection()->fetchColumn("select named_lower_case_string from customtype_uppercases where id=".$entity->id.""), 'Database holds uppercase string'); + $this->assertEquals('FOO', $this->_em->getConnection()->fetchOne("select named_lower_case_string from customtype_uppercases where id=".$entity->id.""), 'Database holds uppercase string'); $entity->namedLowerCaseString = 'bar'; @@ -82,7 +82,7 @@ public function testUpperCaseStringTypeWhenColumnNameIsDefined() $entity = $this->_em->find('\Doctrine\Tests\Models\CustomType\CustomTypeUpperCase', $id); $this->assertEquals('bar', $entity->namedLowerCaseString, 'Entity holds lowercase string'); - $this->assertEquals('BAR', $this->_em->getConnection()->fetchColumn("select named_lower_case_string from customtype_uppercases where id=".$entity->id.""), 'Database holds uppercase string'); + $this->assertEquals('BAR', $this->_em->getConnection()->fetchOne("select named_lower_case_string from customtype_uppercases where id=".$entity->id.""), 'Database holds uppercase string'); } public function testTypeValueSqlWithAssociations() @@ -109,7 +109,7 @@ public function testTypeValueSqlWithAssociations() $entity = $this->_em->find(CustomTypeParent::class, $parentId); $this->assertTrue($entity->customInteger < 0, 'Fetched customInteger negative'); - $this->assertEquals(1, $this->_em->getConnection()->fetchColumn("select customInteger from customtype_parents where id=".$entity->id.""), 'Database has stored customInteger positive'); + $this->assertEquals(1, $this->_em->getConnection()->fetchOne("select customInteger from customtype_parents where id=".$entity->id.""), 'Database has stored customInteger positive'); $this->assertNotNull($parent->child, 'Child attached'); $this->assertCount(2, $entity->getMyFriends(), '2 friends attached'); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php index e314e8172e7..a611bf35b21 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php @@ -58,16 +58,16 @@ public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); - $this->assertEquals('nop', $conn->fetchColumn('SELECT id4 FROM vct_auxiliary LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT id4 FROM vct_auxiliary LIMIT 1')); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT id1 FROM vct_inversed_manytomany_compositeid_foreignkey LIMIT 1')); - $this->assertEquals('nop', $conn->fetchColumn('SELECT foreign_id FROM vct_inversed_manytomany_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchOne('SELECT id1 FROM vct_inversed_manytomany_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT foreign_id FROM vct_inversed_manytomany_compositeid_foreignkey LIMIT 1')); - $this->assertEquals('tuv', $conn->fetchColumn('SELECT id2 FROM vct_owning_manytomany_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('tuv', $conn->fetchOne('SELECT id2 FROM vct_owning_manytomany_compositeid_foreignkey LIMIT 1')); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT associated_id FROM vct_xref_manytomany_compositeid_foreignkey LIMIT 1')); - $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_foreign_id FROM vct_xref_manytomany_compositeid_foreignkey LIMIT 1')); - $this->assertEquals('tuv', $conn->fetchColumn('SELECT owning_id FROM vct_xref_manytomany_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchOne('SELECT associated_id FROM vct_xref_manytomany_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT associated_foreign_id FROM vct_xref_manytomany_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('tuv', $conn->fetchOne('SELECT owning_id FROM vct_xref_manytomany_compositeid_foreignkey LIMIT 1')); } /** @@ -190,6 +190,6 @@ public function testThatTheJoinTableRowsAreRemovedWhenRemovingTheAssociation() // test association is removed - $this->assertEquals(0, $conn->fetchColumn('SELECT COUNT(*) FROM vct_xref_manytomany_compositeid_foreignkey')); + $this->assertEquals(0, $conn->fetchOne('SELECT COUNT(*) FROM vct_xref_manytomany_compositeid_foreignkey')); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php index 99bec4a4a50..5b08b7ac1ef 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php @@ -52,14 +52,14 @@ public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); - $this->assertEquals('nop', $conn->fetchColumn('SELECT id1 FROM vct_inversed_manytomany_compositeid LIMIT 1')); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT id2 FROM vct_inversed_manytomany_compositeid LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT id1 FROM vct_inversed_manytomany_compositeid LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchOne('SELECT id2 FROM vct_inversed_manytomany_compositeid LIMIT 1')); - $this->assertEquals('tuv', $conn->fetchColumn('SELECT id3 FROM vct_owning_manytomany_compositeid LIMIT 1')); + $this->assertEquals('tuv', $conn->fetchOne('SELECT id3 FROM vct_owning_manytomany_compositeid LIMIT 1')); - $this->assertEquals('nop', $conn->fetchColumn('SELECT inversed_id1 FROM vct_xref_manytomany_compositeid LIMIT 1')); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT inversed_id2 FROM vct_xref_manytomany_compositeid LIMIT 1')); - $this->assertEquals('tuv', $conn->fetchColumn('SELECT owning_id FROM vct_xref_manytomany_compositeid LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT inversed_id1 FROM vct_xref_manytomany_compositeid LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchOne('SELECT inversed_id2 FROM vct_xref_manytomany_compositeid LIMIT 1')); + $this->assertEquals('tuv', $conn->fetchOne('SELECT owning_id FROM vct_xref_manytomany_compositeid LIMIT 1')); } /** @@ -152,6 +152,6 @@ public function testThatTheJoinTableRowsAreRemovedWhenRemovingTheAssociation() // test association is removed - $this->assertEquals(0, $conn->fetchColumn('SELECT COUNT(*) FROM vct_xref_manytomany_compositeid')); + $this->assertEquals(0, $conn->fetchOne('SELECT COUNT(*) FROM vct_xref_manytomany_compositeid')); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php index 4ebec8d071f..77aac782e0d 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php @@ -51,12 +51,12 @@ public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); - $this->assertEquals('nop', $conn->fetchColumn('SELECT id1 FROM vct_inversed_manytomany LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT id1 FROM vct_inversed_manytomany LIMIT 1')); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT id2 FROM vct_owning_manytomany LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchOne('SELECT id2 FROM vct_owning_manytomany LIMIT 1')); - $this->assertEquals('nop', $conn->fetchColumn('SELECT inversed_id FROM vct_xref_manytomany LIMIT 1')); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT owning_id FROM vct_xref_manytomany LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT inversed_id FROM vct_xref_manytomany LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchOne('SELECT owning_id FROM vct_xref_manytomany LIMIT 1')); } /** @@ -148,6 +148,6 @@ public function testThatTheJoinTableRowsAreRemovedWhenRemovingTheAssociation() // test association is removed - $this->assertEquals(0, $conn->fetchColumn('SELECT COUNT(*) FROM vct_xref_manytomany')); + $this->assertEquals(0, $conn->fetchOne('SELECT COUNT(*) FROM vct_xref_manytomany')); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php index a8e017b0c96..8e542758b50 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php @@ -58,14 +58,14 @@ public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); - $this->assertEquals('nop', $conn->fetchColumn('SELECT id4 FROM vct_auxiliary LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT id4 FROM vct_auxiliary LIMIT 1')); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT id1 FROM vct_inversed_onetomany_compositeid_foreignkey LIMIT 1')); - $this->assertEquals('nop', $conn->fetchColumn('SELECT foreign_id FROM vct_inversed_onetomany_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchOne('SELECT id1 FROM vct_inversed_onetomany_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT foreign_id FROM vct_inversed_onetomany_compositeid_foreignkey LIMIT 1')); - $this->assertEquals('tuv', $conn->fetchColumn('SELECT id2 FROM vct_owning_manytoone_compositeid_foreignkey LIMIT 1')); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT associated_id FROM vct_owning_manytoone_compositeid_foreignkey LIMIT 1')); - $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_foreign_id FROM vct_owning_manytoone_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('tuv', $conn->fetchOne('SELECT id2 FROM vct_owning_manytoone_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchOne('SELECT associated_id FROM vct_owning_manytoone_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT associated_foreign_id FROM vct_owning_manytoone_compositeid_foreignkey LIMIT 1')); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php index 359def14337..70ef76c8fb2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php @@ -52,12 +52,12 @@ public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); - $this->assertEquals('nop', $conn->fetchColumn('SELECT id1 FROM vct_inversed_onetomany_compositeid LIMIT 1')); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT id2 FROM vct_inversed_onetomany_compositeid LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT id1 FROM vct_inversed_onetomany_compositeid LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchOne('SELECT id2 FROM vct_inversed_onetomany_compositeid LIMIT 1')); - $this->assertEquals('tuv', $conn->fetchColumn('SELECT id3 FROM vct_owning_manytoone_compositeid LIMIT 1')); - $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_id1 FROM vct_owning_manytoone_compositeid LIMIT 1')); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT associated_id2 FROM vct_owning_manytoone_compositeid LIMIT 1')); + $this->assertEquals('tuv', $conn->fetchOne('SELECT id3 FROM vct_owning_manytoone_compositeid LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT associated_id1 FROM vct_owning_manytoone_compositeid LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchOne('SELECT associated_id2 FROM vct_owning_manytoone_compositeid LIMIT 1')); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php index f210e2ec84f..c01d41e7c65 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php @@ -51,10 +51,10 @@ public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); - $this->assertEquals('nop', $conn->fetchColumn('SELECT id1 FROM vct_inversed_onetomany LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT id1 FROM vct_inversed_onetomany LIMIT 1')); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT id2 FROM vct_owning_manytoone LIMIT 1')); - $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_id FROM vct_owning_manytoone LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchOne('SELECT id2 FROM vct_owning_manytoone LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT associated_id FROM vct_owning_manytoone LIMIT 1')); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php index f5bd984c043..38e65d6f2ad 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php @@ -57,14 +57,14 @@ public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); - $this->assertEquals('nop', $conn->fetchColumn('SELECT id4 FROM vct_auxiliary LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT id4 FROM vct_auxiliary LIMIT 1')); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT id1 FROM vct_inversed_onetoone_compositeid_foreignkey LIMIT 1')); - $this->assertEquals('nop', $conn->fetchColumn('SELECT foreign_id FROM vct_inversed_onetoone_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchOne('SELECT id1 FROM vct_inversed_onetoone_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT foreign_id FROM vct_inversed_onetoone_compositeid_foreignkey LIMIT 1')); - $this->assertEquals('tuv', $conn->fetchColumn('SELECT id2 FROM vct_owning_onetoone_compositeid_foreignkey LIMIT 1')); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT associated_id FROM vct_owning_onetoone_compositeid_foreignkey LIMIT 1')); - $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_foreign_id FROM vct_owning_onetoone_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('tuv', $conn->fetchOne('SELECT id2 FROM vct_owning_onetoone_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchOne('SELECT associated_id FROM vct_owning_onetoone_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT associated_foreign_id FROM vct_owning_onetoone_compositeid_foreignkey LIMIT 1')); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php index df63a3906ec..f5e3a0a5fc2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php @@ -51,12 +51,12 @@ public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); - $this->assertEquals('nop', $conn->fetchColumn('SELECT id1 FROM vct_inversed_onetoone_compositeid LIMIT 1')); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT id2 FROM vct_inversed_onetoone_compositeid LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT id1 FROM vct_inversed_onetoone_compositeid LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchOne('SELECT id2 FROM vct_inversed_onetoone_compositeid LIMIT 1')); - $this->assertEquals('tuv', $conn->fetchColumn('SELECT id3 FROM vct_owning_onetoone_compositeid LIMIT 1')); - $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_id1 FROM vct_owning_onetoone_compositeid LIMIT 1')); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT associated_id2 FROM vct_owning_onetoone_compositeid LIMIT 1')); + $this->assertEquals('tuv', $conn->fetchOne('SELECT id3 FROM vct_owning_onetoone_compositeid LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT associated_id1 FROM vct_owning_onetoone_compositeid LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchOne('SELECT associated_id2 FROM vct_owning_onetoone_compositeid LIMIT 1')); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php index 9bba31c7529..ef5300574c2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php @@ -51,10 +51,10 @@ public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); - $this->assertEquals('nop', $conn->fetchColumn('SELECT id1 FROM vct_inversed_onetoone LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT id1 FROM vct_inversed_onetoone LIMIT 1')); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT id2 FROM vct_owning_onetoone LIMIT 1')); - $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_id FROM vct_owning_onetoone LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchOne('SELECT id2 FROM vct_owning_onetoone LIMIT 1')); + $this->assertEquals('nop', $conn->fetchOne('SELECT associated_id FROM vct_owning_onetoone LIMIT 1')); } /** diff --git a/tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php index 40a3d03233e..55982d3209e 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/AbstractHydratorTest.php @@ -4,7 +4,7 @@ use Doctrine\Common\EventManager; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Driver\Statement; +use Doctrine\DBAL\Statement; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Events; use Doctrine\ORM\Internal\Hydration\AbstractHydrator; @@ -58,6 +58,10 @@ protected function setUp() : void ->expects(self::any()) ->method('fetch') ->willReturn(false); + $this->mockStatement + ->expects(self::any()) + ->method('fetchAssociative') + ->willReturn(false); $this->hydrator = $this ->getMockBuilder(AbstractHydrator::class) diff --git a/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php index 6c0b30ef655..e941cc75914 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php @@ -4,6 +4,7 @@ use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\Tests\Mocks\HydratorMockStatement; +use Doctrine\Tests\Mocks\ResultMock; use Doctrine\Tests\Models\CMS\CmsArticle; use Doctrine\Tests\Models\CMS\CmsComment; use Doctrine\Tests\Models\CMS\CmsPhonenumber; @@ -47,7 +48,7 @@ public function testSimpleEntityQuery() ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -91,7 +92,7 @@ public function testSimpleEntityWithScalarQuery($userEntityKey) ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -139,7 +140,7 @@ public function testSimpleEntityQueryWithAliasedUserEntity() ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -186,7 +187,7 @@ public function testSimpleMultipleRootEntityQuery() ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -236,7 +237,7 @@ public function testSimpleMultipleRootEntityQueryWithAliasedUserEntity() ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -290,7 +291,7 @@ public function testSimpleMultipleRootEntityQueryWithAliasedArticleEntity() ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -344,7 +345,7 @@ public function testSimpleMultipleRootEntityQueryWithAliasedEntities() ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -399,7 +400,7 @@ public function testMixedQueryNormalJoin($userEntityKey) ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -463,7 +464,7 @@ public function testMixedQueryFetchJoin($userEntityKey) ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -537,7 +538,7 @@ public function testMixedQueryFetchJoinCustomIndex($userEntityKey) ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -651,7 +652,7 @@ public function testMixedQueryMultipleFetchJoin() ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -790,7 +791,7 @@ public function testMixedQueryMultipleDeepMixedFetchJoin() ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -904,7 +905,7 @@ public function testEntityQueryCustomResultSetOrder() ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -967,7 +968,7 @@ public function testChainedJoinWithScalars($entityKey) ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -1016,7 +1017,7 @@ public function testResultIteration() ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $iterator = $hydrator->iterate($stmt, $rsm); $rowNum = 0; @@ -1061,7 +1062,7 @@ public function testResultIterationWithAliasedUserEntity() ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $iterator = $hydrator->iterate($stmt, $rsm); $rowNum = 0; @@ -1106,7 +1107,7 @@ public function testSkipUnknownColumns() ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -1157,7 +1158,7 @@ public function testMissingIdForRootEntity($userEntityKey) ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -1207,7 +1208,7 @@ public function testIndexByAndMixedResult($userEntityKey) ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\ArrayHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); diff --git a/tests/Doctrine/Tests/ORM/Hydration/CustomHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/CustomHydratorTest.php index 7342b942f4f..8d12fcbc853 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/CustomHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/CustomHydratorTest.php @@ -23,6 +23,6 @@ class CustomHydrator extends AbstractHydrator { protected function hydrateAllData() { - return $this->_stmt->fetchAll(PDO::FETCH_ASSOC); + return $this->_stmt->fetchAllAssociative(); } } diff --git a/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php index 70524e9a7ff..45a89b3b59a 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php @@ -9,6 +9,7 @@ use Doctrine\ORM\Query; use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\Tests\Mocks\HydratorMockStatement; +use Doctrine\Tests\Mocks\ResultMock; use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsArticle; use Doctrine\Tests\Models\CMS\CmsComment; @@ -76,7 +77,7 @@ public function testSimpleEntityQuery() ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -115,7 +116,7 @@ public function testSimpleEntityQueryWithAliasedUserEntity() ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -164,7 +165,7 @@ public function testSimpleMultipleRootEntityQuery() ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -218,7 +219,7 @@ public function testSimpleMultipleRootEntityQueryWithAliasedUserEntity() ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -279,7 +280,7 @@ public function testSimpleMultipleRootEntityQueryWithAliasedArticleEntity() ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -340,7 +341,7 @@ public function testSimpleMultipleRootEntityQueryWithAliasedEntities() ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -402,7 +403,7 @@ public function testMixedQueryNormalJoin($userEntityKey) ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -466,7 +467,7 @@ public function testMixedQueryFetchJoin($userEntityKey) ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -547,7 +548,7 @@ public function testMixedQueryFetchJoinCustomIndex($userEntityKey) ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -661,7 +662,7 @@ public function testMixedQueryMultipleFetchJoin($userEntityKey) ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -791,7 +792,7 @@ public function testMixedQueryMultipleDeepMixedFetchJoin($userEntityKey) ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -904,7 +905,7 @@ public function testEntityQueryCustomResultSetOrder() ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -947,7 +948,7 @@ public function testSkipUnknownColumns() ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -980,7 +981,7 @@ public function testScalarQueryWithoutResultVariables($userEntityKey) ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -1036,7 +1037,7 @@ public function testCreatesProxyForLazyLoadingWithForeignKeys() $metadata = $this->_em->getClassMetadata(ECommerceProduct::class); $metadata->associationMappings['shipping']['fetch'] = ClassMetadata::FETCH_LAZY; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -1085,7 +1086,7 @@ public function testCreatesProxyForLazyLoadingWithForeignKeysWithAliasedProductE $metadata = $this->_em->getClassMetadata(ECommerceProduct::class); $metadata->associationMappings['shipping']['fetch'] = ClassMetadata::FETCH_LAZY; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -1145,7 +1146,7 @@ public function testChainedJoinWithEmptyCollections() ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -1208,7 +1209,7 @@ public function testChainedJoinWithEmptyCollectionsWithAliasedUserEntity() ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -1250,7 +1251,7 @@ public function testResultIteration() $hydrator = new ObjectHydrator($this->_em); $iterableResult = $hydrator->iterate( - new HydratorMockStatement($resultSet), + class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet), $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true] ); @@ -1274,7 +1275,7 @@ public function testResultIteration() self::assertSame(2, $rowNum); $iterableResult = $hydrator->toIterable( - new HydratorMockStatement($resultSet), + class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet), $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true] ); @@ -1325,7 +1326,7 @@ public function testResultIterationWithAliasedUserEntity() $hydrator = new ObjectHydrator($this->_em); $rowNum = 0; $iterableResult = $hydrator->iterate( - new HydratorMockStatement($resultSet), + class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet), $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true] ); @@ -1351,7 +1352,7 @@ public function testResultIterationWithAliasedUserEntity() $rowNum = 0; $iterableResult = $hydrator->toIterable( - new HydratorMockStatement($resultSet), + class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet), $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true] ); @@ -1485,7 +1486,7 @@ public function testManyToManyHydration() ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -1608,7 +1609,7 @@ public function testManyToManyHydrationWithAliasedUserEntity() ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -1666,7 +1667,7 @@ public function testMissingIdForRootEntity($userEntityKey) ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -1736,7 +1737,7 @@ public function testMissingIdForCollectionValuedChildEntity($userEntityKey) ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -1790,7 +1791,7 @@ public function testMissingIdForSingleValuedChildEntity($userEntityKey) ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -1832,7 +1833,7 @@ public function testIndexByAndMixedResult($userEntityKey) ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -1870,7 +1871,7 @@ public function testIndexByScalarsOnly($userEntityKey) ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm, [Query::HINT_FORCE_PARTIAL_LOAD => true]); @@ -1905,7 +1906,7 @@ public function testMissingMetaMappingException() ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $hydrator->hydrateAll($stmt, $rsm); } @@ -1938,7 +1939,7 @@ public function testMissingDiscriminatorColumnException() ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $hydrator->hydrateAll($stmt, $rsm); } @@ -1966,7 +1967,7 @@ public function testInvalidDiscriminatorValueException() ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $hydrator->hydrateAll($stmt, $rsm); } @@ -1987,7 +1988,7 @@ public function testFetchJoinCollectionValuedAssociationWithDefaultArrayValue() ] ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); diff --git a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php index dd2aab48f5a..cd37a931989 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php @@ -4,6 +4,7 @@ use Doctrine\ORM\Internal\Hydration\ScalarHydrator; use Doctrine\Tests\Mocks\HydratorMockStatement; +use Doctrine\Tests\Mocks\ResultMock; use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\Tests\Models\CMS\CmsUser; @@ -32,7 +33,7 @@ public function testNewHydrationSimpleEntityQuery() ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ScalarHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); @@ -63,7 +64,7 @@ public function testHydrateScalarResults() ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ScalarHydrator($this->_em); self::assertCount(1, $hydrator->hydrateAll($stmt, $rsm)); @@ -93,7 +94,7 @@ public function testSkipUnknownColumns() ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new ScalarHydrator($this->_em); self::assertCount(1, $hydrator->hydrateAll($stmt, $rsm)); diff --git a/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php index 76c286ab545..d587fdd9e25 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php @@ -4,6 +4,7 @@ use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\Tests\Mocks\HydratorMockStatement; +use Doctrine\Tests\Mocks\ResultMock; use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\Company\CompanyPerson; use Doctrine\Tests\Models\Issue5989\Issue5989Employee; @@ -32,7 +33,7 @@ public function testMissingDiscriminatorColumnException() ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em); $hydrator->hydrateAll($stmt, $rsm); } @@ -55,7 +56,7 @@ public function testExtraFieldInResultSetShouldBeIgnore() $expectedEntity->id = 1; $expectedEntity->city = 'Cracow'; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); $this->assertEquals($result[0], $expectedEntity); @@ -85,7 +86,7 @@ public function testInvalidDiscriminatorValueException() ], ]; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em); $hydrator->hydrateAll($stmt, $rsm); } @@ -114,7 +115,7 @@ public function testNullValueShouldNotOverwriteFieldWithSameNameInJoinedInherita $expectedEntity->id = 1; $expectedEntity->tags = ['tag1', 'tag2']; - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new \Doctrine\ORM\Internal\Hydration\SimpleObjectHydrator($this->_em); $result = $hydrator->hydrateAll($stmt, $rsm); $this->assertEquals($result[0], $expectedEntity); diff --git a/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php index f9d91be638d..77c97b8433e 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/SingleScalarHydratorTest.php @@ -5,6 +5,7 @@ use Doctrine\ORM\Internal\Hydration\SingleScalarHydrator; use Doctrine\ORM\NonUniqueResultException; use Doctrine\Tests\Mocks\HydratorMockStatement; +use Doctrine\Tests\Mocks\ResultMock; use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\Tests\Models\CMS\CmsUser; @@ -69,7 +70,7 @@ public function testHydrateSingleScalar($name, $resultSet) $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); - $stmt = new HydratorMockStatement($resultSet); + $stmt = class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new HydratorMockStatement($resultSet); $hydrator = new SingleScalarHydrator($this->_em); if ($name === 'result1') { diff --git a/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php b/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php index 5e4247715b0..237eeda37d9 100644 --- a/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Id/SequenceGeneratorTest.php @@ -5,7 +5,8 @@ use Doctrine\ORM\EntityManager; use Doctrine\ORM\Id\SequenceGenerator; use Doctrine\Tests\Mocks\ConnectionMock; -use Doctrine\Tests\Mocks\StatementArrayMock; +use Doctrine\Tests\Mocks\ResultMock; +use Doctrine\Tests\Mocks\StatementMock; use Doctrine\Tests\OrmTestCase; class SequenceGeneratorTest extends OrmTestCase @@ -45,7 +46,10 @@ public function testGeneration() : void for ($i = 0; $i < 42; ++$i) { if ($i % 10 == 0) { - $this->connection->setQueryResult(new StatementArrayMock([[(int)($i / 10) * 10]])); + $resultSet = [[(int)($i / 10) * 10]]; + $this->connection->setQueryResult( + class_exists(\Doctrine\DBAL\Result::class) ? new ResultMock($resultSet) : new StatementMock($resultSet) + ); } $id = $this->sequenceGenerator->generate($this->entityManager, null); diff --git a/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php b/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php index 35e9bf2f57e..eadfb2be958 100644 --- a/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php @@ -2,9 +2,9 @@ namespace Doctrine\Tests\ORM\Query; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Query\ParameterTypeInferer; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Types\Type; use Doctrine\Tests\OrmTestCase; use PDO; @@ -14,20 +14,20 @@ class ParameterTypeInfererTest extends OrmTestCase public function providerParameterTypeInferer() { $data = [ - [1, Type::INTEGER], + [1, Types::INTEGER], ["bar", PDO::PARAM_STR], ["1", PDO::PARAM_STR], - [new \DateTime, Type::DATETIME], - [new \DateInterval('P1D'), Type::DATEINTERVAL], + [new \DateTime, Types::DATETIME_MUTABLE], + [new \DateInterval('P1D'), Types::DATEINTERVAL], [[2], Connection::PARAM_INT_ARRAY], [["foo"], Connection::PARAM_STR_ARRAY], [["1","2"], Connection::PARAM_STR_ARRAY], [[], Connection::PARAM_STR_ARRAY], - [true, Type::BOOLEAN], + [true, Types::BOOLEAN], ]; if (PHP_VERSION_ID >= 50500) { - $data[] = [new \DateTimeImmutable(), Type::DATETIME]; + $data[] = [new \DateTimeImmutable(), Types::DATETIME_MUTABLE]; } return $data; diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index 2d2d5241229..6b1ceef1563 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -5,21 +5,19 @@ use DateTime; use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Collections\ArrayCollection; -use Doctrine\DBAL\Types\Type; +use Doctrine\DBAL\Types\Types; use Doctrine\ORM\Internal\Hydration\IterableResult; -use Doctrine\ORM\Query; use Doctrine\ORM\Query\Parameter; use Doctrine\ORM\Query\QueryException; use Doctrine\ORM\UnitOfWork; use Doctrine\Tests\Mocks\DriverConnectionMock; use Doctrine\Tests\Mocks\EntityManagerMock; -use Doctrine\Tests\Mocks\StatementArrayMock; +use Doctrine\Tests\Mocks\StatementMock; use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\Generic\DateTimeModel; use Doctrine\Tests\OrmTestCase; use Generator; -use ReflectionClass; class QueryTest extends OrmTestCase { @@ -298,7 +296,7 @@ public function testResultCacheCaching() $this->_em->getConfiguration()->setQueryCacheImpl(new ArrayCache()); /** @var DriverConnectionMock $driverConnectionMock */ $driverConnectionMock = $this->_em->getConnection()->getWrappedConnection(); - $stmt = new StatementArrayMock([ + $stmt = new StatementMock([ [ 'id_0' => 1, ] @@ -345,12 +343,12 @@ public function testResultCacheEviction() $driverConnectionMock = $this->_em->getConnection() ->getWrappedConnection(); - $driverConnectionMock->setStatementMock(new StatementArrayMock([['id_0' => 1]])); + $driverConnectionMock->setStatementMock(new StatementMock([['id_0' => 1]])); // Performs the query and sets up the initial cache self::assertCount(1, $query->getResult()); - $driverConnectionMock->setStatementMock(new StatementArrayMock([['id_0' => 1], ['id_0' => 2]])); + $driverConnectionMock->setStatementMock(new StatementMock([['id_0' => 1], ['id_0' => 2]])); // Retrieves cached data since expire flag is false and we have a cached result set self::assertCount(1, $query->getResult()); @@ -358,7 +356,7 @@ public function testResultCacheEviction() // Performs the query and caches the result set since expire flag is true self::assertCount(2, $query->expireResultCache(true)->getResult()); - $driverConnectionMock->setStatementMock(new StatementArrayMock([['id_0' => 1]])); + $driverConnectionMock->setStatementMock(new StatementMock([['id_0' => 1]])); // Retrieves cached data since expire flag is false and we have a cached result set self::assertCount(2, $query->expireResultCache(false)->getResult()); @@ -477,7 +475,7 @@ public function testValuesAreNotBeingResolvedForSpecifiedParameterTypes() : void $query = $this->_em->createQuery('SELECT d FROM ' . DateTimeModel::class . ' d WHERE d.datetime = :value'); - $query->setParameter('value', new DateTime(), Type::DATETIME); + $query->setParameter('value', new DateTime(), Types::DATETIME_MUTABLE); self::assertEmpty($query->getResult()); } diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 8286e29108c..ad02be9c9e3 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -5,9 +5,9 @@ use Doctrine\DBAL\LockMode; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Platforms\OraclePlatform; -use Doctrine\DBAL\Platforms\PostgreSqlPlatform; +use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Platforms\SqlitePlatform; -use Doctrine\DBAL\Platforms\SQLServerPlatform; +use Doctrine\DBAL\Platforms\SQLServer2012Platform; use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\ORM\Query as ORMQuery; use Doctrine\ORM\Query\AST\Functions\FunctionNode; @@ -642,7 +642,7 @@ public function testSupportsConcatFunctionForMysqlAndPostgresql() "SELECT CONCAT(c0_.id, c0_.name) AS sclr_0 FROM cms_users c0_ WHERE c0_.id = ?" ); - $connMock->setDatabasePlatform(new PostgreSqlPlatform()); + $connMock->setDatabasePlatform(new PostgreSQL94Platform()); $this->assertSqlGeneration( "SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CONCAT(u.name, 's') = ?1", "SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE c0_.name || 's' = ?" @@ -938,7 +938,7 @@ public function testBooleanLiteralInWhereOnSqlite() public function testBooleanLiteralInWhereOnPostgres() { $oldPlat = $this->_em->getConnection()->getDatabasePlatform(); - $this->_em->getConnection()->setDatabasePlatform(new PostgreSqlPlatform()); + $this->_em->getConnection()->setDatabasePlatform(new PostgreSQL94Platform()); $this->assertSqlGeneration( "SELECT b FROM Doctrine\Tests\Models\Generic\BooleanModel b WHERE b.booleanField = true", @@ -1078,7 +1078,7 @@ public function testPessimisticWriteLockQueryHint() */ public function testPessimisticReadLockQueryHintPostgreSql() { - $this->_em->getConnection()->setDatabasePlatform(new PostgreSqlPlatform()); + $this->_em->getConnection()->setDatabasePlatform(new PostgreSQL94Platform()); $this->assertSqlGeneration( "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 'gblanco'", @@ -2097,7 +2097,7 @@ public function testSupportsMoreThanTwoParametersInConcatFunction() "SELECT CONCAT(c0_.id, c0_.name, c0_.status) AS sclr_0 FROM cms_users c0_ WHERE c0_.id = ?" ); - $connMock->setDatabasePlatform(new PostgreSqlPlatform()); + $connMock->setDatabasePlatform(new PostgreSQL94Platform()); $this->assertSqlGeneration( "SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CONCAT(u.name, u.status, 's') = ?1", "SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE c0_.name || c0_.status || 's' = ?" @@ -2107,7 +2107,7 @@ public function testSupportsMoreThanTwoParametersInConcatFunction() "SELECT c0_.id || c0_.name || c0_.status AS sclr_0 FROM cms_users c0_ WHERE c0_.id = ?" ); - $connMock->setDatabasePlatform(new SQLServerPlatform()); + $connMock->setDatabasePlatform(new SQLServer2012Platform()); $this->assertSqlGeneration( "SELECT u.id FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE CONCAT(u.name, u.status, 's') = ?1", "SELECT c0_.id AS id_0 FROM cms_users c0_ WHERE (c0_.name + c0_.status + 's') = ?" diff --git a/tests/Doctrine/Tests/ORM/Tools/Console/ConsoleRunnerTest.php b/tests/Doctrine/Tests/ORM/Tools/Console/ConsoleRunnerTest.php index 62225a87e83..c862daa1961 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Console/ConsoleRunnerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Console/ConsoleRunnerTest.php @@ -23,9 +23,11 @@ public function testCreateApplicationShouldReturnAnApplicationWithTheCorrectComm self::assertSame($helperSet, $app->getHelperSet()); self::assertSame(Versions::getVersion('doctrine/orm'), $app->getVersion()); - self::assertTrue($app->has('dbal:import')); - self::assertTrue($app->has('dbal:reserved-words')); - self::assertTrue($app->has('dbal:run-sql')); + if (class_exists(\Doctrine\DBAL\Tools\Console\Command\ImportCommand::class)) { + self::assertTrue($app->has('dbal:import')); + self::assertTrue($app->has('dbal:reserved-words')); + self::assertTrue($app->has('dbal:run-sql')); + } self::assertTrue($app->has('orm:clear-cache:region:collection')); self::assertTrue($app->has('orm:clear-cache:region:entity')); self::assertTrue($app->has('orm:clear-cache:region:query')); diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php index 39ee1360dc9..3ca058ab201 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php @@ -4,7 +4,7 @@ use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Platforms\OraclePlatform; -use Doctrine\DBAL\Platforms\PostgreSqlPlatform; +use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\ORM\Query; use Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker; @@ -26,7 +26,7 @@ public function testLimitSubquery() : void public function testLimitSubqueryWithSortPg() : void { $odp = $this->entityManager->getConnection()->getDatabasePlatform(); - $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform); + $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSQL94Platform()); $query = $this->entityManager->createQuery( 'SELECT p, c, a FROM Doctrine\Tests\ORM\Tools\Pagination\MyBlogPost p JOIN p.category c JOIN p.author a ORDER BY p.title'); @@ -43,7 +43,7 @@ public function testLimitSubqueryWithSortPg() : void public function testLimitSubqueryWithScalarSortPg() : void { $odp = $this->entityManager->getConnection()->getDatabasePlatform(); - $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform); + $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSQL94Platform()); $query = $this->entityManager->createQuery( 'SELECT u, g, COUNT(g.id) AS g_quantity FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g ORDER BY g_quantity' @@ -62,7 +62,7 @@ public function testLimitSubqueryWithScalarSortPg() : void public function testLimitSubqueryWithMixedSortPg() : void { $odp = $this->entityManager->getConnection()->getDatabasePlatform(); - $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform); + $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSQL94Platform()); $query = $this->entityManager->createQuery( 'SELECT u, g, COUNT(g.id) AS g_quantity FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g ORDER BY g_quantity, u.id DESC' @@ -81,7 +81,7 @@ public function testLimitSubqueryWithMixedSortPg() : void public function testLimitSubqueryWithHiddenScalarSortPg() : void { $odp = $this->entityManager->getConnection()->getDatabasePlatform(); - $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform); + $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSQL94Platform()); $query = $this->entityManager->createQuery( 'SELECT u, g, COUNT(g.id) AS hidden g_quantity FROM Doctrine\Tests\ORM\Tools\Pagination\User u JOIN u.groups g ORDER BY g_quantity, u.id DESC' @@ -100,7 +100,7 @@ public function testLimitSubqueryWithHiddenScalarSortPg() : void public function testLimitSubqueryPg() : void { $odp = $this->entityManager->getConnection()->getDatabasePlatform(); - $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform); + $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSQL94Platform()); $this->testLimitSubquery(); @@ -337,7 +337,7 @@ public function testLimitSubqueryWithOrderByAndSubSelectInWhereClauseMySql() : v public function testLimitSubqueryWithOrderByAndSubSelectInWhereClausePgSql() : void { - $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform()); + $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSQL94Platform()); $query = $this->entityManager->createQuery( 'SELECT b FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost b WHERE ((SELECT COUNT(simple.id) FROM Doctrine\Tests\ORM\Tools\Pagination\BlogPost simple) = 1) @@ -400,7 +400,7 @@ public function testLimitSubqueryOrderBySubSelectOrderByExpression() : void */ public function testLimitSubqueryOrderBySubSelectOrderByExpressionPg() : void { - $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSqlPlatform()); + $this->entityManager->getConnection()->setDatabasePlatform(new PostgreSQL94Platform()); $query = $this->entityManager->createQuery( 'SELECT a,