From 843966ac50d216b7c55e9f5fde7441fbf25dad57 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Fri, 6 Nov 2015 15:23:16 +0000 Subject: [PATCH] General fixes across CS, type resolving, test fixes, etc --- .travis.yml | 2 - .../ORM/Cache/DefaultEntityHydrator.php | 8 +- .../Internal/Hydration/AbstractHydrator.php | 11 +- .../ORM/Mapping/ClassMetadataInfo.php | 153 ++++++++++++------ .../ORM/Mapping/Driver/AnnotationDriver.php | 27 +++- .../ORM/Mapping/Driver/YamlDriver.php | 1 + lib/Doctrine/ORM/PersistentCollection.php | 4 +- .../Collection/OneToManyPersister.php | 3 +- .../AbstractEntityInheritancePersister.php | 17 +- .../Entity/BasicEntityPersister.php | 85 +++++----- .../Entity/JoinedSubclassPersister.php | 7 +- .../Entity/SingleTablePersister.php | 17 +- .../Query/Exec/MultiTableDeleteExecutor.php | 4 +- .../Query/Exec/MultiTableUpdateExecutor.php | 8 +- lib/Doctrine/ORM/Query/ResultSetMapping.php | 2 + .../ORM/Query/ResultSetMappingBuilder.php | 62 ++++--- lib/Doctrine/ORM/Query/SqlWalker.php | 76 ++++----- .../Tools/Pagination/LimitSubqueryWalker.php | 4 +- .../Models/DDC869/DDC869ChequePayment.php | 2 +- .../Models/DDC869/DDC869CreditCardPayment.php | 2 +- .../Tests/Models/DDC869/DDC869Payment.php | 2 +- .../Tests/Models/DDC964/DDC964Admin.php | 2 +- .../Tests/Models/DDC964/DDC964Guest.php | 2 +- .../Tests/Models/DDC964/DDC964User.php | 2 +- .../Models/Generic/NonAlphaColumnsEntity.php | 30 ++++ .../Models/Global/GlobalNamespaceModel.php | 21 +-- .../Tests/ORM/Cache/DefaultQueryCacheTest.php | 2 +- .../ORM/Functional/DetachedEntityTest.php | 7 + .../ORM/Functional/Locking/OptimisticTest.php | 32 +++- .../Tests/ORM/Functional/NativeQueryTest.php | 5 +- .../Tests/ORM/Functional/ResultCacheTest.php | 29 ++-- .../Tests/ORM/Functional/SQLFilterTest.php | 3 - .../ORM/Functional/Ticket/DDC1050Test.php | 2 + .../ORM/Functional/Ticket/DDC1655Test.php | 2 +- .../ORM/Functional/Ticket/DDC1695Test.php | 38 ++--- .../ORM/Functional/Ticket/DDC3634Test.php | 2 +- .../Tests/ORM/Hydration/ArrayHydratorTest.php | 48 ++++-- .../ORM/Hydration/ObjectHydratorTest.php | 58 ++++--- .../ORM/Hydration/ResultSetMappingTest.php | 38 +++-- .../ORM/Hydration/ScalarHydratorTest.php | 12 +- .../Hydration/SimpleObjectHydratorTest.php | 4 +- .../ORM/Mapping/AbstractMappingDriverTest.php | 4 +- .../ORM/Mapping/ClassMetadataFactoryTest.php | 2 +- .../Doctrine.Tests.Models.CMS.CmsAddress.php | 2 - .../php/Doctrine.Tests.Models.CMS.CmsUser.php | 2 - ...e.Tests.Models.Company.CompanyContract.php | 2 +- ...ine.Tests.Models.Company.CompanyPerson.php | 2 - .../Tests/ORM/PersistentCollectionTest.php | 25 +++ .../BasicEntityPersisterTypeValueSqlTest.php | 8 +- .../ORM/Query/SelectSqlGenerationTest.php | 12 +- .../Tests/ORM/Tools/EntityGeneratorTest.php | 15 +- .../AbstractClassMetadataExporterTest.php | 39 +++-- .../Doctrine/Tests/OrmFunctionalTestCase.php | 8 +- tests/Doctrine/Tests/OrmTestCase.php | 47 +++--- 54 files changed, 609 insertions(+), 395 deletions(-) create mode 100644 tests/Doctrine/Tests/Models/Generic/NonAlphaColumnsEntity.php diff --git a/.travis.yml b/.travis.yml index efe678ba3..d194279ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -29,7 +29,5 @@ matrix: exclude: - php: hhvm env: DB=pgsql # driver for PostgreSQL currently unsupported by HHVM, requires 3rd party dependency - allow_failures: - - php: 7.0 sudo: false diff --git a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php index 200af9c0d..ad54dc245 100644 --- a/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php +++ b/lib/Doctrine/ORM/Cache/DefaultEntityHydrator.php @@ -76,7 +76,6 @@ class DefaultEntityHydrator implements EntityHydrator $data = array_merge($data, $key->identifier); // why update has no identifier values ? foreach ($metadata->associationMappings as $name => $assoc) { - if ( ! isset($data[$name])) { continue; } @@ -92,18 +91,16 @@ class DefaultEntityHydrator implements EntityHydrator unset($data[$name]); foreach ($associationIds as $fieldName => $fieldValue) { - if (isset($targetClassMetadata->associationMappings[$fieldName])){ $targetAssoc = $targetClassMetadata->associationMappings[$fieldName]; foreach($assoc['targetToSourceKeyColumns'] as $referencedColumn => $localColumn) { - if (isset($targetAssoc['sourceToTargetKeyColumns'][$referencedColumn])) { $data[$localColumn] = $fieldValue; } } - }else{ - $data[$assoc['targetToSourceKeyColumns'][$targetClassMetadata->columnNames[$fieldName]]] = $fieldValue; + } else { + $data[$assoc['targetToSourceKeyColumns'][$targetClassMetadata->fieldMappings[$fieldName]['columnName']]] = $fieldValue; } } @@ -126,7 +123,6 @@ class DefaultEntityHydrator implements EntityHydrator // @TODO - fix it ! // handle UnitOfWork#createEntity hash generation if ( ! is_array($targetId)) { - $data[reset($assoc['joinColumnFieldNames'])] = $targetId; $targetEntity = $this->em->getClassMetadata($assoc['targetEntity']); diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index af232d1ff..ff142fc35 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -120,6 +120,7 @@ abstract class AbstractHydrator $this->_hints = $hints; $evm = $this->_em->getEventManager(); + $evm->addEventListener(array(Events::onClear), $this); $this->prepare(); @@ -398,13 +399,15 @@ abstract class AbstractHydrator case (isset($this->_rsm->metaMappings[$key])): // Meta column (has meaning in relational schema only, i.e. foreign keys or discriminator columns). - $fieldName = $this->_rsm->metaMappings[$key]; - $dqlAlias = $this->_rsm->columnOwnerMap[$key]; - $classMetadata = $this->getClassMetadata($this->_rsm->aliasMap[$dqlAlias]); - $type = isset($this->_rsm->typeMappings[$key]) + $fieldName = $this->_rsm->metaMappings[$key]; + $dqlAlias = $this->_rsm->columnOwnerMap[$key]; + $type = isset($this->_rsm->typeMappings[$key]) ? Type::getType($this->_rsm->typeMappings[$key]) : null; + // Cache metadata fetch + $this->getClassMetadata($this->_rsm->aliasMap[$dqlAlias]); + return $this->_cache[$key] = array( 'isIdentifier' => isset($this->_rsm->isIdentifierColumn[$dqlAlias][$key]), 'isMetaColumn' => true, diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 73f7dc647..501ffec68 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -399,7 +399,6 @@ class ClassMetadataInfo implements ClassMetadata /** * READ-ONLY: An array of field names. Used to look up field names from column names. * Keys are column names and values are field names. - * This is the reverse lookup map of $_columnNames. * * @var array */ @@ -412,7 +411,7 @@ class ClassMetadataInfo implements ClassMetadata * * @var array * - * @todo We could get rid of this array by just using $fieldMappings[$fieldName]['columnName']. + * @deprecated 3.0 Remove this. */ public $columnNames = array(); @@ -742,7 +741,7 @@ class ClassMetadataInfo implements ClassMetadata * Populates the entity identifier of an entity. * * @param object $entity - * @param mixed $id + * @param array $id * * @return void * @@ -812,7 +811,7 @@ class ClassMetadataInfo implements ClassMetadata // This metadata is always serialized/cached. $serialized = array( 'associationMappings', - 'columnNames', //TODO: Not really needed. Can use fieldMappings[$fieldName]['columnName'] + 'columnNames', //TODO: 3.0 Remove this. Can use fieldMappings[$fieldName]['columnName'] 'fieldMappings', 'fieldNames', 'embeddedClasses', @@ -1177,9 +1176,11 @@ class ClassMetadataInfo implements ClassMetadata public function isUniqueField($fieldName) { $mapping = $this->getFieldMapping($fieldName); + if ($mapping !== false) { return isset($mapping['unique']) && $mapping['unique'] == true; } + return false; } @@ -1193,9 +1194,11 @@ class ClassMetadataInfo implements ClassMetadata public function isNullable($fieldName) { $mapping = $this->getFieldMapping($fieldName); + if ($mapping !== false) { return isset($mapping['nullable']) && $mapping['nullable'] == true; } + return false; } @@ -1210,8 +1213,9 @@ class ClassMetadataInfo implements ClassMetadata */ public function getColumnName($fieldName) { - return isset($this->columnNames[$fieldName]) ? - $this->columnNames[$fieldName] : $fieldName; + return isset($this->columnNames[$fieldName]) + ? $this->columnNames[$fieldName] + : $fieldName; } /** @@ -1229,6 +1233,7 @@ class ClassMetadataInfo implements ClassMetadata if ( ! isset($this->fieldMappings[$fieldName])) { throw MappingException::mappingNotFound($this->name, $fieldName); } + return $this->fieldMappings[$fieldName]; } @@ -1249,6 +1254,7 @@ class ClassMetadataInfo implements ClassMetadata if ( ! isset($this->associationMappings[$fieldName])) { throw MappingException::mappingNotFound($this->name, $fieldName); } + return $this->associationMappings[$fieldName]; } @@ -1272,8 +1278,9 @@ class ClassMetadataInfo implements ClassMetadata */ public function getFieldName($columnName) { - return isset($this->fieldNames[$columnName]) ? - $this->fieldNames[$columnName] : $columnName; + return isset($this->fieldNames[$columnName]) + ? $this->fieldNames[$columnName] + : $columnName; } /** @@ -1292,6 +1299,7 @@ class ClassMetadataInfo implements ClassMetadata if ( ! isset($this->namedQueries[$queryName])) { throw MappingException::queryNotFound($this->name, $queryName); } + return $this->namedQueries[$queryName]['dql']; } @@ -1380,6 +1388,7 @@ class ClassMetadataInfo implements ClassMetadata if ( ! isset($mapping['fieldName']) || strlen($mapping['fieldName']) == 0) { throw MappingException::missingFieldName($this->name); } + if ( ! isset($mapping['type'])) { // Default to string $mapping['type'] = 'string'; @@ -1396,6 +1405,7 @@ class ClassMetadataInfo implements ClassMetadata } $this->columnNames[$mapping['fieldName']] = $mapping['columnName']; + if (isset($this->fieldNames[$mapping['columnName']]) || ($this->discriminatorColumn != null && $this->discriminatorColumn['name'] == $mapping['columnName'])) { throw MappingException::duplicateColumnName($this->name, $mapping['columnName']); } @@ -1411,6 +1421,7 @@ class ClassMetadataInfo implements ClassMetadata if ( ! in_array($mapping['fieldName'], $this->identifier)) { $this->identifier[] = $mapping['fieldName']; } + // Check for composite key if ( ! $this->isIdentifierComposite && count($this->identifier) > 1) { $this->isIdentifierComposite = true; @@ -1441,9 +1452,11 @@ class ClassMetadataInfo implements ClassMetadata if ( ! isset($mapping['mappedBy'])) { $mapping['mappedBy'] = null; } + if ( ! isset($mapping['inversedBy'])) { $mapping['inversedBy'] = null; } + $mapping['isOwningSide'] = true; // assume owning side until we hit mappedBy // unset optional indexBy attribute if its empty @@ -1460,10 +1473,7 @@ class ClassMetadataInfo implements ClassMetadata $mapping['targetEntity'] = ltrim($mapping['targetEntity'], '\\'); } - if ( ($mapping['type'] & self::MANY_TO_ONE) > 0 && - isset($mapping['orphanRemoval']) && - $mapping['orphanRemoval'] == true) { - + if (($mapping['type'] & self::MANY_TO_ONE) > 0 && isset($mapping['orphanRemoval']) && $mapping['orphanRemoval'] == true) { throw MappingException::illegalOrphanRemoval($this->name, $mapping['fieldName']); } @@ -1483,6 +1493,7 @@ class ClassMetadataInfo implements ClassMetadata $this->identifier[] = $mapping['fieldName']; $this->containsForeignIdentifier = true; } + // Check for composite key if ( ! $this->isIdentifierComposite && count($this->identifier) > 1) { $this->isIdentifierComposite = true; @@ -1498,6 +1509,7 @@ class ClassMetadataInfo implements ClassMetadata if ( ! isset($mapping['fieldName']) || strlen($mapping['fieldName']) == 0) { throw MappingException::missingFieldName($this->name); } + if ( ! isset($mapping['targetEntity'])) { throw MappingException::missingTargetEntity($mapping['fieldName']); } @@ -1569,13 +1581,16 @@ class ClassMetadataInfo implements ClassMetadata if ($mapping['isOwningSide']) { if ( ! isset($mapping['joinColumns']) || ! $mapping['joinColumns']) { // Apply default join column - $mapping['joinColumns'] = array(array( - 'name' => $this->namingStrategy->joinColumnName($mapping['fieldName'], $this->name), - 'referencedColumnName' => $this->namingStrategy->referenceColumnName() - )); + $mapping['joinColumns'] = array( + array( + 'name' => $this->namingStrategy->joinColumnName($mapping['fieldName'], $this->name), + 'referencedColumnName' => $this->namingStrategy->referenceColumnName() + ) + ); } $uniqueConstraintColumns = array(); + foreach ($mapping['joinColumns'] as &$joinColumn) { if ($mapping['type'] === self::ONE_TO_ONE && ! $this->isInheritanceTypeSingleTable()) { if (count($mapping['joinColumns']) == 1) { @@ -1607,14 +1622,16 @@ class ClassMetadataInfo implements ClassMetadata $mapping['sourceToTargetKeyColumns'][$joinColumn['name']] = $joinColumn['referencedColumnName']; $mapping['joinColumnFieldNames'][$joinColumn['name']] = isset($joinColumn['fieldName']) - ? $joinColumn['fieldName'] : $joinColumn['name']; + ? $joinColumn['fieldName'] + : $joinColumn['name']; } if ($uniqueConstraintColumns) { if ( ! $this->table) { throw new RuntimeException("ClassMetadataInfo::setTable() has to be called before defining a one to one relationship."); } - $this->table['uniqueConstraints'][$mapping['fieldName']."_uniq"] = array( + + $this->table['uniqueConstraints'][$mapping['fieldName'] . "_uniq"] = array( 'columns' => $uniqueConstraintColumns ); } @@ -1679,6 +1696,7 @@ class ClassMetadataInfo implements ClassMetadata protected function _validateAndCompleteManyToManyMapping(array $mapping) { $mapping = $this->_validateAndCompleteAssociationMapping($mapping); + if ($mapping['isOwningSide']) { // owning side MUST have a join table if ( ! isset($mapping['joinTable']['name'])) { @@ -1689,16 +1707,23 @@ class ClassMetadataInfo implements ClassMetadata && (! (isset($mapping['joinTable']['joinColumns']) || isset($mapping['joinTable']['inverseJoinColumns']))); if ( ! isset($mapping['joinTable']['joinColumns'])) { - $mapping['joinTable']['joinColumns'] = array(array( + $mapping['joinTable']['joinColumns'] = array( + array( 'name' => $this->namingStrategy->joinKeyColumnName($mapping['sourceEntity'], $selfReferencingEntityWithoutJoinColumns ? 'source' : null), 'referencedColumnName' => $this->namingStrategy->referenceColumnName(), - 'onDelete' => 'CASCADE')); + 'onDelete' => 'CASCADE' + ) + ); } + if ( ! isset($mapping['joinTable']['inverseJoinColumns'])) { - $mapping['joinTable']['inverseJoinColumns'] = array(array( + $mapping['joinTable']['inverseJoinColumns'] = array( + array( 'name' => $this->namingStrategy->joinKeyColumnName($mapping['targetEntity'], $selfReferencingEntityWithoutJoinColumns ? 'target' : null), 'referencedColumnName' => $this->namingStrategy->referenceColumnName(), - 'onDelete' => 'CASCADE')); + 'onDelete' => 'CASCADE' + ) + ); } $mapping['joinTableColumns'] = array(); @@ -1790,6 +1815,7 @@ class ClassMetadataInfo implements ClassMetadata if ($this->isIdentifierComposite) { throw MappingException::singleIdNotAllowedOnCompositePrimaryKey($this->name); } + return $this->identifier[0]; } @@ -1848,13 +1874,15 @@ class ClassMetadataInfo implements ClassMetadata { if ($fieldNames === null) { return array_keys($this->fieldNames); - } else { - $columnNames = array(); - foreach ($fieldNames as $fieldName) { - $columnNames[] = $this->getColumnName($fieldName); - } - return $columnNames; } + + $columnNames = array(); + + foreach ($fieldNames as $fieldName) { + $columnNames[] = $this->getColumnName($fieldName); + } + + return $columnNames; } /** @@ -2003,11 +2031,14 @@ class ClassMetadataInfo implements ClassMetadata * @param string $fieldName * * @return \Doctrine\DBAL\Types\Type|string|null + * + * @todo 3.0 Remove this. PersisterHelper should fix it somehow */ public function getTypeOfField($fieldName) { - return isset($this->fieldMappings[$fieldName]) ? - $this->fieldMappings[$fieldName]['type'] : null; + return isset($this->fieldMappings[$fieldName]) + ? $this->fieldMappings[$fieldName]['type'] + : null; } /** @@ -2017,8 +2048,8 @@ class ClassMetadataInfo implements ClassMetadata * * @return \Doctrine\DBAL\Types\Type|string|null * - * @deprecated this method is bogous and unreliable, since it cannot resolve the type of a column that is - * derived by a referenced field on a different entity. + * @deprecated 3.0 remove this. this method is bogous and unreliable, since it cannot resolve the type of a column + * that is derived by a referenced field on a different entity. */ public function getTypeOfColumn($columnName) { @@ -2082,6 +2113,7 @@ class ClassMetadataInfo implements ClassMetadata public function setParentClasses(array $classNames) { $this->parentClasses = $classNames; + if (count($classNames) > 0) { $this->rootEntityName = array_pop($classNames); } @@ -2101,6 +2133,7 @@ class ClassMetadataInfo implements ClassMetadata if ( ! $this->_isInheritanceType($type)) { throw MappingException::invalidInheritanceType($this->name, $type); } + $this->inheritanceType = $type; } @@ -2195,6 +2228,7 @@ class ClassMetadataInfo implements ClassMetadata unset($this->fieldMappings[$fieldName]); unset($this->fieldNames[$mapping['columnName']]); unset($this->columnNames[$mapping['fieldName']]); + $this->_validateAndCompleteFieldMapping($overrideMapping); $this->fieldMappings[$fieldName] = $overrideMapping; @@ -2394,10 +2428,11 @@ class ClassMetadataInfo implements ClassMetadata $name = $queryMapping['name']; $query = $queryMapping['query']; $dql = str_replace('__CLASS__', $this->name, $query); + $this->namedQueries[$name] = array( 'name' => $name, 'query' => $query, - 'dql' => $dql + 'dql' => $dql, ); } @@ -2430,8 +2465,8 @@ class ClassMetadataInfo implements ClassMetadata } $queryMapping['isSelfClass'] = false; - if (isset($queryMapping['resultClass'])) { + if (isset($queryMapping['resultClass'])) { if ($queryMapping['resultClass'] === '__CLASS__') { $queryMapping['isSelfClass'] = true; @@ -2516,7 +2551,9 @@ class ClassMetadataInfo implements ClassMetadata public function mapOneToOne(array $mapping) { $mapping['type'] = self::ONE_TO_ONE; + $mapping = $this->_validateAndCompleteOneToOneMapping($mapping); + $this->_storeAssociationMapping($mapping); } @@ -2530,7 +2567,9 @@ class ClassMetadataInfo implements ClassMetadata public function mapOneToMany(array $mapping) { $mapping['type'] = self::ONE_TO_MANY; + $mapping = $this->_validateAndCompleteOneToManyMapping($mapping); + $this->_storeAssociationMapping($mapping); } @@ -2544,8 +2583,10 @@ class ClassMetadataInfo implements ClassMetadata public function mapManyToOne(array $mapping) { $mapping['type'] = self::MANY_TO_ONE; + // A many-to-one mapping is essentially a one-one backreference $mapping = $this->_validateAndCompleteOneToOneMapping($mapping); + $this->_storeAssociationMapping($mapping); } @@ -2559,7 +2600,9 @@ class ClassMetadataInfo implements ClassMetadata public function mapManyToMany(array $mapping) { $mapping['type'] = self::MANY_TO_MANY; + $mapping = $this->_validateAndCompleteManyToManyMapping($mapping); + $this->_storeAssociationMapping($mapping); } @@ -2677,9 +2720,10 @@ class ClassMetadataInfo implements ClassMetadata public function addEntityListener($eventName, $class, $method) { $class = $this->fullyQualifiedClassName($class); + $listener = array( 'class' => $class, - 'method' => $method + 'method' => $method, ); if ( ! class_exists($class)) { @@ -2764,6 +2808,7 @@ class ClassMetadataInfo implements ClassMetadata { $className = $this->fullyQualifiedClassName($className); $className = ltrim($className, '\\'); + $this->discriminatorMap[$name] = $className; if ($this->name === $className) { @@ -2830,8 +2875,8 @@ class ClassMetadataInfo implements ClassMetadata */ public function isSingleValuedAssociation($fieldName) { - return isset($this->associationMappings[$fieldName]) && - ($this->associationMappings[$fieldName]['type'] & self::TO_ONE); + return isset($this->associationMappings[$fieldName]) + && ($this->associationMappings[$fieldName]['type'] & self::TO_ONE); } /** @@ -2839,8 +2884,8 @@ class ClassMetadataInfo implements ClassMetadata */ public function isCollectionValuedAssociation($fieldName) { - return isset($this->associationMappings[$fieldName]) && - ! ($this->associationMappings[$fieldName]['type'] & self::TO_ONE); + return isset($this->associationMappings[$fieldName]) + && ! ($this->associationMappings[$fieldName]['type'] & self::TO_ONE); } /** @@ -2852,11 +2897,9 @@ class ClassMetadataInfo implements ClassMetadata */ public function isAssociationWithSingleJoinColumn($fieldName) { - return ( - isset($this->associationMappings[$fieldName]) && - isset($this->associationMappings[$fieldName]['joinColumns'][0]) && - !isset($this->associationMappings[$fieldName]['joinColumns'][1]) - ); + return isset($this->associationMappings[$fieldName]) + && isset($this->associationMappings[$fieldName]['joinColumns'][0]) + && ! isset($this->associationMappings[$fieldName]['joinColumns'][1]); } /** @@ -2873,6 +2916,7 @@ class ClassMetadataInfo implements ClassMetadata if ( ! $this->isAssociationWithSingleJoinColumn($fieldName)) { throw MappingException::noSingleAssociationJoinColumnFound($this->name, $fieldName); } + return $this->associationMappings[$fieldName]['joinColumns'][0]['name']; } @@ -2890,6 +2934,7 @@ class ClassMetadataInfo implements ClassMetadata if ( ! $this->isAssociationWithSingleJoinColumn($fieldName)) { throw MappingException::noSingleAssociationJoinColumnFound($this->name, $fieldName); } + return $this->associationMappings[$fieldName]['joinColumns'][0]['referencedColumnName']; } @@ -2961,6 +3006,8 @@ class ClassMetadataInfo implements ClassMetadata * @param array $definition * * @return void + * + * @throws MappingException */ public function setSequenceGeneratorDefinition(array $definition) { @@ -3142,7 +3189,9 @@ class ClassMetadataInfo implements ClassMetadata */ public function getQuotedTableName($platform) { - return isset($this->table['quoted']) ? $platform->quoteIdentifier($this->table['name']) : $this->table['name']; + return isset($this->table['quoted']) + ? $platform->quoteIdentifier($this->table['name']) + : $this->table['name']; } /** @@ -3157,7 +3206,9 @@ class ClassMetadataInfo implements ClassMetadata */ public function getQuotedJoinTableName(array $assoc, $platform) { - return isset($assoc['joinTable']['quoted']) ? $platform->quoteIdentifier($assoc['joinTable']['name']) : $assoc['joinTable']['name']; + return isset($assoc['joinTable']['quoted']) + ? $platform->quoteIdentifier($assoc['joinTable']['name']) + : $assoc['joinTable']['name']; } /** @@ -3165,7 +3216,8 @@ class ClassMetadataInfo implements ClassMetadata */ public function isAssociationInverseSide($fieldName) { - return isset($this->associationMappings[$fieldName]) && ! $this->associationMappings[$fieldName]['isOwningSide']; + return isset($this->associationMappings[$fieldName]) + && ! $this->associationMappings[$fieldName]['isOwningSide']; } /** @@ -3184,11 +3236,13 @@ class ClassMetadataInfo implements ClassMetadata public function getAssociationsByTargetClass($targetClass) { $relations = array(); + foreach ($this->associationMappings as $mapping) { if ($mapping['targetEntity'] == $targetClass) { $relations[$mapping['fieldName']] = $mapping; } } + return $relations; } @@ -3303,9 +3357,8 @@ class ClassMetadataInfo implements ClassMetadata public function getSequenceName(AbstractPlatform $platform) { $sequencePrefix = $this->getSequencePrefix($platform); - - $columnName = $this->getSingleIdentifierColumnName(); - $sequenceName = $sequencePrefix . '_' . $columnName . '_seq'; + $columnName = $this->getSingleIdentifierColumnName(); + $sequenceName = $sequencePrefix . '_' . $columnName . '_seq'; return $sequenceName; } diff --git a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php index a4e88dc51..92b4b4722 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php @@ -54,6 +54,7 @@ class AnnotationDriver extends AbstractAnnotationDriver { /* @var $metadata \Doctrine\ORM\Mapping\ClassMetadataInfo */ $class = $metadata->getReflectionClass(); + if ( ! $class) { // this happens when running annotation driver in combination with // static reflection services. This is not the nicest fix @@ -78,11 +79,13 @@ class AnnotationDriver extends AbstractAnnotationDriver if ($entityAnnot->repositoryClass !== null) { $metadata->setCustomRepositoryClass($entityAnnot->repositoryClass); } + if ($entityAnnot->readOnly) { $metadata->markReadOnly(); } } else if (isset($classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass'])) { $mappedSuperclassAnnot = $classAnnotations['Doctrine\ORM\Mapping\MappedSuperclass']; + $metadata->setCustomRepositoryClass($mappedSuperclassAnnot->repositoryClass); $metadata->isMappedSuperclass = true; } else if (isset($classAnnotations['Doctrine\ORM\Mapping\Embeddable'])) { @@ -227,17 +230,21 @@ class AnnotationDriver extends AbstractAnnotationDriver // Evaluate InheritanceType annotation if (isset($classAnnotations['Doctrine\ORM\Mapping\InheritanceType'])) { $inheritanceTypeAnnot = $classAnnotations['Doctrine\ORM\Mapping\InheritanceType']; - $metadata->setInheritanceType(constant('Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value)); + + $metadata->setInheritanceType( + constant('Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceTypeAnnot->value) + ); if ($metadata->inheritanceType != \Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_NONE) { // Evaluate DiscriminatorColumn annotation if (isset($classAnnotations['Doctrine\ORM\Mapping\DiscriminatorColumn'])) { $discrColumnAnnot = $classAnnotations['Doctrine\ORM\Mapping\DiscriminatorColumn']; + $metadata->setDiscriminatorColumn(array( - 'name' => $discrColumnAnnot->name, - 'type' => $discrColumnAnnot->type, - 'length' => $discrColumnAnnot->length, - 'columnDefinition' => $discrColumnAnnot->columnDefinition + 'name' => $discrColumnAnnot->name, + 'type' => $discrColumnAnnot->type, + 'length' => $discrColumnAnnot->length, + 'columnDefinition' => $discrColumnAnnot->columnDefinition, )); } else { $metadata->setDiscriminatorColumn(array('name' => 'dtype', 'type' => 'string', 'length' => 255)); @@ -273,6 +280,7 @@ class AnnotationDriver extends AbstractAnnotationDriver $mapping = array(); $mapping['fieldName'] = $property->getName(); + // Evaluate @Cache annotation if (($cacheAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Cache')) !== null) { $mapping['cache'] = $metadata->getAssociationCacheDefaults($mapping['fieldName'], array( @@ -400,6 +408,7 @@ class AnnotationDriver extends AbstractAnnotationDriver } else if ($embeddedAnnot = $this->reader->getPropertyAnnotation($property, 'Doctrine\ORM\Mapping\Embedded')) { $mapping['class'] = $embeddedAnnot->class; $mapping['columnPrefix'] = $embeddedAnnot->columnPrefix; + $metadata->mapEmbedded($mapping); } } @@ -415,9 +424,11 @@ class AnnotationDriver extends AbstractAnnotationDriver // Check for JoinColumn/JoinColumns annotations if ($associationOverride->joinColumns) { $joinColumns = array(); + foreach ($associationOverride->joinColumns as $joinColumn) { $joinColumns[] = $this->joinColumnToArray($joinColumn); } + $override['joinColumns'] = $joinColumns; } @@ -452,8 +463,10 @@ class AnnotationDriver extends AbstractAnnotationDriver // Evaluate AttributeOverrides annotation if (isset($classAnnotations['Doctrine\ORM\Mapping\AttributeOverrides'])) { $attributeOverridesAnnot = $classAnnotations['Doctrine\ORM\Mapping\AttributeOverrides']; + foreach ($attributeOverridesAnnot->value as $attributeOverrideAnnot) { $attributeOverride = $this->columnToArray($attributeOverrideAnnot->name, $attributeOverrideAnnot->column); + $metadata->setAttributeOverride($attributeOverrideAnnot->name, $attributeOverride); } } @@ -471,6 +484,7 @@ class AnnotationDriver extends AbstractAnnotationDriver $hasMapping = false; $listenerClass = new \ReflectionClass($listenerClassName); + /* @var $method \ReflectionMethod */ foreach ($listenerClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { // find method callbacks. @@ -481,6 +495,7 @@ class AnnotationDriver extends AbstractAnnotationDriver $metadata->addEntityListener($value[1], $listenerClassName, $value[0]); } } + // Evaluate the listener using naming convention. if ( ! $hasMapping ) { EntityListenerBuilder::bindEntityListener($metadata, $listenerClassName); @@ -492,9 +507,7 @@ class AnnotationDriver extends AbstractAnnotationDriver if (isset($classAnnotations['Doctrine\ORM\Mapping\HasLifecycleCallbacks'])) { /* @var $method \ReflectionMethod */ foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) { - foreach ($this->getMethodCallbacks($method) as $value) { - $metadata->addLifecycleCallback($value[0], $value[1]); } } diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 73fda462d..e4b1f050a 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -715,6 +715,7 @@ class YamlDriver extends FileDriver if (isset($column['type'])) { $params = explode('(', $column['type']); + $column['type'] = $params[0]; $mapping['type'] = $column['type']; diff --git a/lib/Doctrine/ORM/PersistentCollection.php b/lib/Doctrine/ORM/PersistentCollection.php index 9c0439f59..8dd5c74b1 100644 --- a/lib/Doctrine/ORM/PersistentCollection.php +++ b/lib/Doctrine/ORM/PersistentCollection.php @@ -471,7 +471,7 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec $this->changed(); - if ($this->em) { + if (is_object($value) && $this->em) { $this->em->getUnitOfWork()->cancelOrphanRemoval($value); } } @@ -485,7 +485,7 @@ final class PersistentCollection extends AbstractLazyCollection implements Selec $this->changed(); - if ($this->em) { + if (is_object($value) && $this->em) { $this->em->getUnitOfWork()->cancelOrphanRemoval($value); } diff --git a/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php index 86b364df8..d4213f15d 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php @@ -23,6 +23,7 @@ use Doctrine\Common\Collections\Criteria; use Doctrine\Common\Proxy\Proxy; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\PersistentCollection; +use Doctrine\ORM\Utility\PersisterHelper; /** * Persister for one-to-many collections. @@ -251,7 +252,7 @@ class OneToManyPersister extends AbstractCollectionPersister foreach ($idColumnNames as $idColumnName) { $columnDefinitions[$idColumnName] = array( 'notnull' => true, - 'type' => Type::getType($rootClass->getTypeOfColumn($idColumnName)), + 'type' => Type::getType(PersisterHelper::getTypeOfColumn($idColumnName, $rootClass, $this->em)), ); } diff --git a/lib/Doctrine/ORM/Persisters/Entity/AbstractEntityInheritancePersister.php b/lib/Doctrine/ORM/Persisters/Entity/AbstractEntityInheritancePersister.php index 6b5e5c4f1..aa2038ffc 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/AbstractEntityInheritancePersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/AbstractEntityInheritancePersister.php @@ -60,16 +60,19 @@ abstract class AbstractEntityInheritancePersister extends BasicEntityPersister */ protected function getSelectColumnSQL($field, ClassMetadata $class, $alias = 'r') { - $tableAlias = $alias == 'r' ? '' : $alias; - $columnName = $class->columnNames[$field]; - $columnAlias = $this->getSQLColumnAlias($columnName); - $sql = $this->getSQLTableAlias($class->name, $tableAlias) . '.' - . $this->quoteStrategy->getColumnName($field, $class, $this->platform); + $tableAlias = $alias == 'r' ? '' : $alias; + $fieldMapping = $class->fieldMappings[$field]; + $columnAlias = $this->getSQLColumnAlias($fieldMapping['columnName']); + $sql = sprintf( + '%s.%s', + $this->getSQLTableAlias($class->name, $tableAlias), + $this->quoteStrategy->getColumnName($field, $class, $this->platform) + ); $this->currentPersisterContext->rsm->addFieldResult($alias, $columnAlias, $field, $class->name); - if (isset($class->fieldMappings[$field]['requireSQLConversion'])) { - $type = Type::getType($class->getTypeOfField($field)); + if (isset($fieldMapping['requireSQLConversion'])) { + $type = Type::getType($fieldMapping['type']); $sql = $type->convertToPHPValueSQL($sql, $this->platform); } diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 7ab1d3b1c..8d6ce7e7d 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -331,10 +331,11 @@ class BasicEntityPersister implements EntityPersister */ protected function fetchVersionValue($versionedClass, array $id) { - $versionField = $versionedClass->versionField; - $tableName = $this->quoteStrategy->getTableName($versionedClass, $this->platform); - $identifier = $this->quoteStrategy->getIdentifierColumnNames($versionedClass, $this->platform); - $columnName = $this->quoteStrategy->getColumnName($versionField, $versionedClass, $this->platform); + $versionField = $versionedClass->versionField; + $fieldMapping = $versionedClass->fieldMappings[$versionField]; + $tableName = $this->quoteStrategy->getTableName($versionedClass, $this->platform); + $identifier = $this->quoteStrategy->getIdentifierColumnNames($versionedClass, $this->platform); + $columnName = $this->quoteStrategy->getColumnName($versionField, $versionedClass, $this->platform); // FIXME: Order with composite keys might not be correct $sql = 'SELECT ' . $columnName @@ -345,7 +346,7 @@ class BasicEntityPersister implements EntityPersister $value = $this->conn->fetchColumn($sql, array_values($flatId)); - return Type::getType($versionedClass->fieldMappings[$versionField]['type'])->convertToPHPValue($value, $this->platform); + return Type::getType($fieldMapping['type'])->convertToPHPValue($value, $this->platform); } /** @@ -424,7 +425,6 @@ class BasicEntityPersister implements EntityPersister foreach ($this->class->identifier as $idField) { if ( ! isset($this->class->associationMappings[$idField])) { - $params[] = $identifier[$idField]; $types[] = $this->class->fieldMappings[$idField]['type']; $where[] = $this->quoteStrategy->getColumnName($idField, $this->class, $this->platform); @@ -550,18 +550,18 @@ class BasicEntityPersister implements EntityPersister */ public function delete($entity) { + $self = $this; $class = $this->class; $identifier = $this->em->getUnitOfWork()->getEntityIdentifier($entity); $tableName = $this->quoteStrategy->getTableName($class, $this->platform); $idColumns = $this->quoteStrategy->getIdentifierColumnNames($class, $this->platform); $id = array_combine($idColumns, $identifier); - $types = array_map(function ($identifier) use ($class) { - + $types = array_map(function ($identifier) use ($class, $self) { if (isset($class->fieldMappings[$identifier])) { return $class->fieldMappings[$identifier]['type']; } - $targetMapping = $this->em->getClassMetadata($class->associationMappings[$identifier]['targetEntity']); + $targetMapping = $self->em->getClassMetadata($class->associationMappings[$identifier]['targetEntity']); if (isset($targetMapping->fieldMappings[$targetMapping->identifier[0]])) { return $targetMapping->fieldMappings[$targetMapping->identifier[0]]['type']; @@ -572,7 +572,6 @@ class BasicEntityPersister implements EntityPersister } throw ORMException::unrecognizedField($targetMapping->identifier[0]); - }, $class->identifier); $this->deleteJoinTableRecords($identifier); @@ -623,8 +622,11 @@ class BasicEntityPersister implements EntityPersister $newVal = $change[1]; if ( ! isset($this->class->associationMappings[$field])) { - $columnName = $this->class->columnNames[$field]; - $this->columnTypes[$columnName] = $this->class->fieldMappings[$field]['type']; + $fieldMapping = $this->class->fieldMappings[$field]; + $columnName = $fieldMapping['columnName']; + + $this->columnTypes[$columnName] = $fieldMapping['type']; + $result[$this->getOwningTable($field)][$columnName] = $newVal; continue; @@ -988,7 +990,6 @@ class BasicEntityPersister implements EntityPersister $quotedJoinTable = $this->quoteStrategy->getJoinTableName($association, $class, $this->platform); foreach ($joinColumns as $joinColumn) { - $sourceKeyColumn = $joinColumn['referencedColumnName']; $quotedKeyColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); @@ -1314,19 +1315,19 @@ class BasicEntityPersister implements EntityPersister return ''; } - $columnList = array(); - $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); + $columnList = array(); + $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); + $isIdentifier = isset($assoc['id']) && $assoc['id'] === true; + $sqlTableAlias = $this->getSQLTableAlias($class->name, ($alias == 'r' ? '' : $alias)); foreach ($assoc['joinColumns'] as $joinColumn) { - $type = null; - $isIdentifier = isset($assoc['id']) && $assoc['id'] === true; $quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->class, $this->platform); $resultColumnName = $this->getSQLColumnAlias($joinColumn['name']); - $columnList[] = $this->getSQLTableAlias($class->name, ($alias == 'r' ? '' : $alias) ) - . '.' . $quotedColumn . ' AS ' . $resultColumnName; $type = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); $this->currentPersisterContext->rsm->addMetaResult($alias, $resultColumnName, $quotedColumn, $isIdentifier, $type); + + $columnList[] = sprintf('%s.%s AS %s', $sqlTableAlias, $quotedColumn, $resultColumnName); } return implode(', ', $columnList); @@ -1393,7 +1394,6 @@ class BasicEntityPersister implements EntityPersister if (isset($this->class->fieldNames[$column]) && isset($this->columnTypes[$this->class->fieldNames[$column]]) && isset($this->class->fieldMappings[$this->class->fieldNames[$column]]['requireSQLConversion'])) { - $type = Type::getType($this->columnTypes[$this->class->fieldNames[$column]]); $placeholder = $type->convertToDatabaseValueSQL('?', $this->platform); } @@ -1432,6 +1432,7 @@ class BasicEntityPersister implements EntityPersister if (isset($this->class->associationMappings[$name])) { $assoc = $this->class->associationMappings[$name]; + if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE) { foreach ($assoc['joinColumns'] as $joinColumn) { $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->class, $this->platform); @@ -1462,17 +1463,17 @@ class BasicEntityPersister implements EntityPersister */ protected function getSelectColumnSQL($field, ClassMetadata $class, $alias = 'r') { - $root = $alias == 'r' ? '' : $alias ; - $tableAlias = $this->getSQLTableAlias($class->name, $root); - $columnName = $this->quoteStrategy->getColumnName($field, $class, $this->platform); - $sql = $tableAlias . '.' . $columnName; - $columnAlias = $this->getSQLColumnAlias($class->columnNames[$field]); + $root = $alias == 'r' ? '' : $alias ; + $tableAlias = $this->getSQLTableAlias($class->name, $root); + $fieldMapping = $class->fieldMappings[$field]; + $sql = sprintf('%s.%s', $tableAlias, $this->quoteStrategy->getColumnName($field, $class, $this->platform)); + $columnAlias = $this->getSQLColumnAlias($fieldMapping['columnName']); $this->currentPersisterContext->rsm->addFieldResult($alias, $columnAlias, $field); - if (isset($class->fieldMappings[$field]['requireSQLConversion'])) { - $type = Type::getType($class->getTypeOfField($field)); - $sql = $type->convertToPHPValueSQL($sql, $this->platform); + if (isset($fieldMapping['requireSQLConversion'])) { + $type = Type::getType($fieldMapping['type']); + $sql = $type->convertToPHPValueSQL($sql, $this->platform); } return $sql . ' AS ' . $columnAlias; @@ -1593,22 +1594,26 @@ class BasicEntityPersister implements EntityPersister $placeholder = '?'; if (isset($this->class->fieldMappings[$field]['requireSQLConversion'])) { - $placeholder = Type::getType($this->class->getTypeOfField($field))->convertToDatabaseValueSQL($placeholder, $this->platform); + $type = Type::getType($this->class->fieldMappings[$field]['type']); + $placeholder = $type->convertToDatabaseValueSQL($placeholder, $this->platform); } if (null !== $comparison) { // special case null value handling if (($comparison === Comparison::EQ || $comparison === Comparison::IS) && null ===$value) { $selectedColumns[] = $column . ' IS NULL'; + continue; } if ($comparison === Comparison::NEQ && null === $value) { $selectedColumns[] = $column . ' IS NOT NULL'; + continue; } $selectedColumns[] = $column . ' ' . sprintf(self::$comparisonMap[$comparison], $placeholder); + continue; } @@ -1617,15 +1622,18 @@ class BasicEntityPersister implements EntityPersister if (false !== array_search(null, $value, true)) { $selectedColumns[] = sprintf('(%s OR %s IS NULL)', $in, $column); + continue; } $selectedColumns[] = $in; + continue; } if (null === $value) { $selectedColumns[] = sprintf('%s IS NULL', $column); + continue; } @@ -1647,7 +1655,7 @@ class BasicEntityPersister implements EntityPersister */ private function getSelectConditionStatementColumnSQL($field, $assoc = null) { - if (isset($this->class->columnNames[$field])) { + if (isset($this->class->fieldMappings[$field])) { $className = (isset($this->class->fieldMappings[$field]['inherited'])) ? $this->class->fieldMappings[$field]['inherited'] : $this->class->name; @@ -1677,7 +1685,6 @@ class BasicEntityPersister implements EntityPersister } } else { - if ( ! $association['isOwningSide']) { throw ORMException::invalidFindByInverseAssociation($this->class->name, $field); } @@ -1767,8 +1774,7 @@ class BasicEntityPersister implements EntityPersister $parameters = array(); $owningAssoc = $this->class->associationMappings[$assoc['mappedBy']]; $sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']); - - $tableAlias = $this->getSQLTableAlias(isset($owningAssoc['inherited']) ? $owningAssoc['inherited'] : $this->class->name); + $tableAlias = $this->getSQLTableAlias(isset($owningAssoc['inherited']) ? $owningAssoc['inherited'] : $this->class->name); foreach ($owningAssoc['targetToSourceKeyColumns'] as $sourceKeyColumn => $targetKeyColumn) { if ($sourceClass->containsForeignIdentifier) { @@ -1873,7 +1879,7 @@ class BasicEntityPersister implements EntityPersister switch (true) { case (isset($class->fieldMappings[$field])): - $types = array_merge($types, PersisterHelper::getTypeOfField($field, $class, $this->em)); + $types = array_merge($types, array($class->fieldMappings[$field]['type'])); break; case (isset($class->associationMappings[$field])): @@ -1900,12 +1906,11 @@ class BasicEntityPersister implements EntityPersister } if (is_array($value)) { - return array_map( - function ($type) { - return Type::getType($type)->getBindingType() + Connection::ARRAY_PARAM_OFFSET; - }, - $types - ); + return array_map(function ($type) { + $type = Type::getType($type); + + return $type->getBindingType() + Connection::ARRAY_PARAM_OFFSET; + }, $types); } return $types; diff --git a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php index b807fbae9..466ce9a14 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php @@ -257,11 +257,13 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister // table were affected. if ($isVersioned) { if ( ! isset($updateData[$versionedTable])) { - $tableName = $this->quoteStrategy->getTableName($versionedClass, $this->platform); + $tableName = $this->quoteStrategy->getTableName($versionedClass, $this->platform); + $this->updateTable($entity, $tableName, array(), true); } $identifiers = $this->em->getUnitOfWork()->getEntityIdentifier($entity); + $this->assignDefaultVersionValue($entity, $identifiers); } } @@ -434,12 +436,13 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $columnList = array(); $discrColumn = $this->class->discriminatorColumn['name']; + $discrColumnType = $this->class->discriminatorColumn['type']; $baseTableAlias = $this->getSQLTableAlias($this->class->name); $resultColumnName = $this->platform->getSQLResultCasing($discrColumn); $this->currentPersisterContext->rsm->addEntityResult($this->class->name, 'r'); $this->currentPersisterContext->rsm->setDiscriminatorColumn('r', $resultColumnName); - $this->currentPersisterContext->rsm->addMetaResult('r', $resultColumnName, $discrColumn); + $this->currentPersisterContext->rsm->addMetaResult('r', $resultColumnName, $discrColumn, false, $discrColumnType); // Add regular columns foreach ($this->class->fieldMappings as $fieldName => $mapping) { diff --git a/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php b/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php index f9e4d5573..8dc71bb1d 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php @@ -58,13 +58,15 @@ class SingleTablePersister extends AbstractEntityInheritancePersister $tableAlias = $this->getSQLTableAlias($rootClass->name); // Append discriminator column - $discrColumn = $this->class->discriminatorColumn['name']; + $discrColumn = $this->class->discriminatorColumn['name']; + $discrColumnType = $this->class->discriminatorColumn['type']; + $columnList[] = $tableAlias . '.' . $discrColumn; $resultColumnName = $this->platform->getSQLResultCasing($discrColumn); $this->currentPersisterContext->rsm->setDiscriminatorColumn('r', $resultColumnName); - $this->currentPersisterContext->rsm->addMetaResult('r', $resultColumnName, $discrColumn); + $this->currentPersisterContext->rsm->addMetaResult('r', $resultColumnName, $discrColumn, false, $discrColumnType); // Append subclass columns foreach ($this->class->subClasses as $subClassName) { @@ -81,17 +83,14 @@ class SingleTablePersister extends AbstractEntityInheritancePersister // Foreign key columns foreach ($subClass->associationMappings as $assoc) { - if ( ! $assoc['isOwningSide'] - || ! ($assoc['type'] & ClassMetadata::TO_ONE) - || isset($assoc['inherited'])) { + if ( ! $assoc['isOwningSide'] || ! ($assoc['type'] & ClassMetadata::TO_ONE) || isset($assoc['inherited'])) { continue; } + $className = isset($assoc['inherited']) ? $assoc['inherited'] : $this->class->name; + $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); + foreach ($assoc['targetToSourceKeyColumns'] as $srcColumn) { - $className = isset($assoc['inherited']) ? $assoc['inherited'] : $this->class->name; - - $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); - $columnList[] = $this->getSelectJoinColumnSQL( $tableAlias, $srcColumn, diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php index 4e5303ce7..12713e1a7 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableDeleteExecutor.php @@ -20,7 +20,9 @@ namespace Doctrine\ORM\Query\Exec; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Query\AST; +use Doctrine\ORM\Utility\PersisterHelper; /** * Executes the SQL statements for bulk DQL DELETE statements on classes in @@ -103,7 +105,7 @@ class MultiTableDeleteExecutor extends AbstractSqlExecutor foreach ($idColumnNames as $idColumnName) { $columnDefinitions[$idColumnName] = array( 'notnull' => true, - 'type' => \Doctrine\DBAL\Types\Type::getType($rootClass->getTypeOfColumn($idColumnName)) + 'type' => Type::getType(PersisterHelper::getTypeOfColumn($idColumnName, $rootClass, $em)), ); } $this->_createTempTableSql = $platform->getCreateTemporaryTableSnippetSQL() . ' ' . $tempTable . ' (' diff --git a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php index 54653fc55..b47ba1795 100644 --- a/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php +++ b/lib/Doctrine/ORM/Query/Exec/MultiTableUpdateExecutor.php @@ -21,9 +21,9 @@ namespace Doctrine\ORM\Query\Exec; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Types\Type; - use Doctrine\ORM\Query\ParameterTypeInferer; use Doctrine\ORM\Query\AST; +use Doctrine\ORM\Utility\PersisterHelper; /** * Executes the SQL statements for bulk DQL UPDATE statements on classes in @@ -111,8 +111,8 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor foreach ($updateItems as $updateItem) { $field = $updateItem->pathExpression->field; - if (isset($class->fieldMappings[$field]) && ! isset($class->fieldMappings[$field]['inherited']) || - isset($class->associationMappings[$field]) && ! isset($class->associationMappings[$field]['inherited'])) { + if ((isset($class->fieldMappings[$field]) && ! isset($class->fieldMappings[$field]['inherited'])) || + (isset($class->associationMappings[$field]) && ! isset($class->associationMappings[$field]['inherited']))) { $newValue = $updateItem->newValue; if ( ! $affected) { @@ -148,7 +148,7 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor foreach ($idColumnNames as $idColumnName) { $columnDefinitions[$idColumnName] = array( 'notnull' => true, - 'type' => Type::getType($rootClass->getTypeOfColumn($idColumnName)) + 'type' => Type::getType(PersisterHelper::getTypeOfColumn($idColumnName, $rootClass, $em)), ); } diff --git a/lib/Doctrine/ORM/Query/ResultSetMapping.php b/lib/Doctrine/ORM/Query/ResultSetMapping.php index bdd5de75e..2fad66825 100644 --- a/lib/Doctrine/ORM/Query/ResultSetMapping.php +++ b/lib/Doctrine/ORM/Query/ResultSetMapping.php @@ -558,6 +558,8 @@ class ResultSetMapping * @param string $type The column type * * @return ResultSetMapping This ResultSetMapping instance. + * + * @todo Make all methods of this class require all parameters and not infer anything */ public function addMetaResult($alias, $columnName, $fieldName, $isIdentifierColumn = false, $type = null) { diff --git a/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php b/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php index 2b22d52e2..9dbb7277e 100644 --- a/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php +++ b/lib/Doctrine/ORM/Query/ResultSetMappingBuilder.php @@ -19,8 +19,11 @@ namespace Doctrine\ORM\Query; +use Doctrine\DBAL\Types\Type; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\ORM\Mapping\MappingException; +use Doctrine\ORM\Utility\PersisterHelper; /** * A ResultSetMappingBuilder uses the EntityManager to automatically populate entity fields. @@ -160,20 +163,19 @@ class ResultSetMappingBuilder extends ResultSetMapping foreach ($classMetadata->associationMappings as $associationMapping) { if ($associationMapping['isOwningSide'] && $associationMapping['type'] & ClassMetadataInfo::TO_ONE) { + $targetClass = $this->em->getClassMetadata($associationMapping['targetEntity']); + $isIdentifier = isset($associationMapping['id']) && $associationMapping['id'] === true; + foreach ($associationMapping['joinColumns'] as $joinColumn) { $columnName = $joinColumn['name']; $columnAlias = $platform->getSQLResultCasing($columnAliasMap[$columnName]); + $columnType = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); if (isset($this->metaMappings[$columnAlias])) { throw new \InvalidArgumentException("The column '$columnAlias' conflicts with another column in the mapper."); } - $this->addMetaResult( - $alias, - $columnAlias, - $columnName, - (isset($associationMapping['id']) && $associationMapping['id'] === true) - ); + $this->addMetaResult($alias, $columnAlias, $columnName, $isIdentifier, $columnType); } } } @@ -284,21 +286,27 @@ class ResultSetMappingBuilder extends ResultSetMapping $this->addEntityResult($class->name, $alias); if ($classMetadata->discriminatorColumn) { - $discriminatorColumn = $classMetadata->discriminatorColumn; - $this->setDiscriminatorColumn($alias, $discriminatorColumn['name']); - $this->addMetaResult($alias, $discriminatorColumn['name'], $discriminatorColumn['fieldName']); + $discrColumn = $classMetadata->discriminatorColumn; + + $this->setDiscriminatorColumn($alias, $discrColumn['name']); + $this->addMetaResult($alias, $discrColumn['name'], $discrColumn['fieldName'], false, $discrColumn['type']); } foreach ($classMetadata->getColumnNames() as $key => $columnName) { - $propertyName = $classMetadata->getFieldName($columnName); + $propertyName = $classMetadata->getFieldName($columnName); + $this->addFieldResult($alias, $columnName, $propertyName); } foreach ($classMetadata->associationMappings as $associationMapping) { if ($associationMapping['isOwningSide'] && $associationMapping['type'] & ClassMetadataInfo::TO_ONE) { + $targetClass = $this->em->getClassMetadata($associationMapping['targetEntity']); + foreach ($associationMapping['joinColumns'] as $joinColumn) { - $columnName = $joinColumn['name']; - $this->addMetaResult($alias, $columnName, $columnName, $classMetadata->isIdentifier($columnName)); + $columnName = $joinColumn['name']; + $columnType = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); + + $this->addMetaResult($alias, $columnName, $columnName, $classMetadata->isIdentifier($columnName), $columnType); } } } @@ -318,8 +326,8 @@ class ResultSetMappingBuilder extends ResultSetMapping { $counter = 0; $resultMapping = $class->getSqlResultSetMapping($resultSetMappingName); - $rooShortName = $class->reflClass->getShortName(); - $rootAlias = strtolower($rooShortName[0]) . $counter; + $rootShortName = $class->reflClass->getShortName(); + $rootAlias = strtolower($rootShortName[0]) . $counter; if (isset($resultMapping['entities'])) { @@ -334,9 +342,10 @@ class ResultSetMappingBuilder extends ResultSetMapping $joinAlias = strtolower($shortName[0]) . ++ $counter; $associations = $class->getAssociationsByTargetClass($classMetadata->name); + $this->addNamedNativeQueryEntityResultMapping($classMetadata, $entityMapping, $joinAlias); + foreach ($associations as $relation => $mapping) { $this->addJoinedEntityResult($mapping['targetEntity'], $joinAlias, $rootAlias, $relation); - $this->addNamedNativeQueryEntityResultMapping($classMetadata, $entityMapping, $joinAlias); } } @@ -345,7 +354,11 @@ class ResultSetMappingBuilder extends ResultSetMapping if (isset($resultMapping['columns'])) { foreach ($resultMapping['columns'] as $entityMapping) { - $this->addScalarResult($entityMapping['name'], $entityMapping['name']); + $type = isset($class->fieldNames[$entityMapping['name']]) + ? PersisterHelper::getTypeOfColumn($entityMapping['name'], $class, $this->em) + : 'string'; + + $this->addScalarResult($entityMapping['name'], $entityMapping['name'], $type); } } @@ -361,14 +374,17 @@ class ResultSetMappingBuilder extends ResultSetMapping * * @return ResultSetMappingBuilder * + * @throws MappingException * @throws \InvalidArgumentException */ public function addNamedNativeQueryEntityResultMapping(ClassMetadataInfo $classMetadata, array $entityMapping, $alias) { if (isset($entityMapping['discriminatorColumn']) && $entityMapping['discriminatorColumn']) { $discriminatorColumn = $entityMapping['discriminatorColumn']; + $discriminatorType = $classMetadata->discriminatorColumn['type']; + $this->setDiscriminatorColumn($alias, $discriminatorColumn); - $this->addMetaResult($alias, $discriminatorColumn, $discriminatorColumn); + $this->addMetaResult($alias, $discriminatorColumn, $discriminatorColumn, false, $discriminatorType); } if (isset($entityMapping['fields']) && !empty($entityMapping['fields'])) { @@ -376,32 +392,34 @@ class ResultSetMappingBuilder extends ResultSetMapping $fieldName = $field['name']; $relation = null; - if(strpos($fieldName, '.')){ + if (strpos($fieldName, '.') !== false) { list($relation, $fieldName) = explode('.', $fieldName); } if (isset($classMetadata->associationMappings[$relation])) { - if($relation) { + if ($relation) { $associationMapping = $classMetadata->associationMappings[$relation]; $joinAlias = $alias.$relation; $parentAlias = $alias; $this->addJoinedEntityResult($associationMapping['targetEntity'], $joinAlias, $parentAlias, $relation); $this->addFieldResult($joinAlias, $field['column'], $fieldName); - }else { + } else { $this->addFieldResult($alias, $field['column'], $fieldName, $classMetadata->name); } } else { - if(!isset($classMetadata->fieldMappings[$fieldName])) { + if( ! isset($classMetadata->fieldMappings[$fieldName])) { throw new \InvalidArgumentException("Entity '".$classMetadata->name."' has no field '".$fieldName."'. "); } + $this->addFieldResult($alias, $field['column'], $fieldName, $classMetadata->name); } } } else { foreach ($classMetadata->getColumnNames() as $columnName) { - $propertyName = $classMetadata->getFieldName($columnName); + $propertyName = $classMetadata->getFieldName($columnName); + $this->addFieldResult($alias, $columnName, $propertyName); } } diff --git a/lib/Doctrine/ORM/Query/SqlWalker.php b/lib/Doctrine/ORM/Query/SqlWalker.php index 3dea8de4b..4f1932ea8 100644 --- a/lib/Doctrine/ORM/Query/SqlWalker.php +++ b/lib/Doctrine/ORM/Query/SqlWalker.php @@ -22,9 +22,10 @@ namespace Doctrine\ORM\Query; use Doctrine\DBAL\LockMode; use Doctrine\DBAL\Types\Type; use Doctrine\ORM\Mapping\ClassMetadata; -use Doctrine\ORM\Query; -use Doctrine\ORM\OptimisticLockException; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\ORM\OptimisticLockException; +use Doctrine\ORM\Query; +use Doctrine\ORM\Utility\PersisterHelper; /** * The SqlWalker is a TreeWalker that walks over a DQL AST and constructs @@ -456,8 +457,11 @@ class SqlWalker implements TreeWalker $values[] = $conn->quote($this->em->getClassMetadata($subclassName)->discriminatorValue); } - $sqlParts[] = (($this->useSqlTableAliases) ? $this->getSQLTableAlias($class->getTableName(), $dqlAlias) . '.' : '') - . $class->discriminatorColumn['name'] . ' IN (' . implode(', ', $values) . ')'; + $sqlTableAlias = ($this->useSqlTableAliases) + ? $this->getSQLTableAlias($class->getTableName(), $dqlAlias) . '.' + : ''; + + $sqlParts[] = $sqlTableAlias . $class->discriminatorColumn['name'] . ' IN (' . implode(', ', $values) . ')'; } $sql = implode(' AND ', $sqlParts); @@ -735,7 +739,7 @@ class SqlWalker implements TreeWalker $sqlSelectExpressions[] = $tblAlias . '.' . $discrColumn['name'] . ' AS ' . $columnAlias; $this->rsm->setDiscriminatorColumn($dqlAlias, $columnAlias); - $this->rsm->addMetaResult($dqlAlias, $columnAlias, $discrColumn['fieldName']); + $this->rsm->addMetaResult($dqlAlias, $columnAlias, $discrColumn['fieldName'], false, $discrColumn['type']); } // Add foreign key columns to SQL, if necessary @@ -751,23 +755,19 @@ class SqlWalker implements TreeWalker continue; } + $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); + $isIdentifier = (isset($assoc['id']) && $assoc['id'] === true); $owningClass = (isset($assoc['inherited'])) ? $this->em->getClassMetadata($assoc['inherited']) : $class; $sqlTableAlias = $this->getSQLTableAlias($owningClass->getTableName(), $dqlAlias); - $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); + foreach ($assoc['joinColumns'] as $joinColumn) { + $columnName = $joinColumn['name']; + $columnAlias = $this->getSQLColumnAlias($columnName); + $columnType = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); - foreach ($assoc['targetToSourceKeyColumns'] as $targetColumn => $srcColumn) { - $columnAlias = $this->getSQLColumnAlias($srcColumn); + $sqlSelectExpressions[] = $sqlTableAlias . '.' . $columnName . ' AS ' . $columnAlias; - $type = null; - $isIdentifier = (isset($assoc['id']) && $assoc['id'] === true); - $sqlSelectExpressions[] = $sqlTableAlias . '.' . $srcColumn . ' AS ' . $columnAlias; - - if (isset($targetClass->fieldNames[$targetColumn])) { - $type = $targetClass->fieldMappings[$targetClass->fieldNames[$targetColumn]]['type']; - } - - $this->rsm->addMetaResult($dqlAlias, $columnAlias, $srcColumn, $isIdentifier, $type); + $this->rsm->addMetaResult($dqlAlias, $columnAlias, $columnName, $isIdentifier, $columnType); } } @@ -785,14 +785,18 @@ class SqlWalker implements TreeWalker // Skip if association is inherited if (isset($assoc['inherited'])) continue; - if ( ! ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE)) continue; + if ($assoc['isOwningSide'] && $assoc['type'] & ClassMetadata::TO_ONE) { + $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); - foreach ($assoc['targetToSourceKeyColumns'] as $srcColumn) { - $columnAlias = $this->getSQLColumnAlias($srcColumn); + foreach ($assoc['joinColumns'] as $joinColumn) { + $columnName = $joinColumn['name']; + $columnAlias = $this->getSQLColumnAlias($columnName); + $columnType = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); - $sqlSelectExpressions[] = $sqlTableAlias . '.' . $srcColumn . ' AS ' . $columnAlias; + $sqlSelectExpressions[] = $sqlTableAlias . '.' . $columnName . ' AS ' . $columnAlias; - $this->rsm->addMetaResult($dqlAlias, $columnAlias, $srcColumn); + $this->rsm->addMetaResult($dqlAlias, $columnAlias, $columnName, $subClass->isIdentifier($columnName), $columnType); + } } } } @@ -1296,15 +1300,13 @@ class SqlWalker implements TreeWalker : $class->getTableName(); $sqlTableAlias = $this->getSQLTableAlias($tableName, $dqlAlias); + $fieldMapping = $class->fieldMappings[$fieldName]; $columnName = $this->quoteStrategy->getColumnName($fieldName, $class, $this->platform); - $columnAlias = $this->getSQLColumnAlias($class->fieldMappings[$fieldName]['columnName']); + $columnAlias = $this->getSQLColumnAlias($fieldMapping['columnName']); + $col = $sqlTableAlias . '.' . $columnName; - $col = $sqlTableAlias . '.' . $columnName; - - $fieldType = $class->getTypeOfField($fieldName); - - if (isset($class->fieldMappings[$fieldName]['requireSQLConversion'])) { - $type = Type::getType($fieldType); + if (isset($fieldMapping['requireSQLConversion'])) { + $type = Type::getType($fieldMapping['type']); $col = $type->convertToPHPValueSQL($col, $this->conn->getDatabasePlatform()); } @@ -1313,9 +1315,10 @@ class SqlWalker implements TreeWalker $this->scalarResultAliasMap[$resultAlias] = $columnAlias; if ( ! $hidden) { - $this->rsm->addScalarResult($columnAlias, $resultAlias, $fieldType); + $this->rsm->addScalarResult($columnAlias, $resultAlias, $fieldMapping['type']); $this->scalarFields[$dqlAlias][$fieldName] = $columnAlias; } + break; case ($expr instanceof AST\AggregateExpression): @@ -1400,8 +1403,8 @@ class SqlWalker implements TreeWalker $col = $sqlTableAlias . '.' . $quotedColumnName; - if (isset($class->fieldMappings[$fieldName]['requireSQLConversion'])) { - $type = Type::getType($class->getTypeOfField($fieldName)); + if (isset($mapping['requireSQLConversion'])) { + $type = Type::getType($mapping['type']); $col = $type->convertToPHPValueSQL($col, $this->platform); } @@ -1422,7 +1425,7 @@ class SqlWalker implements TreeWalker $sqlTableAlias = $this->getSQLTableAlias($subClass->getTableName(), $dqlAlias); foreach ($subClass->fieldMappings as $fieldName => $mapping) { - if (isset($mapping['inherited']) || $partialFieldSet && !in_array($fieldName, $partialFieldSet)) { + if (isset($mapping['inherited']) || ($partialFieldSet && !in_array($fieldName, $partialFieldSet))) { continue; } @@ -1431,8 +1434,8 @@ class SqlWalker implements TreeWalker $col = $sqlTableAlias . '.' . $quotedColumnName; - if (isset($subClass->fieldMappings[$fieldName]['requireSQLConversion'])) { - $type = Type::getType($subClass->getTypeOfField($fieldName)); + if (isset($mapping['requireSQLConversion'])) { + $type = Type::getType($mapping['type']); $col = $type->convertToPHPValueSQL($col, $this->platform); } @@ -1543,11 +1546,10 @@ class SqlWalker implements TreeWalker break; case ($e instanceof AST\PathExpression): - $fieldName = $e->field; $dqlAlias = $e->identificationVariable; $qComp = $this->queryComponents[$dqlAlias]; $class = $qComp['metadata']; - $fieldType = $class->getTypeOfField($fieldName); + $fieldType = $class->fieldMappings[$e->field]['type']; $sqlSelectExpressions[] = trim($e->dispatch($this)) . ' AS ' . $columnAlias; break; diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php index e65cfcaeb..d65ab6cfe 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryWalker.php @@ -89,7 +89,7 @@ class LimitSubqueryWalker extends TreeWalkerAdapter $this->_getQuery()->setHint( self::IDENTIFIER_TYPE, - Type::getType($rootClass->getTypeOfField($identifier)) + Type::getType($rootClass->fieldMappings[$identifier]['type']) ); $pathExpression = new PathExpression( @@ -97,9 +97,11 @@ class LimitSubqueryWalker extends TreeWalkerAdapter $rootAlias, $identifier ); + $pathExpression->type = PathExpression::TYPE_STATE_FIELD; array_unshift($selectExpressions, new SelectExpression($pathExpression, '_dctrn_id')); + $AST->selectClause->selectExpressions = $selectExpressions; if (isset($AST->orderByClause)) { diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php index 594f79f78..a9f548ffc 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869ChequePayment.php @@ -26,7 +26,7 @@ namespace Doctrine\Tests\Models\DDC869; class DDC869ChequePayment extends DDC869Payment { - /** @column(type="string") */ + /** @Column(type="string") */ protected $serialNumber; public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php index 9e978d494..cd637b3c0 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869CreditCardPayment.php @@ -26,7 +26,7 @@ namespace Doctrine\Tests\Models\DDC869; class DDC869CreditCardPayment extends DDC869Payment { - /** @column(type="string") */ + /** @Column(type="string") */ protected $creditCardNumber; public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) diff --git a/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php index b9b8febdc..01e7fbefd 100644 --- a/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php +++ b/tests/Doctrine/Tests/Models/DDC869/DDC869Payment.php @@ -33,7 +33,7 @@ class DDC869Payment */ protected $id; - /** @column(type="float") */ + /** @Column(type="float") */ protected $value; diff --git a/tests/Doctrine/Tests/Models/DDC964/DDC964Admin.php b/tests/Doctrine/Tests/Models/DDC964/DDC964Admin.php index e22b973de..464471b31 100644 --- a/tests/Doctrine/Tests/Models/DDC964/DDC964Admin.php +++ b/tests/Doctrine/Tests/Models/DDC964/DDC964Admin.php @@ -23,7 +23,7 @@ use Doctrine\Common\Collections\ArrayCollection; */ class DDC964Admin extends DDC964User { - public static function loadMetadata($metadata) + public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { $metadata->setAssociationOverride('address',array( 'joinColumns'=>array(array( diff --git a/tests/Doctrine/Tests/Models/DDC964/DDC964Guest.php b/tests/Doctrine/Tests/Models/DDC964/DDC964Guest.php index 90501187c..935ee59c0 100644 --- a/tests/Doctrine/Tests/Models/DDC964/DDC964Guest.php +++ b/tests/Doctrine/Tests/Models/DDC964/DDC964Guest.php @@ -26,7 +26,7 @@ use Doctrine\Common\Collections\ArrayCollection; */ class DDC964Guest extends DDC964User { - public static function loadMetadata($metadata) + public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { $metadata->setAttributeOverride('id', array( 'columnName' => 'guest_id', diff --git a/tests/Doctrine/Tests/Models/DDC964/DDC964User.php b/tests/Doctrine/Tests/Models/DDC964/DDC964User.php index 4ed88d638..f1bfdae39 100644 --- a/tests/Doctrine/Tests/Models/DDC964/DDC964User.php +++ b/tests/Doctrine/Tests/Models/DDC964/DDC964User.php @@ -107,7 +107,7 @@ class DDC964User $this->address = $address; } - public static function loadMetadata($metadata) + public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) { $metadata->mapField(array( 'id' => true, diff --git a/tests/Doctrine/Tests/Models/Generic/NonAlphaColumnsEntity.php b/tests/Doctrine/Tests/Models/Generic/NonAlphaColumnsEntity.php new file mode 100644 index 000000000..7c2b888fc --- /dev/null +++ b/tests/Doctrine/Tests/Models/Generic/NonAlphaColumnsEntity.php @@ -0,0 +1,30 @@ +value = $value; + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/Global/GlobalNamespaceModel.php b/tests/Doctrine/Tests/Models/Global/GlobalNamespaceModel.php index d474832ee..b661d78be 100644 --- a/tests/Doctrine/Tests/Models/Global/GlobalNamespaceModel.php +++ b/tests/Doctrine/Tests/Models/Global/GlobalNamespaceModel.php @@ -1,19 +1,19 @@ em); - $rsm->addScalarResult('id', 'u'); + $rsm->addScalarResult('id', 'u', 'integer'); $this->queryCache->put($key, $rsm, $result); } diff --git a/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php b/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php index 5504246d5..85d588880 100644 --- a/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/DetachedEntityTest.php @@ -58,12 +58,16 @@ class DetachedEntityTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->persist($user); $this->_em->flush(); + $this->assertTrue($this->_em->contains($user)); $this->assertTrue($user->phonenumbers->isInitialized()); $serialized = serialize($user); + $this->_em->clear(); + $this->assertFalse($this->_em->contains($user)); + unset($user); $user = unserialize($serialized); @@ -71,9 +75,12 @@ class DetachedEntityTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(1, count($user->getPhonenumbers()), "Pre-Condition: 1 Phonenumber"); $ph2 = new CmsPhonenumber; + $ph2->phonenumber = "56789"; $user->addPhonenumber($ph2); + $oldPhonenumbers = $user->getPhonenumbers(); + $this->assertEquals(2, count($oldPhonenumbers), "Pre-Condition: 2 Phonenumbers"); $this->assertFalse($this->_em->contains($user)); diff --git a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php index 3ce6437f3..df55bd798 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/Locking/OptimisticTest.php @@ -32,8 +32,10 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testJoinedChildInsertSetsInitialVersionValue() { $test = new OptimisticJoinedChild(); + $test->name = 'child'; $test->whatever = 'whatever'; + $this->_em->persist($test); $this->_em->flush(); @@ -48,7 +50,9 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testJoinedChildFailureThrowsException(OptimisticJoinedChild $child) { $q = $this->_em->createQuery('SELECT t FROM Doctrine\Tests\ORM\Functional\Locking\OptimisticJoinedChild t WHERE t.id = :id'); + $q->setParameter('id', $child->id); + $test = $q->getSingleResult(); // Manually update/increment the version so we can try and save the same @@ -58,6 +62,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase // Now lets change a property and try and save it again $test->whatever = 'ok'; + try { $this->_em->flush(); } catch (OptimisticLockException $e) { @@ -68,7 +73,9 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testJoinedParentInsertSetsInitialVersionValue() { $test = new OptimisticJoinedParent(); + $test->name = 'parent'; + $this->_em->persist($test); $this->_em->flush(); @@ -83,7 +90,9 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testJoinedParentFailureThrowsException(OptimisticJoinedParent $parent) { $q = $this->_em->createQuery('SELECT t FROM Doctrine\Tests\ORM\Functional\Locking\OptimisticJoinedParent t WHERE t.id = :id'); + $q->setParameter('id', $parent->id); + $test = $q->getSingleResult(); // Manually update/increment the version so we can try and save the same @@ -93,6 +102,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase // Now lets change a property and try and save it again $test->name = 'WHATT???'; + try { $this->_em->flush(); } catch (OptimisticLockException $e) { @@ -106,6 +116,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase for ($i = 0; $i < 5; $i++) { $test->name = 'test' . $i; + $this->_em->persist($test); $this->_em->flush(); @@ -117,7 +128,9 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testStandardInsertSetsInitialVersionValue() { $test = new OptimisticStandard(); + $test->name = 'test'; + $this->_em->persist($test); $this->_em->flush(); @@ -133,7 +146,9 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testStandardFailureThrowsException(OptimisticStandard $entity) { $q = $this->_em->createQuery('SELECT t FROM Doctrine\Tests\ORM\Functional\Locking\OptimisticStandard t WHERE t.id = :id'); + $q->setParameter('id', $entity->id); + $test = $q->getSingleResult(); // Manually update/increment the version so we can try and save the same @@ -143,6 +158,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase // Now lets change a property and try and save it again $test->name = 'WHATT???'; + try { $this->_em->flush(); } catch (OptimisticLockException $e) { @@ -153,7 +169,9 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testLockWorksWithProxy() { $test = new OptimisticStandard(); + $test->name = 'test'; + $this->_em->persist($test); $this->_em->flush(); $this->_em->clear(); @@ -166,6 +184,7 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testOptimisticTimestampSetsDefaultValue() { $test = new OptimisticTimestamp(); + $test->name = 'Testing'; $this->assertNull($test->version, "Pre-Condition"); @@ -184,18 +203,22 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testOptimisticTimestampFailureThrowsException(OptimisticTimestamp $entity) { $q = $this->_em->createQuery('SELECT t FROM Doctrine\Tests\ORM\Functional\Locking\OptimisticTimestamp t WHERE t.id = :id'); + $q->setParameter('id', $entity->id); + $test = $q->getSingleResult(); $this->assertInstanceOf('DateTime', $test->version); // Manually increment the version datetime column $format = $this->_em->getConnection()->getDatabasePlatform()->getDateTimeFormatString(); + $this->_conn->executeQuery('UPDATE optimistic_timestamp SET version = ? WHERE id = ?', array(date($format, strtotime($test->version->format($format)) + 3600), $test->id)); // Try and update the record and it should throw an exception $caughtException = null; $test->name = 'Testing again'; + try { $this->_em->flush(); } catch (OptimisticLockException $e) { @@ -213,15 +236,19 @@ class OptimisticTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testOptimisticTimestampLockFailureThrowsException(OptimisticTimestamp $entity) { $q = $this->_em->createQuery('SELECT t FROM Doctrine\Tests\ORM\Functional\Locking\OptimisticTimestamp t WHERE t.id = :id'); + $q->setParameter('id', $entity->id); + $test = $q->getSingleResult(); $this->assertInstanceOf('DateTime', $test->version); // Try to lock the record with an older timestamp and it should throw an exception $caughtException = null; + try { $expectedVersionExpired = DateTime::createFromFormat('U', $test->version->getTimestamp()-3600); + $this->_em->lock($test, LockMode::OPTIMISTIC, $expectedVersionExpired); } catch (OptimisticLockException $e) { $caughtException = $e; @@ -294,7 +321,10 @@ class OptimisticStandard */ private $version; - function getVersion() {return $this->version;} + public function getVersion() + { + return $this->version; + } } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php index 79f37c1b0..d3d066b72 100644 --- a/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/NativeQueryTest.php @@ -7,13 +7,10 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\Query\ResultSetMappingBuilder; use Doctrine\ORM\Query\Parameter; - use Doctrine\Tests\Models\CMS\CmsUser; use Doctrine\Tests\Models\CMS\CmsPhonenumber; use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsEmail; -use Doctrine\Tests\Models\CMS\CmsArticle; -use Doctrine\Tests\Models\Company\CompanyFixContract; use Doctrine\Tests\Models\Company\CompanyEmployee; use Doctrine\Tests\Models\Company\CompanyPerson; @@ -85,7 +82,7 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $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'); + $rsm->addMetaResult('a', $this->platform->getSQLResultCasing('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); diff --git a/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php index 810271acf..580473476 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ResultCacheTest.php @@ -37,13 +37,14 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testResultCache() { $user = new CmsUser; + $user->name = 'Roman'; $user->username = 'romanb'; $user->status = 'dev'; + $this->_em->persist($user); $this->_em->flush(); - $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); $cache = new ArrayCache(); @@ -73,8 +74,8 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testSetResultCacheId() { $cache = new ArrayCache; - $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); + $query->setResultCacheDriver($cache); $query->setResultCacheId('testing_result_cache_id'); @@ -87,9 +88,9 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testUseResultCache() { - $cache = new \Doctrine\Common\Cache\ArrayCache(); - + $cache = new ArrayCache(); $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux'); + $query->useResultCache(true); $query->setResultCacheDriver($cache); $query->setResultCacheId('testing_result_cache_id'); @@ -105,10 +106,10 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase */ public function testUseResultCacheParams() { - $cache = new \Doctrine\Common\Cache\ArrayCache(); - + $cache = new ArrayCache(); $sqlCount = count($this->_sqlLoggerStack->queries); - $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux WHERE ux.id = ?1'); + $query = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux WHERE ux.id = ?1'); + $query->setParameter(1, 1); $query->setResultCacheDriver($cache); $query->useResultCache(true); @@ -131,16 +132,20 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase public function testNativeQueryResultCaching() { - $rsm = new \Doctrine\ORM\Query\ResultSetMapping(); - $rsm->addScalarResult('id', 'u'); - $query = $this->_em->createNativeQuery('select u.id FROM cms_users u WHERE u.id = ?', $rsm); - $query->setParameter(1, 10); - $cache = new ArrayCache(); + $rsm = new \Doctrine\ORM\Query\ResultSetMapping(); + + $rsm->addScalarResult('id', 'u', 'integer'); + + $query = $this->_em->createNativeQuery('select u.id FROM cms_users u WHERE u.id = ?', $rsm); + + $query->setParameter(1, 10); $query->setResultCacheDriver($cache)->useResultCache(true); $this->assertEquals(0, $this->getCacheSize($cache)); + $query->getResult(); + $this->assertEquals(1, $this->getCacheSize($cache)); return $query; diff --git a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php index dd76a93a8..831d0b564 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php @@ -10,15 +10,12 @@ use Doctrine\Common\Cache\ArrayCache; use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\Tests\Models\CMS\CmsUser; -use Doctrine\Tests\Models\CMS\CmsPhonenumber; use Doctrine\Tests\Models\CMS\CmsAddress; use Doctrine\Tests\Models\CMS\CmsGroup; use Doctrine\Tests\Models\CMS\CmsArticle; -use Doctrine\Tests\Models\CMS\CmsComment; use Doctrine\Tests\Models\Company\CompanyPerson; use Doctrine\Tests\Models\Company\CompanyManager; -use Doctrine\Tests\Models\Company\CompanyEmployee; use Doctrine\Tests\Models\Company\CompanyOrganization; use Doctrine\Tests\Models\Company\CompanyAuction; diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php index 7e9d4a651..d95605425 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1050Test.php @@ -12,7 +12,9 @@ class DDC1050Test extends \Doctrine\Tests\OrmFunctionalTestCase public function setUp() { $this->markTestSkipped('performance skipped'); + $this->useModelSet('cms'); + parent::setUp(); } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1655Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1655Test.php index 22b20e722..cb5023a86 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1655Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1655Test.php @@ -12,6 +12,7 @@ class DDC1655Test extends \Doctrine\Tests\OrmFunctionalTestCase public function setUp() { parent::setUp(); + try { $this->_schemaTool->createSchema(array( $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1655Foo'), @@ -19,7 +20,6 @@ class DDC1655Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1655Baz'), )); } catch(\Exception $e) { - } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1695Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1695Test.php index b1095d372..20cef6507 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1695Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1695Test.php @@ -29,7 +29,7 @@ class DDC1695Test extends \Doctrine\Tests\OrmFunctionalTestCase class DDC1695News { /** - * @var int $idNews + * @var int * * @Column(name="`IdNews`", type="integer", nullable=false) * @Id @@ -38,119 +38,119 @@ class DDC1695News private $idNews; /** - * @var bigint $iduser + * @var int * * @Column(name="`IdUser`", type="bigint", nullable=false) */ private $idUser; /** - * @var int $idLanguage + * @var int * * @Column(name="`IdLanguage`", type="integer", nullable=false) */ private $idLanguage; /** - * @var int $idCondition + * @var int * * @Column(name="`IdCondition`", type="integer", nullable=true) */ private $idCondition; /** - * @var int $idHealthProvider + * @var int * * @Column(name="`IdHealthProvider`", type="integer", nullable=true) */ private $idHealthProvider; /** - * @var int $idSpeciality + * @var int * * @Column(name="`IdSpeciality`", type="integer", nullable=true) */ private $idSpeciality; /** - * @var int $idMedicineType + * @var int * * @Column(name="`IdMedicineType`", type="integer", nullable=true) */ private $idMedicineType; /** - * @var int $idTreatment + * @var int * * @Column(name="`IdTreatment`", type="integer", nullable=true) */ private $idTreatment; /** - * @var string $title + * @var string * * @Column(name="`Title`", type="string", nullable=true) */ private $title; /** - * @var string $smallText + * @var string * * @Column(name="`SmallText`", type="string", nullable=true) */ private $smallText; /** - * @var string $longText + * @var string * * @Column(name="`LongText`", type="string", nullable=true) */ private $longText; /** - * @var datetimetz $publishDate + * @var DateTimeZone * * @Column(name="`PublishDate`", type="datetimetz", nullable=true) */ private $publishDate; /** - * @var tsvector $idxNews + * @var array * - * @Column(name="`IdxNews`", type="tsvector", nullable=true) + * @Column(name="`IdxNews`", type="json_array", nullable=true) */ private $idxNews; /** - * @var bool $highlight + * @var bool * * @Column(name="`Highlight`", type="boolean", nullable=false) */ private $highlight; /** - * @var int $order + * @var int * * @Column(name="`Order`", type="integer", nullable=false) */ private $order; /** - * @var bool $deleted + * @var bool * * @Column(name="`Deleted`", type="boolean", nullable=false) */ private $deleted; /** - * @var bool $active + * @var bool * * @Column(name="`Active`", type="boolean", nullable=false) */ private $active; /** - * @var bool $updateToHighlighted + * @var bool * * @Column(name="`UpdateToHighlighted`", type="boolean", nullable=true) */ diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php index 9749e31e1..679ab559c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3634Test.php @@ -18,7 +18,7 @@ class DDC3634Test extends OrmFunctionalTestCase { $metadata = $this->_em->getClassMetadata(DDC3634Entity::CLASSNAME); - if (! $metadata->idGenerator->isPostInsertGenerator()) { + if ( ! $metadata->idGenerator->isPostInsertGenerator()) { $this->markTestSkipped('Need a post-insert ID generator in order to make this test work correctly'); } diff --git a/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php index 9281048bc..0942a6051 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ArrayHydratorTest.php @@ -24,6 +24,7 @@ class ArrayHydratorTest extends HydrationTestCase public function testSimpleEntityQuery() { $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); @@ -45,7 +46,6 @@ class ArrayHydratorTest extends HydrationTestCase $result = $hydrator->hydrateAll($stmt, $rsm); $this->assertEquals(2, count($result)); - $this->assertTrue(is_array($result)); $this->assertEquals(1, $result[0]['id']); @@ -64,12 +64,12 @@ class ArrayHydratorTest extends HydrationTestCase public function testSimpleEntityWithScalarQuery($userEntityKey) { $alias = $userEntityKey ?: 'u'; + $rsm = new ResultSetMapping; - $rsm = new ResultSetMapping; $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', $alias); $rsm->addFieldResult($alias, 's__id', 'id'); $rsm->addFieldResult($alias, 's__name', 'name'); - $rsm->addScalarResult('sclr0', 'nameUpper'); + $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); // Faked result set $resultSet = array( @@ -90,7 +90,6 @@ class ArrayHydratorTest extends HydrationTestCase $result = $hydrator->hydrateAll($stmt, $rsm); $this->assertEquals(2, count($result)); - $this->assertTrue(is_array($result)); $this->assertArrayHasKey('nameUpper', $result[0]); @@ -117,6 +116,7 @@ class ArrayHydratorTest extends HydrationTestCase public function testSimpleEntityQueryWithAliasedUserEntity() { $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', 'user'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); @@ -138,7 +138,6 @@ class ArrayHydratorTest extends HydrationTestCase $result = $hydrator->hydrateAll($stmt, $rsm); $this->assertEquals(2, count($result)); - $this->assertTrue(is_array($result)); $this->assertArrayHasKey('user', $result[0]); @@ -157,6 +156,7 @@ class ArrayHydratorTest extends HydrationTestCase public function testSimpleMultipleRootEntityQuery() { $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsArticle', 'a'); $rsm->addFieldResult('u', 'u__id', 'id'); @@ -206,6 +206,7 @@ class ArrayHydratorTest extends HydrationTestCase public function testSimpleMultipleRootEntityQueryWithAliasedUserEntity() { $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', 'user'); $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsArticle', 'a'); $rsm->addFieldResult('u', 'u__id', 'id'); @@ -259,6 +260,7 @@ class ArrayHydratorTest extends HydrationTestCase public function testSimpleMultipleRootEntityQueryWithAliasedArticleEntity() { $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsArticle', 'a', 'article'); $rsm->addFieldResult('u', 'u__id', 'id'); @@ -312,6 +314,7 @@ class ArrayHydratorTest extends HydrationTestCase public function testSimpleMultipleRootEntityQueryWithAliasedEntities() { $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', 'user'); $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsArticle', 'a', 'article'); $rsm->addFieldResult('u', 'u__id', 'id'); @@ -369,10 +372,11 @@ class ArrayHydratorTest extends HydrationTestCase public function testMixedQueryNormalJoin($userEntityKey) { $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addScalarResult('sclr0', 'numPhones'); + $rsm->addScalarResult('sclr0', 'numPhones', 'integer'); // Faked result set $resultSet = array( @@ -417,6 +421,7 @@ class ArrayHydratorTest extends HydrationTestCase public function testMixedQueryFetchJoin($userEntityKey) { $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); $rsm->addJoinedEntityResult( 'Doctrine\Tests\Models\CMS\CmsPhonenumber', @@ -426,7 +431,7 @@ class ArrayHydratorTest extends HydrationTestCase ); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addScalarResult('sclr0', 'nameUpper'); + $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); // Faked result set @@ -487,6 +492,7 @@ class ArrayHydratorTest extends HydrationTestCase public function testMixedQueryFetchJoinCustomIndex($userEntityKey) { $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); $rsm->addJoinedEntityResult( 'Doctrine\Tests\Models\CMS\CmsPhonenumber', @@ -496,7 +502,7 @@ class ArrayHydratorTest extends HydrationTestCase ); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addScalarResult('sclr0', 'nameUpper'); + $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); $rsm->addIndexBy('u', 'id'); $rsm->addIndexBy('p', 'phonenumber'); @@ -565,6 +571,7 @@ class ArrayHydratorTest extends HydrationTestCase public function testMixedQueryMultipleFetchJoin() { $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addJoinedEntityResult( 'Doctrine\Tests\Models\CMS\CmsPhonenumber', @@ -580,7 +587,7 @@ class ArrayHydratorTest extends HydrationTestCase ); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addScalarResult('sclr0', 'nameUpper'); + $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); $rsm->addFieldResult('a', 'a__id', 'id'); $rsm->addFieldResult('a', 'a__topic', 'topic'); @@ -682,8 +689,8 @@ class ArrayHydratorTest extends HydrationTestCase */ public function testMixedQueryMultipleDeepMixedFetchJoin() { - $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addJoinedEntityResult( 'Doctrine\Tests\Models\CMS\CmsPhonenumber', @@ -705,7 +712,7 @@ class ArrayHydratorTest extends HydrationTestCase ); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addScalarResult('sclr0', 'nameUpper'); + $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); $rsm->addFieldResult('a', 'a__id', 'id'); $rsm->addFieldResult('a', 'a__topic', 'topic'); @@ -840,6 +847,7 @@ class ArrayHydratorTest extends HydrationTestCase public function testEntityQueryCustomResultSetOrder() { $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\Forum\ForumCategory', 'c'); $rsm->addJoinedEntityResult( 'Doctrine\Tests\Models\Forum\ForumBoard', @@ -915,13 +923,14 @@ class ArrayHydratorTest extends HydrationTestCase public function testChainedJoinWithScalars($entityKey) { $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $entityKey ?: null); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addScalarResult('a__id', 'id'); - $rsm->addScalarResult('a__topic', 'topic'); - $rsm->addScalarResult('c__id', 'cid'); - $rsm->addScalarResult('c__topic', 'ctopic'); + $rsm->addScalarResult('a__id', 'id', 'integer'); + $rsm->addScalarResult('a__topic', 'topic', 'string'); + $rsm->addScalarResult('c__id', 'cid', 'integer'); + $rsm->addScalarResult('c__topic', 'ctopic', 'string'); // Faked result set $resultSet = array( @@ -984,6 +993,7 @@ class ArrayHydratorTest extends HydrationTestCase public function testResultIteration() { $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); @@ -1028,6 +1038,7 @@ class ArrayHydratorTest extends HydrationTestCase public function testResultIterationWithAliasedUserEntity() { $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', 'user'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); @@ -1075,6 +1086,7 @@ class ArrayHydratorTest extends HydrationTestCase public function testSkipUnknownColumns() { $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); @@ -1108,10 +1120,11 @@ class ArrayHydratorTest extends HydrationTestCase public function testMissingIdForRootEntity($userEntityKey) { $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addScalarResult('sclr0', 'nameUpper'); + $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); // Faked result set $resultSet = array( @@ -1166,10 +1179,11 @@ class ArrayHydratorTest extends HydrationTestCase public function testIndexByAndMixedResult($userEntityKey) { $rsm = new ResultSetMapping; + $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addScalarResult('sclr0', 'nameUpper'); + $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); $rsm->addIndexBy('u', 'id'); // Faked result set diff --git a/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php index b3d309090..ff77312aa 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ObjectHydratorTest.php @@ -373,7 +373,7 @@ class ObjectHydratorTest extends HydrationTestCase $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addScalarResult('sclr0', 'numPhones'); + $rsm->addScalarResult('sclr0', 'numPhones', 'integer'); // Faked result set $resultSet = array( @@ -429,7 +429,7 @@ class ObjectHydratorTest extends HydrationTestCase $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); - $rsm->addScalarResult('sclr0', 'nameUpper'); + $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); // Faked result set $resultSet = array( @@ -506,7 +506,7 @@ class ObjectHydratorTest extends HydrationTestCase ); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addScalarResult('sclr0', 'nameUpper'); + $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); $rsm->addIndexBy('u', 'id'); $rsm->addIndexBy('p', 'phonenumber'); @@ -591,7 +591,7 @@ class ObjectHydratorTest extends HydrationTestCase ); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addScalarResult('sclr0', 'nameUpper'); + $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); $rsm->addFieldResult('a', 'a__id', 'id'); $rsm->addFieldResult('a', 'a__topic', 'topic'); @@ -707,7 +707,7 @@ class ObjectHydratorTest extends HydrationTestCase ); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addScalarResult('sclr0', 'nameUpper'); + $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); $rsm->addFieldResult('a', 'a__id', 'id'); $rsm->addFieldResult('a', 'a__topic', 'topic'); @@ -953,8 +953,8 @@ class ObjectHydratorTest extends HydrationTestCase { $rsm = new ResultSetMapping; $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); - $rsm->addScalarResult('sclr0', 'id'); - $rsm->addScalarResult('sclr1', 'name'); + $rsm->addScalarResult('sclr0', 'id', 'integer'); + $rsm->addScalarResult('sclr1', 'name', 'string'); // Faked result set $resultSet = array( @@ -994,7 +994,7 @@ class ObjectHydratorTest extends HydrationTestCase $rsm->addEntityResult('Doctrine\Tests\Models\ECommerce\ECommerceProduct', 'p'); $rsm->addFieldResult('p', 'p__id', 'id'); $rsm->addFieldResult('p', 'p__name', 'name'); - $rsm->addMetaResult('p', 'p__shipping_id', 'shipping_id'); + $rsm->addMetaResult('p', 'p__shipping_id', 'shipping_id', false, 'integer'); // Faked result set $resultSet = array( @@ -1039,7 +1039,7 @@ class ObjectHydratorTest extends HydrationTestCase $rsm->addEntityResult('Doctrine\Tests\Models\ECommerce\ECommerceProduct', 'p', 'product'); $rsm->addFieldResult('p', 'p__id', 'id'); $rsm->addFieldResult('p', 'p__name', 'name'); - $rsm->addMetaResult('p', 'p__shipping_id', 'shipping_id'); + $rsm->addMetaResult('p', 'p__shipping_id', 'shipping_id', false, 'integer'); // Faked result set $resultSet = array( @@ -1620,7 +1620,7 @@ class ObjectHydratorTest extends HydrationTestCase $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addScalarResult('sclr0', 'nameUpper'); + $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); // Faked result set $resultSet = array( @@ -1685,7 +1685,7 @@ class ObjectHydratorTest extends HydrationTestCase ); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addScalarResult('sclr0', 'nameUpper'); + $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); // Faked result set @@ -1747,10 +1747,10 @@ class ObjectHydratorTest extends HydrationTestCase ); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addScalarResult('sclr0', 'nameUpper'); + $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); $rsm->addFieldResult('a', 'a__id', 'id'); $rsm->addFieldResult('a', 'a__city', 'city'); - $rsm->addMetaResult('a', 'user_id', 'user_id'); + $rsm->addMetaResult('a', 'user_id', 'user_id', false, 'string'); // Faked result set $resultSet = array( @@ -1795,7 +1795,7 @@ class ObjectHydratorTest extends HydrationTestCase $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__status', 'status'); - $rsm->addScalarResult('sclr0', 'nameUpper'); + $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); $rsm->addIndexBy('u', 'id'); // Faked result set @@ -1837,7 +1837,7 @@ class ObjectHydratorTest extends HydrationTestCase { $rsm = new ResultSetMapping; $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u', $userEntityKey ?: null); - $rsm->addScalarResult('sclr0', 'nameUpper'); + $rsm->addScalarResult('sclr0', 'nameUpper', 'string'); $rsm->addIndexByScalar('sclr0'); // Faked result set @@ -1877,7 +1877,6 @@ class ObjectHydratorTest extends HydrationTestCase $rsm->addEntityResult('Doctrine\Tests\Models\Company\CompanyFixContract', 'c'); $rsm->addJoinedEntityResult('Doctrine\Tests\Models\Company\CompanyEmployee', 'e', 'c', 'salesPerson'); - $rsm->addFieldResult('c', 'c__id', 'id'); $rsm->setDiscriminatorColumn('c', 'c_discr'); @@ -1905,14 +1904,12 @@ class ObjectHydratorTest extends HydrationTestCase $rsm->addEntityResult('Doctrine\Tests\Models\Company\CompanyFixContract', 'c'); $rsm->addJoinedEntityResult('Doctrine\Tests\Models\Company\CompanyEmployee', 'e', 'c', 'salesPerson'); - $rsm->addFieldResult('c', 'c__id', 'id'); - $rsm->addMetaResult('c', 'c_discr', 'discr'); + $rsm->addMetaResult('c', 'c_discr', 'discr', false, 'string'); $rsm->setDiscriminatorColumn('c', 'c_discr'); - $rsm->addFieldResult('e', 'e__id', 'id'); $rsm->addFieldResult('e', 'e__name', 'name'); - $rsm->addMetaResult('e ', 'e_discr', 'discr'); + $rsm->addMetaResult('e ', 'e_discr', 'discr', false, 'string'); $rsm->setDiscriminatorColumn('e', 'e_discr'); $resultSet = array( @@ -1940,10 +1937,9 @@ class ObjectHydratorTest extends HydrationTestCase $rsm = new ResultSetMapping; $rsm->addEntityResult('Doctrine\Tests\Models\Company\CompanyPerson', 'p'); - $rsm->addFieldResult('p', 'p__id', 'id'); $rsm->addFieldResult('p', 'p__name', 'name'); - $rsm->addMetaResult('p', 'discr', 'discr'); + $rsm->addMetaResult('p', 'discr', 'discr', false, 'string'); $rsm->setDiscriminatorColumn('p', 'discr'); $resultSet = array( @@ -1968,14 +1964,16 @@ class ObjectHydratorTest extends HydrationTestCase $rsm->addFieldResult('e1', 'a1__id', 'id'); $rsm->addFieldResult('e2', 'e2__id', 'id'); - $result = (new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em)) - ->hydrateAll( - new HydratorMockStatement([[ - 'a1__id' => '1', - 'e2__id' => '1', - ]]), - $rsm - ); + $resultSet = array( + array( + 'a1__id' => '1', + 'e2__id' => '1', + ) + ); + + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); + $result = $hydrator->hydrateAll($stmt, $rsm); $this->assertCount(1, $result); $this->assertInstanceOf(EntityWithArrayDefaultArrayValueM2M::CLASSNAME, $result[0]); diff --git a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php index 079381d4f..2ce9ae789 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ResultSetMappingTest.php @@ -71,17 +71,16 @@ class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase { $rms = $this->_rsm; - $rms->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser','u') - ->addJoinedEntityResult('Doctrine\Tests\Models\CMS\CmsPhonenumber','p','u','phonenumbers') - ->addFieldResult('u', 'id', 'id') - ->addFieldResult('u', 'name', 'name') - ->setDiscriminatorColumn('name', 'name') - ->addIndexByColumn('id', 'id') - ->addIndexBy('username', 'username') - ->addIndexByScalar('sclr0') - ->addScalarResult('sclr0', 'numPhones') - ->addMetaResult('a', 'user_id', 'user_id'); - + $this->_rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser','u'); + $this->_rsm->addJoinedEntityResult('Doctrine\Tests\Models\CMS\CmsPhonenumber','p','u','phonenumbers'); + $this->_rsm->addFieldResult('u', 'id', 'id'); + $this->_rsm->addFieldResult('u', 'name', 'name'); + $this->_rsm->setDiscriminatorColumn('name', 'name'); + $this->_rsm->addIndexByColumn('id', 'id'); + $this->_rsm->addIndexBy('username', 'username'); + $this->_rsm->addIndexByScalar('sclr0'); + $this->_rsm->addScalarResult('sclr0', 'numPhones'); + $this->_rsm->addMetaResult('a', 'user_id', 'user_id'); $this->assertTrue($rms->hasIndexBy('id')); $this->assertTrue($rms->isFieldResult('id')); @@ -118,6 +117,7 @@ class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase 'query' => 'SELECT u.id AS user_id, e.id AS email_id, u.name, e.email, u.id + e.id AS scalarColumn FROM cms_users u INNER JOIN cms_emails e ON e.id = u.email_id', 'resultSetMapping' => 'find-all', )); + $cm->addSqlResultSetMapping(array( 'name' => 'find-all', 'entities' => array( @@ -155,7 +155,6 @@ class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase ) )); - $queryMapping = $cm->getNamedNativeQuery('find-all'); $rsm = new \Doctrine\ORM\Query\ResultSetMappingBuilder($this->_em); @@ -190,6 +189,7 @@ class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase 'query' => 'SELECT u.id AS user_id, e.id AS email_id, u.name, e.email, u.id + e.id AS scalarColumn FROM cms_users u INNER JOIN cms_emails e ON e.id = u.email_id', 'resultSetMapping' => 'find-all', )); + $cm->addSqlResultSetMapping(array( 'name' => 'find-all', 'entities' => array( @@ -204,14 +204,12 @@ class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase ) )); - $queryMapping = $cm->getNamedNativeQuery('find-all'); + $rsm = new \Doctrine\ORM\Query\ResultSetMappingBuilder($this->_em); - $rsm = new \Doctrine\ORM\Query\ResultSetMappingBuilder($this->_em); $rsm->addNamedNativeQueryMapping($cm, $queryMapping); $this->assertEquals('scalarColumn', $rsm->getScalarAlias('scalarColumn')); - $this->assertEquals('c0', $rsm->getEntityAlias('id')); $this->assertEquals('c0', $rsm->getEntityAlias('name')); $this->assertEquals('c0', $rsm->getEntityAlias('status')); @@ -229,6 +227,7 @@ class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase public function testAddNamedNativeQueryResultClass() { $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); $cm->addNamedNativeQuery(array( @@ -238,11 +237,10 @@ class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase )); $queryMapping = $cm->getNamedNativeQuery('find-all'); + $rsm = new \Doctrine\ORM\Query\ResultSetMappingBuilder($this->_em); - $rsm = new \Doctrine\ORM\Query\ResultSetMappingBuilder($this->_em); $rsm->addNamedNativeQueryMapping($cm, $queryMapping); - $this->assertEquals('c0', $rsm->getEntityAlias('id')); $this->assertEquals('c0', $rsm->getEntityAlias('name')); $this->assertEquals('c0', $rsm->getEntityAlias('status')); @@ -259,9 +257,9 @@ class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase public function testIndexByMetadataColumn() { $this->_rsm->addEntityResult('Doctrine\Tests\Models\Legacy\LegacyUser', 'u'); - $this->_rsm->addJoinedEntityResult('Doctrine\Tests\Models\Legacy', 'lu', 'u', '_references'); - $this->_rsm->addMetaResult('lu', '_source', '_source', true); - $this->_rsm->addMetaResult('lu', '_target', '_target', true); + $this->_rsm->addJoinedEntityResult('Doctrine\Tests\Models\LegacyUserReference', 'lu', 'u', '_references'); + $this->_rsm->addMetaResult('lu', '_source', '_source', true, 'integer'); + $this->_rsm->addMetaResult('lu', '_target', '_target', true, 'integer'); $this->_rsm->addIndexBy('lu', '_source'); $this->assertTrue($this->_rsm->hasIndexBy('lu')); diff --git a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php index 83e3c3c19..5c5f55f40 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php @@ -49,9 +49,9 @@ class ScalarHydratorTest extends HydrationTestCase public function testHydrateScalarResults() { $rsm = new ResultSetMapping(); - $rsm->addScalarResult('foo1', 'foo'); - $rsm->addScalarResult('bar2', 'bar'); - $rsm->addScalarResult('baz3', 'baz'); + $rsm->addScalarResult('foo1', 'foo', 'string'); + $rsm->addScalarResult('bar2', 'bar', 'string'); + $rsm->addScalarResult('baz3', 'baz', 'string'); $resultSet = array( array( @@ -76,9 +76,9 @@ class ScalarHydratorTest extends HydrationTestCase $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__name', 'name'); - $rsm->addScalarResult('foo1', 'foo'); - $rsm->addScalarResult('bar2', 'bar'); - $rsm->addScalarResult('baz3', 'baz'); + $rsm->addScalarResult('foo1', 'foo', 'string'); + $rsm->addScalarResult('bar2', 'bar', 'string'); + $rsm->addScalarResult('baz3', 'baz', 'string'); $resultSet = array( array( diff --git a/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php index 459ce9ba1..eb33c23c2 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/SimpleObjectHydratorTest.php @@ -19,7 +19,7 @@ class SimpleObjectHydratorTest extends HydrationTestCase $rsm->addEntityResult('Doctrine\Tests\Models\Company\CompanyPerson', 'p'); $rsm->addFieldResult('p', 'p__id', 'id'); $rsm->addFieldResult('p', 'p__name', 'name'); - $rsm->addMetaResult('p ', 'discr', 'discr'); + $rsm->addMetaResult('p ', 'discr', 'discr', false, 'string'); $rsm->setDiscriminatorColumn('p', 'discr'); $resultSet = array( array( @@ -71,7 +71,7 @@ class SimpleObjectHydratorTest extends HydrationTestCase $rsm->addFieldResult('p', 'p__id', 'id'); $rsm->addFieldResult('p', 'p__name', 'name'); - $rsm->addMetaResult('p', 'discr', 'discr'); + $rsm->addMetaResult('p', 'discr', 'discr', false, 'string'); $rsm->setDiscriminatorColumn('p', 'discr'); $resultSet = array( diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 19d148b98..874f9416b 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -491,8 +491,8 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase $class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType'); - $this->assertEquals('ID', $class->columnNames['id']); - $this->assertEquals('NAME', $class->columnNames['name']); + $this->assertEquals('ID', $class->getColumnName('id')); + $this->assertEquals('NAME', $class->getColumnName('name')); $this->assertEquals('DDC1476ENTITY_WITH_DEFAULT_FIELD_TYPE', $class->table['name']); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php index 855ff818e..686e8bfff 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php @@ -254,7 +254,7 @@ class ClassMetadataFactoryTest extends \Doctrine\Tests\OrmTestCase $cm1->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); $cm1->setPrimaryTable(array('name' => '`group`')); // Add a mapped field - $cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar')); + $cm1->mapField(array('fieldName' => 'name', 'type' => 'string')); // Add a mapped field $cm1->mapField(array('fieldName' => 'id', 'type' => 'integer', 'id' => true)); // and a mapped association diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsAddress.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsAddress.php index 24739a50c..b0ac6cade 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsAddress.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsAddress.php @@ -1,7 +1,5 @@ setPrimaryTable(array( 'name' => 'company_person', )); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsUser.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsUser.php index 9484bf750..dfa89851a 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsUser.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.CMS.CmsUser.php @@ -1,7 +1,5 @@ setPrimaryTable(array( 'name' => 'cms_users', )); diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyContract.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyContract.php index fdb8d5d02..d307ba7f1 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyContract.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyContract.php @@ -2,7 +2,7 @@ use Doctrine\ORM\Mapping\ClassMetadataInfo; -$metadata->setInheritanceType(\Doctrine\ORM\Mapping\ClassMetadata::INHERITANCE_TYPE_JOINED); +$metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_JOINED); $metadata->setTableName( 'company_contracts'); $metadata->setDiscriminatorColumn(array( 'name' => 'discr', diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyPerson.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyPerson.php index 68703f40a..32cc813da 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyPerson.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.Models.Company.CompanyPerson.php @@ -1,7 +1,5 @@ setPrimaryTable(array( 'name' => 'company_person', )); diff --git a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php index e77f898d1..5b1ffce62 100644 --- a/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php +++ b/tests/Doctrine/Tests/ORM/PersistentCollectionTest.php @@ -9,6 +9,7 @@ use Doctrine\Tests\Mocks\ConnectionMock; use Doctrine\Tests\Mocks\DriverMock; use Doctrine\Tests\Mocks\EntityManagerMock; use Doctrine\Tests\Models\ECommerce\ECommerceCart; +use Doctrine\Tests\Models\ECommerce\ECommerceProduct; use Doctrine\Tests\OrmTestCase; /** @@ -83,4 +84,28 @@ class PersistentCollectionTest extends OrmTestCase $this->collection->next(); $this->assertTrue($this->collection->isInitialized()); } + + /** + * @group DDC-3382 + */ + public function testNonObjects() + { + $this->setUpPersistentCollection(); + + $this->assertEmpty($this->collection); + + $this->collection->add("dummy"); + + $this->assertNotEmpty($this->collection); + + $product = new ECommerceProduct(); + + $this->collection->set(1, $product); + $this->collection->set(2, "dummy"); + $this->collection->set(3, null); + + $this->assertSame($product, $this->collection->get(1)); + $this->assertSame("dummy", $this->collection->get(2)); + $this->assertSame(null, $this->collection->get(3)); + } } diff --git a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php index dd058f050..d51e40555 100644 --- a/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php +++ b/tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php @@ -92,7 +92,7 @@ class BasicEntityPersisterTypeValueSqlTest extends \Doctrine\Tests\OrmTestCase */ public function testStripNonAlphanumericCharactersFromSelectColumnListSQL() { - $persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\DDC1719SimpleEntity')); + $persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata('Doctrine\Tests\Models\Generic\NonAlphaColumnsEntity')); $method = new \ReflectionMethod($persister, 'getSelectColumnsSQL'); $method->setAccessible(true); @@ -143,16 +143,16 @@ class BasicEntityPersisterTypeValueSqlTest extends \Doctrine\Tests\OrmTestCase public function testCountCondition() { - $persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata('Doctrine\Tests\ORM\Functional\Ticket\DDC1719SimpleEntity')); + $persister = new BasicEntityPersister($this->_em, $this->_em->getClassMetadata('Doctrine\Tests\Models\Generic\NonAlphaColumnsEntity')); // Using a criteria as array $statement = $persister->getCountSQL(array('value' => 'bar')); - $this->assertEquals('SELECT COUNT(*) FROM "ddc-1719-simple-entity" t0 WHERE t0."simple-entity-value" = ?', $statement); + $this->assertEquals('SELECT COUNT(*) FROM "not-a-simple-entity" t0 WHERE t0."simple-entity-value" = ?', $statement); // Using a criteria object $criteria = new Criteria(Criteria::expr()->eq('value', 'bar')); $statement = $persister->getCountSQL($criteria); - $this->assertEquals('SELECT COUNT(*) FROM "ddc-1719-simple-entity" t0 WHERE t0."simple-entity-value" = ?', $statement); + $this->assertEquals('SELECT COUNT(*) FROM "not-a-simple-entity" t0 WHERE t0."simple-entity-value" = ?', $statement); } public function testCountEntities() diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 982d149ea..0eb7b3bbe 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -1889,18 +1889,18 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase public function testStripNonAlphanumericCharactersFromAlias() { $this->assertSqlGeneration( - 'SELECT e FROM Doctrine\Tests\ORM\Functional\Ticket\DDC1719SimpleEntity e', - 'SELECT d0_."simple-entity-id" AS simpleentityid_0, d0_."simple-entity-value" AS simpleentityvalue_1 FROM "ddc-1719-simple-entity" d0_' + 'SELECT e FROM Doctrine\Tests\Models\Generic\NonAlphaColumnsEntity e', + 'SELECT n0_."simple-entity-id" AS simpleentityid_0, n0_."simple-entity-value" AS simpleentityvalue_1 FROM "not-a-simple-entity" n0_' ); $this->assertSqlGeneration( - 'SELECT e.value FROM Doctrine\Tests\ORM\Functional\Ticket\DDC1719SimpleEntity e ORDER BY e.value', - 'SELECT d0_."simple-entity-value" AS simpleentityvalue_0 FROM "ddc-1719-simple-entity" d0_ ORDER BY d0_."simple-entity-value" ASC' + 'SELECT e.value FROM Doctrine\Tests\Models\Generic\NonAlphaColumnsEntity e ORDER BY e.value', + 'SELECT n0_."simple-entity-value" AS simpleentityvalue_0 FROM "not-a-simple-entity" n0_ ORDER BY n0_."simple-entity-value" ASC' ); $this->assertSqlGeneration( - 'SELECT TRIM(e.value) FROM Doctrine\Tests\ORM\Functional\Ticket\DDC1719SimpleEntity e ORDER BY e.value', - 'SELECT TRIM(d0_."simple-entity-value") AS sclr_0 FROM "ddc-1719-simple-entity" d0_ ORDER BY d0_."simple-entity-value" ASC' + 'SELECT TRIM(e.value) FROM Doctrine\Tests\Models\Generic\NonAlphaColumnsEntity e ORDER BY e.value', + 'SELECT TRIM(n0_."simple-entity-value") AS sclr_0 FROM "not-a-simple-entity" n0_ ORDER BY n0_."simple-entity-value" ASC' ); } diff --git a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php index 841e8211b..935ecce78 100644 --- a/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/EntityGeneratorTest.php @@ -4,7 +4,6 @@ namespace Doctrine\Tests\ORM\Tools; use Doctrine\Common\Annotations\AnnotationReader; use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService; -use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ClassMetadataFactory; use Doctrine\ORM\Mapping\ClassMetadataInfo; use Doctrine\ORM\Mapping\Driver\AnnotationDriver; @@ -408,7 +407,7 @@ class EntityGeneratorTest extends OrmTestCase $reflectionService = new RuntimeReflectionService(); - $cm = new ClassMetadata($metadata->name); + $cm = new ClassMetadataInfo($metadata->name); $cm->initializeReflection($reflectionService); $driver = $this->createAnnotationDriver(); @@ -427,7 +426,7 @@ class EntityGeneratorTest extends OrmTestCase $isbn = $this->newInstance($embeddedMetadata); - $cm = new ClassMetadata($embeddedMetadata->name); + $cm = new ClassMetadataInfo($embeddedMetadata->name); $cm->initializeReflection($reflectionService); $driver->loadMetadataForClass($cm->name, $cm); @@ -450,7 +449,7 @@ class EntityGeneratorTest extends OrmTestCase $reflectionService = new RuntimeReflectionService(); - $cm = new ClassMetadata($metadata->name); + $cm = new ClassMetadataInfo($metadata->name); $cm->initializeReflection($reflectionService); $driver->loadMetadataForClass($cm->name, $cm); @@ -464,7 +463,7 @@ class EntityGeneratorTest extends OrmTestCase $isbn = $this->newInstance($embeddedMetadata); - $cm = new ClassMetadata($embeddedMetadata->name); + $cm = new ClassMetadataInfo($embeddedMetadata->name); $cm->initializeReflection($reflectionService); $driver->loadMetadataForClass($cm->name, $cm); @@ -488,7 +487,7 @@ class EntityGeneratorTest extends OrmTestCase $this->newInstance($metadata); // force instantiation (causes autoloading to kick in) $driver = new AnnotationDriver(new AnnotationReader(), array()); - $cm = new ClassMetadata($metadata->name); + $cm = new ClassMetadataInfo($metadata->name); $cm->initializeReflection(new RuntimeReflectionService); $driver->loadMetadataForClass($cm->name, $cm); @@ -593,7 +592,7 @@ class EntityGeneratorTest extends OrmTestCase */ public function testGetInheritanceTypeString() { - $reflection = new \ReflectionClass('\Doctrine\ORM\Mapping\ClassMetadata'); + $reflection = new \ReflectionClass('\Doctrine\ORM\Mapping\ClassMetadataInfo'); $method = new \ReflectionMethod($this->_generator, 'getInheritanceTypeString'); $constants = $reflection->getConstants(); $pattern = '/^INHERITANCE_TYPE_/'; @@ -647,7 +646,7 @@ class EntityGeneratorTest extends OrmTestCase */ public function testGetIdGeneratorTypeString() { - $reflection = new \ReflectionClass('\Doctrine\ORM\Mapping\ClassMetadata'); + $reflection = new \ReflectionClass('\Doctrine\ORM\Mapping\ClassMetadataInfo'); $method = new \ReflectionMethod($this->_generator, 'getIdGeneratorTypeString'); $constants = $reflection->getConstants(); $pattern = '/^GENERATOR_TYPE_/'; diff --git a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php index 7c3c33c6a..2cb6fe605 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Export/AbstractClassMetadataExporterTest.php @@ -71,25 +71,25 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest 'xml' => 'Doctrine\ORM\Mapping\Driver\XmlDriver', 'yaml' => 'Doctrine\ORM\Mapping\Driver\YamlDriver', ); - $this->assertArrayHasKey($type, $mappingDriver, "There is no metadata driver for the type '" . $type . "'."); - $class = $mappingDriver[$type]; - if ($type === 'annotation') { - $driver = $this->createAnnotationDriver(array($path)); - } else { - $driver = new $class($path); - } + $this->assertArrayHasKey($type, $mappingDriver, "There is no metadata driver for the type '" . $type . "'."); + + $class = $mappingDriver[$type]; + $driver = ($type === 'annotation') + ? $this->createAnnotationDriver(array($path)) + : new $class($path); + return $driver; } protected function _createClassMetadataFactory($em, $type) { - if ($type === 'annotation') { - $factory = new ClassMetadataFactory(); - } else { - $factory = new DisconnectedClassMetadataFactory(); - } + $factory = ($type === 'annotation') + ? new ClassMetadataFactory() + : new DisconnectedClassMetadataFactory(); + $factory->setEntityManager($em); + return $factory; } @@ -110,11 +110,14 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest $type = $this->_getType(); $cme = new ClassMetadataExporter(); $exporter = $cme->getExporter($type, __DIR__ . '/export/' . $type); + if ($type === 'annotation') { $entityGenerator = new EntityGenerator(); + $entityGenerator->setAnnotationPrefix(""); $exporter->setEntityGenerator($entityGenerator); } + $this->_extension = $exporter->getExtension(); $exporter->setMetadata($metadata); @@ -215,6 +218,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest public function testFieldsAreProperlySerialized() { $type = $this->_getType(); + if ($type == 'xml') { $xml = simplexml_load_file(__DIR__ . '/export/'.$type.'/Doctrine.Tests.ORM.Tools.Export.ExportedUser.dcm.xml'); @@ -224,8 +228,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest $nodes = $xml->xpath("/d:doctrine-mapping/d:entity/d:field[@name='name' and @type='string' and @unique='true']"); $this->assertEquals(1, count($nodes)); - } - else { + } else { $this->markTestSkipped('Test not available for '.$type.' driver'); } } @@ -361,6 +364,7 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest public function testCascadeAllCollapsed() { $type = $this->_getType(); + if ($type == 'xml') { $xml = simplexml_load_file(__DIR__ . '/export/'.$type.'/Doctrine.Tests.ORM.Tools.Export.ExportedUser.dcm.xml'); @@ -369,19 +373,18 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest $this->assertEquals(1, count($nodes)); $this->assertEquals('cascade-all', $nodes[0]->getName()); - } elseif ($type == 'yaml') { - + } else if ($type == 'yaml') { $yaml = new \Symfony\Component\Yaml\Parser(); $value = $yaml->parse(file_get_contents(__DIR__ . '/export/'.$type.'/Doctrine.Tests.ORM.Tools.Export.ExportedUser.dcm.yml')); $this->assertTrue(isset($value['Doctrine\Tests\ORM\Tools\Export\ExportedUser']['oneToMany']['interests']['cascade'])); $this->assertEquals(1, count($value['Doctrine\Tests\ORM\Tools\Export\ExportedUser']['oneToMany']['interests']['cascade'])); $this->assertEquals('all', $value['Doctrine\Tests\ORM\Tools\Export\ExportedUser']['oneToMany']['interests']['cascade'][0]); - } else { $this->markTestSkipped('Test not available for '.$type.' driver'); } } + public function __destruct() { # $this->_deleteDirectory(__DIR__ . '/export/'.$this->_getType()); @@ -393,11 +396,13 @@ abstract class AbstractClassMetadataExporterTest extends \Doctrine\Tests\OrmTest return unlink($path); } else if (is_dir($path)) { $files = glob(rtrim($path,'/').'/*'); + if (is_array($files)) { foreach ($files as $file){ $this->_deleteDirectory($file); } } + return rmdir($path); } } diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 855fac617..2d7ed2b6c 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -299,7 +299,13 @@ abstract class OrmFunctionalTestCase extends OrmTestCase */ protected function tearDown() { - $conn = static::$_sharedConn; + $conn = static::$_sharedConn; + + // In case test is skipped, tearDown is called, but no setup may have run + if ( ! $conn) { + return; + } + $platform = $conn->getDatabasePlatform(); $this->_sqlLoggerStack->enabled = false; diff --git a/tests/Doctrine/Tests/OrmTestCase.php b/tests/Doctrine/Tests/OrmTestCase.php index c75555d96..7cc9c0580 100644 --- a/tests/Doctrine/Tests/OrmTestCase.php +++ b/tests/Doctrine/Tests/OrmTestCase.php @@ -2,7 +2,9 @@ namespace Doctrine\Tests; +use Doctrine\Common\Annotations; use Doctrine\Common\Cache\ArrayCache; +use Doctrine\Common\Version; use Doctrine\ORM\Cache\DefaultCacheFactory; /** @@ -57,40 +59,41 @@ abstract class OrmTestCase extends DoctrineTestCase */ protected function createAnnotationDriver($paths = array(), $alias = null) { - if (version_compare(\Doctrine\Common\Version::VERSION, '3.0.0', '>=')) { - $reader = new \Doctrine\Common\Annotations\CachedReader( - new \Doctrine\Common\Annotations\AnnotationReader(), new ArrayCache() - ); - } - else if (version_compare(\Doctrine\Common\Version::VERSION, '2.2.0-DEV', '>=')) { + if (version_compare(Version::VERSION, '3.0.0', '>=')) { + $reader = new Annotations\CachedReader(new Annotations\AnnotationReader(), new ArrayCache()); + } else if (version_compare(Version::VERSION, '2.2.0-DEV', '>=')) { // Register the ORM Annotations in the AnnotationRegistry - $reader = new \Doctrine\Common\Annotations\SimpleAnnotationReader(); + $reader = new Annotations\SimpleAnnotationReader(); + $reader->addNamespace('Doctrine\ORM\Mapping'); - $reader = new \Doctrine\Common\Annotations\CachedReader($reader, new ArrayCache()); - } - else if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-BETA3-DEV', '>=')) { - $reader = new \Doctrine\Common\Annotations\AnnotationReader(); + + $reader = new Annotations\CachedReader($reader, new ArrayCache()); + } else if (version_compare(Version::VERSION, '2.1.0-BETA3-DEV', '>=')) { + $reader = new Annotations\AnnotationReader(); + $reader->setIgnoreNotImportedAnnotations(true); $reader->setEnableParsePhpImports(false); + if ($alias) { $reader->setAnnotationNamespaceAlias('Doctrine\ORM\Mapping\\', $alias); } else { $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\'); } - $reader = new \Doctrine\Common\Annotations\CachedReader( - new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache() - ); + + $reader = new Annotations\CachedReader(new Annotations\IndexedReader($reader), new ArrayCache()); } else { - $reader = new \Doctrine\Common\Annotations\AnnotationReader(); + $reader = new Annotations\AnnotationReader(); + if ($alias) { $reader->setAnnotationNamespaceAlias('Doctrine\ORM\Mapping\\', $alias); } else { $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\'); } } - \Doctrine\Common\Annotations\AnnotationRegistry::registerFile( - __DIR__ . "/../../../lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php"); - return new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, (array)$paths); + + Annotations\AnnotationRegistry::registerFile(__DIR__ . "/../../../lib/Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php"); + + return new \Doctrine\ORM\Mapping\Driver\AnnotationDriver($reader, (array) $paths); } /** @@ -112,7 +115,7 @@ abstract class OrmTestCase extends DoctrineTestCase { $metadataCache = $withSharedMetadata ? self::getSharedMetadataCacheImpl() - : new \Doctrine\Common\Cache\ArrayCache; + : new ArrayCache(); $config = new \Doctrine\ORM\Configuration(); @@ -166,7 +169,7 @@ abstract class OrmTestCase extends DoctrineTestCase private static function getSharedMetadataCacheImpl() { if (self::$_metadataCacheImpl === null) { - self::$_metadataCacheImpl = new \Doctrine\Common\Cache\ArrayCache; + self::$_metadataCacheImpl = new ArrayCache(); } return self::$_metadataCacheImpl; @@ -178,7 +181,7 @@ abstract class OrmTestCase extends DoctrineTestCase private static function getSharedQueryCacheImpl() { if (self::$_queryCacheImpl === null) { - self::$_queryCacheImpl = new \Doctrine\Common\Cache\ArrayCache; + self::$_queryCacheImpl = new ArrayCache(); } return self::$_queryCacheImpl; @@ -190,7 +193,7 @@ abstract class OrmTestCase extends DoctrineTestCase protected function getSharedSecondLevelCacheDriverImpl() { if ($this->secondLevelCacheDriverImpl === null) { - $this->secondLevelCacheDriverImpl = new \Doctrine\Common\Cache\ArrayCache(); + $this->secondLevelCacheDriverImpl = new ArrayCache(); } return $this->secondLevelCacheDriverImpl;