From f60f2a567ae1ec4ae7e199b6e90aa1c37217f4f3 Mon Sep 17 00:00:00 2001 From: "Jasper N. Brouwer" Date: Sun, 9 Nov 2014 15:59:05 +0100 Subject: [PATCH 01/32] Fixed associations using a value-conversion type for identifiers --- .../Collection/ManyToManyPersister.php | 18 +- .../Entity/BasicEntityPersister.php | 145 ++++++++++++--- tests/Doctrine/Tests/DbalTypes/Rot13Type.php | 81 +++++++++ .../ValueConversionType/AuxiliaryEntity.php | 16 ++ .../InversedManyToManyCompositeIdEntity.php | 34 ++++ ...dManyToManyCompositeIdForeignKeyEntity.php | 35 ++++ .../InversedManyToManyEntity.php | 28 +++ .../InversedOneToManyCompositeIdEntity.php | 39 ++++ ...edOneToManyCompositeIdForeignKeyEntity.php | 40 +++++ .../InversedOneToManyEntity.php | 33 ++++ .../InversedOneToOneCompositeIdEntity.php | 32 ++++ ...sedOneToOneCompositeIdForeignKeyEntity.php | 33 ++++ .../InversedOneToOneEntity.php | 26 +++ .../OwningManyToManyCompositeIdEntity.php | 36 ++++ ...gManyToManyCompositeIdForeignKeyEntity.php | 36 ++++ .../OwningManyToManyEntity.php | 33 ++++ .../OwningManyToOneCompositeIdEntity.php | 25 +++ ...ngManyToOneCompositeIdForeignKeyEntity.php | 25 +++ .../OwningManyToOneEntity.php | 22 +++ .../OwningOneToOneCompositeIdEntity.php | 25 +++ ...ingOneToOneCompositeIdForeignKeyEntity.php | 30 ++++ .../OwningOneToOneEntity.php | 22 +++ .../ORM/Functional/SchemaValidatorTest.php | 11 ++ .../ManyToManyCompositeIdForeignKeyTest.php | 168 ++++++++++++++++++ .../ManyToManyCompositeIdTest.php | 162 +++++++++++++++++ .../ValueConversionType/ManyToManyTest.php | 158 ++++++++++++++++ .../OneToManyCompositeIdForeignKeyTest.php | 140 +++++++++++++++ .../OneToManyCompositeIdTest.php | 134 ++++++++++++++ .../ValueConversionType/OneToManyTest.php | 130 ++++++++++++++ .../OneToOneCompositeIdForeignKeyTest.php | 140 +++++++++++++++ .../OneToOneCompositeIdTest.php | 134 ++++++++++++++ .../ValueConversionType/OneToOneTest.php | 130 ++++++++++++++ .../Doctrine/Tests/OrmFunctionalTestCase.php | 90 ++++++++++ 33 files changed, 2179 insertions(+), 32 deletions(-) create mode 100644 tests/Doctrine/Tests/DbalTypes/Rot13Type.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/AuxiliaryEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyCompositeIdEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyCompositeIdForeignKeyEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyCompositeIdEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyCompositeIdForeignKeyEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneCompositeIdEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneCompositeIdForeignKeyEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyCompositeIdEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyCompositeIdForeignKeyEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneCompositeIdEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneCompositeIdForeignKeyEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/OwningOneToOneCompositeIdEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/OwningOneToOneCompositeIdForeignKeyEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/OwningOneToOneEntity.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index 40b1be958..3a09079c7 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -374,22 +374,20 @@ class ManyToManyPersister extends AbstractCollectionPersister $mapping = $collection->getMapping(); $identifier = $this->uow->getEntityIdentifier($collection->getOwner()); - // Optimization for single column identifier - if (count($mapping['relationToSourceKeyColumns']) === 1) { - return array(reset($identifier)); - } - - // Composite identifier $sourceClass = $this->em->getClassMetadata($mapping['sourceEntity']); $params = array(); + $types = array(); foreach ($mapping['relationToSourceKeyColumns'] as $columnName => $refColumnName) { - $params[] = isset($sourceClass->fieldNames[$refColumnName]) - ? $identifier[$sourceClass->fieldNames[$refColumnName]] - : $identifier[$sourceClass->getFieldForColumn($columnName)]; + $field = isset($sourceClass->fieldNames[$refColumnName]) + ? $sourceClass->fieldNames[$refColumnName] + : $sourceClass->getFieldForColumn($columnName); + + $params[] = $identifier[$field]; + $types[] = $this->getType($field, $sourceClass); } - return $params; + return array($params, $types); } /** diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 537961420..1be3ecd5b 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -710,6 +710,7 @@ class BasicEntityPersister implements EntityPersister { $sql = $this->getSelectSQL($criteria, $assoc, $lockMode, $limit, null, $orderBy); list($params, $types) = $this->expandParameters($criteria); + $stmt = $this->conn->executeQuery($sql, $params, $types); if ($entity !== null) { @@ -965,11 +966,12 @@ class BasicEntityPersister implements EntityPersister */ private function getManyToManyStatement(array $assoc, $sourceEntity, $offset = null, $limit = null) { - $sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']); - $class = $sourceClass; - $association = $assoc; - $criteria = array(); + $criteria = array(); + $parameters = array(); + $sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']); + $class = $sourceClass; + $association = $assoc; if ( ! $assoc['isOwningSide']) { $class = $this->em->getClassMetadata($assoc['targetEntity']); @@ -984,8 +986,8 @@ class BasicEntityPersister implements EntityPersister foreach ($joinColumns as $joinColumn) { - $sourceKeyColumn = $joinColumn['referencedColumnName']; - $quotedKeyColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); + $sourceKeyColumn = $joinColumn['referencedColumnName']; + $quotedKeyColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); switch (true) { case $sourceClass->containsForeignIdentifier: @@ -1012,10 +1014,11 @@ class BasicEntityPersister implements EntityPersister } $criteria[$quotedJoinTable . '.' . $quotedKeyColumn] = $value; + $parameters[] = array('value' => $value, 'field' => $field, 'class' => $sourceClass); } $sql = $this->getSelectSQL($criteria, $assoc, null, $limit, $offset); - list($params, $types) = $this->expandParameters($criteria); + list($params, $types) = $this->expandToManyParameters($parameters); return $this->conn->executeQuery($sql, $params, $types); } @@ -1303,17 +1306,13 @@ class BasicEntityPersister implements EntityPersister $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); foreach ($assoc['joinColumns'] as $joinColumn) { - $type = null; + $type = $this->getColumnType($joinColumn['referencedColumnName'], null, $targetClass); $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; - if (isset($targetClass->fieldNames[$joinColumn['referencedColumnName']])) { - $type = $targetClass->fieldMappings[$targetClass->fieldNames[$joinColumn['referencedColumnName']]]['type']; - } - $this->rsm->addMetaResult($alias, $resultColumnName, $quotedColumn, $isIdentifier, $type); } @@ -1713,7 +1712,9 @@ class BasicEntityPersister implements EntityPersister */ private function getOneToManyStatement(array $assoc, $sourceEntity, $offset = null, $limit = null) { - $criteria = array(); + $criteria = array(); + $parameters = array(); + $owningAssoc = $this->class->associationMappings[$assoc['mappedBy']]; $sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']); @@ -1730,15 +1731,20 @@ class BasicEntityPersister implements EntityPersister } $criteria[$tableAlias . "." . $targetKeyColumn] = $value; + $parameters[] = array('value' => $value, 'field' => $field, 'class' => $sourceClass); continue; } - $criteria[$tableAlias . "." . $targetKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity); + $field = $sourceClass->fieldNames[$sourceKeyColumn]; + $value = $sourceClass->reflFields[$field]->getValue($sourceEntity); + + $criteria[$tableAlias . "." . $targetKeyColumn] = $value; + $parameters[] = array('value' => $value, 'field' => $field, 'class' => $sourceClass); } $sql = $this->getSelectSQL($criteria, $assoc, null, $limit, $offset); - list($params, $types) = $this->expandParameters($criteria); + list($params, $types) = $this->expandToManyParameters($parameters); return $this->conn->executeQuery($sql, $params, $types); } @@ -1764,17 +1770,51 @@ class BasicEntityPersister implements EntityPersister } /** - * Infers field type to be used by parameter type casting. + * Expands the parameters from the given criteria and use the correct binding types if found, + * specialized for OneToMany or ManyToMany associations. * - * @param string $field - * @param mixed $value + * DDC-3380: {@see getManyToManyStatement()} and {@see getOneToManyStatement()}. * - * @return integer + * @param array $criteria + * + * @return array + */ + private function expandToManyParameters($criteria) + { + $params = array(); + $types = array(); + + foreach ($criteria as $criterion) { + if ($criterion['value'] === null) { + continue; // skip null values. + } + + $types[] = $this->getType($criterion['field'], $criterion['value'], $criterion['class']); + $params[] = $this->getValue($criterion['value']); + } + + return array($params, $types); + } + + /** + * Infers the binding type of a field by parameter type casting. + * + * DDC-3380: Added optional $class argument. + * + * @param string $field + * @param mixed $value + * @param ClassMetadata|null $class + * + * @return int|string|null * * @throws \Doctrine\ORM\Query\QueryException */ - private function getType($field, $value) + private function getType($field, $value, ClassMetadata $class = null) { + if ($class === null) { + $class = $this->class; + } + switch (true) { case (isset($this->class->fieldMappings[$field])): $type = $this->class->fieldMappings[$field]['type']; @@ -1802,8 +1842,8 @@ class BasicEntityPersister implements EntityPersister break; - case (isset($this->class->associationMappings[$field])): - $assoc = $this->class->associationMappings[$field]; + case (isset($class->associationMappings[$field])): + $assoc = $class->associationMappings[$field]; if (count($assoc['sourceToTargetKeyColumns']) > 1) { throw Query\QueryException::associationPathCompositeKeyNotSupported(); @@ -1831,6 +1871,67 @@ class BasicEntityPersister implements EntityPersister return $type; } + /** + * Infers the binding type of a column by parameter type casting. + * + * @param string $columnName + * @param mixed $value + * @param ClassMetadata $class + * @return int|string|null + */ + private function getColumnType($columnName, $value, ClassMetadata $class) + { + $type = null; + + switch (true) { + case (isset($class->fieldNames[$columnName])): + $fieldName = $class->fieldNames[$columnName]; + + if (isset($class->fieldMappings[$fieldName])) { + $type = $class->fieldMappings[$fieldName]['type']; + } + + break; + + default: + $type = $this->getAssociationColumnType($columnName, $class); + } + + if (is_array($value)) { + $type = Type::getType($type)->getBindingType(); + $type += Connection::ARRAY_PARAM_OFFSET; + } + + return $type; + } + + /** + * Infers the binding type of a column by traversing association mappings. + * + * @param string $columnName + * @param ClassMetadata $class + * @return string|null + */ + private function getAssociationColumnType($columnName, ClassMetadata $class) + { + foreach ($class->associationMappings as $assoc) { + foreach ($assoc['joinColumns'] as $joinColumn) { + if ($joinColumn['name'] == $columnName) { + $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); + $targetColumn = $joinColumn['referencedColumnName']; + + if (isset($targetClass->fieldNames[$targetColumn])) { + return $targetClass->fieldMappings[$targetClass->fieldNames[$targetColumn]]['type']; + } + + return $this->getAssociationColumnType($targetColumn, $class); + } + } + } + + return null; + } + /** * Retrieves parameter value. * diff --git a/tests/Doctrine/Tests/DbalTypes/Rot13Type.php b/tests/Doctrine/Tests/DbalTypes/Rot13Type.php new file mode 100644 index 000000000..6403b9ebe --- /dev/null +++ b/tests/Doctrine/Tests/DbalTypes/Rot13Type.php @@ -0,0 +1,81 @@ +getVarcharTypeDeclarationSQL($fieldDeclaration); + } + + /** + * {@inheritdoc} + * + * @param AbstractPlatform $platform + * + * @return int|null + */ + public function getDefaultLength(AbstractPlatform $platform) + { + return $platform->getVarcharDefaultLength(); + } + + /** + * {@inheritdoc} + * + * @return string + */ + public function getName() + { + return 'rot13'; + } +} diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/AuxiliaryEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/AuxiliaryEntity.php new file mode 100644 index 000000000..d37413909 --- /dev/null +++ b/tests/Doctrine/Tests/Models/ValueConversionType/AuxiliaryEntity.php @@ -0,0 +1,16 @@ +associatedEntities = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyCompositeIdForeignKeyEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyCompositeIdForeignKeyEntity.php new file mode 100644 index 000000000..b53f559f9 --- /dev/null +++ b/tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyCompositeIdForeignKeyEntity.php @@ -0,0 +1,35 @@ +associatedEntities = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyEntity.php new file mode 100644 index 000000000..c2cab841c --- /dev/null +++ b/tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyEntity.php @@ -0,0 +1,28 @@ +associatedEntities = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyCompositeIdEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyCompositeIdEntity.php new file mode 100644 index 000000000..01892c1aa --- /dev/null +++ b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyCompositeIdEntity.php @@ -0,0 +1,39 @@ +associatedEntities = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyCompositeIdForeignKeyEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyCompositeIdForeignKeyEntity.php new file mode 100644 index 000000000..571ce8378 --- /dev/null +++ b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyCompositeIdForeignKeyEntity.php @@ -0,0 +1,40 @@ +associatedEntities = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyEntity.php new file mode 100644 index 000000000..8da0b10b9 --- /dev/null +++ b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyEntity.php @@ -0,0 +1,33 @@ +associatedEntities = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneCompositeIdEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneCompositeIdEntity.php new file mode 100644 index 000000000..631b22b8b --- /dev/null +++ b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneCompositeIdEntity.php @@ -0,0 +1,32 @@ +associatedEntities = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyCompositeIdForeignKeyEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyCompositeIdForeignKeyEntity.php new file mode 100644 index 000000000..21e35b79a --- /dev/null +++ b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyCompositeIdForeignKeyEntity.php @@ -0,0 +1,36 @@ +associatedEntities = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyEntity.php new file mode 100644 index 000000000..b05c87874 --- /dev/null +++ b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyEntity.php @@ -0,0 +1,33 @@ +associatedEntities = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneCompositeIdEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneCompositeIdEntity.php new file mode 100644 index 000000000..d8f8a2bab --- /dev/null +++ b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneCompositeIdEntity.php @@ -0,0 +1,25 @@ +useModelSet('vct_manytomany_compositeid_foreignkey'); + parent::setUp(); + + $auxiliary = new Entity\AuxiliaryEntity(); + $auxiliary->id = 'abc'; + + $inversed = new Entity\InversedManyToManyCompositeIdForeignKeyEntity(); + $inversed->id = 'def'; + $inversed->foreignEntity = $auxiliary; + + $owning = new Entity\OwningManyToManyCompositeIdForeignKeyEntity(); + $owning->id = 'ghi'; + + $inversed->associatedEntities->add($owning); + $owning->associatedEntities->add($inversed); + + $this->_em->persist($auxiliary); + $this->_em->persist($inversed); + $this->_em->persist($owning); + + $this->_em->flush(); + $this->_em->clear(); + } + + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_xref_manytomany_compositeid_foreignkey'); + $conn->executeUpdate('DROP TABLE vct_owning_manytomany_compositeid_foreignkey'); + $conn->executeUpdate('DROP TABLE vct_inversed_manytomany_compositeid_foreignkey'); + $conn->executeUpdate('DROP TABLE vct_auxiliary'); + } + + public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() + { + $conn = $this->_em->getConnection(); + + $this->assertEquals('qrs', $conn->fetchColumn('SELECT id FROM vct_inversed_manytomany_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('nop', $conn->fetchColumn('SELECT foreign_id FROM vct_inversed_manytomany_compositeid_foreignkey LIMIT 1')); + + $this->assertEquals('tuv', $conn->fetchColumn('SELECT id FROM vct_owning_manytomany_compositeid_foreignkey LIMIT 1')); + + $this->assertEquals('qrs', $conn->fetchColumn('SELECT associated_id FROM vct_xref_manytomany_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_foreign_id FROM vct_xref_manytomany_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('tuv', $conn->fetchColumn('SELECT owning_id FROM vct_xref_manytomany_compositeid_foreignkey LIMIT 1')); + } + + /** + * @depends testThatTheValueOfIdentifiersAreConvertedInTheDatabase + */ + public function testThatEntitiesAreFetchedFromTheDatabase() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', + array('id' => 'def', 'foreignEntity' => 'abc') + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity', + 'ghi' + ); + + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', $inversed); + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity', $owning); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', + array('id' => 'def', 'foreignEntity' => 'abc') + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity', + 'ghi' + ); + + $this->assertEquals('def', $inversed->id); + $this->assertEquals('abc', $inversed->foreignEntity->id); + $this->assertEquals('ghi', $owning->id); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheCollectionFromOwningToInversedIsLoaded() + { + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity', + 'ghi' + ); + + $this->assertCount(1, $owning->associatedEntities); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheCollectionFromInversedToOwningIsLoaded() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', + array('id' => 'def', 'foreignEntity' => 'abc') + ); + + $this->assertCount(1, $inversed->associatedEntities); + } + + /** + * @depends testThatTheCollectionFromOwningToInversedIsLoaded + * @depends testThatTheCollectionFromInversedToOwningIsLoaded + */ + public function testThatTheJoinTableRowsAreRemovedWhenRemovingTheAssociation() + { + $conn = $this->_em->getConnection(); + + // remove association + + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', + array('id' => 'def', 'foreignEntity' => 'abc') + ); + + foreach ($inversed->associatedEntities as $owning) { + $inversed->associatedEntities->removeElement($owning); + $owning->associatedEntities->removeElement($inversed); + } + + $this->_em->flush(); + $this->_em->clear(); + + // test association is removed + + $this->assertEquals(0, $conn->fetchColumn('SELECT COUNT(*) FROM vct_xref_manytomany_compositeid_foreignkey')); + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php new file mode 100644 index 000000000..d0f75b4cb --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php @@ -0,0 +1,162 @@ +useModelSet('vct_manytomany_compositeid'); + parent::setUp(); + + $inversed = new Entity\InversedManyToManyCompositeIdEntity(); + $inversed->id1 = 'abc'; + $inversed->id2 = 'def'; + + $owning = new Entity\OwningManyToManyCompositeIdEntity(); + $owning->id = 'ghi'; + + $inversed->associatedEntities->add($owning); + $owning->associatedEntities->add($inversed); + + $this->_em->persist($inversed); + $this->_em->persist($owning); + + $this->_em->flush(); + $this->_em->clear(); + } + + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_xref_manytomany_compositeid'); + $conn->executeUpdate('DROP TABLE vct_owning_manytomany_compositeid'); + $conn->executeUpdate('DROP TABLE vct_inversed_manytomany_compositeid'); + } + + public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() + { + $conn = $this->_em->getConnection(); + + $this->assertEquals('nop', $conn->fetchColumn('SELECT id1 FROM vct_inversed_manytomany_compositeid LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchColumn('SELECT id2 FROM vct_inversed_manytomany_compositeid LIMIT 1')); + + $this->assertEquals('tuv', $conn->fetchColumn('SELECT id FROM vct_owning_manytomany_compositeid LIMIT 1')); + + $this->assertEquals('nop', $conn->fetchColumn('SELECT inversed_id1 FROM vct_xref_manytomany_compositeid LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchColumn('SELECT inversed_id2 FROM vct_xref_manytomany_compositeid LIMIT 1')); + $this->assertEquals('tuv', $conn->fetchColumn('SELECT owning_id FROM vct_xref_manytomany_compositeid LIMIT 1')); + } + + /** + * @depends testThatTheValueOfIdentifiersAreConvertedInTheDatabase + */ + public function testThatEntitiesAreFetchedFromTheDatabase() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdEntity', + array('id1' => 'abc', 'id2' => 'def') + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdEntity', + 'ghi' + ); + + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdEntity', $inversed); + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdEntity', $owning); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdEntity', + array('id1' => 'abc', 'id2' => 'def') + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdEntity', + 'ghi' + ); + + $this->assertEquals('abc', $inversed->id1); + $this->assertEquals('def', $inversed->id2); + $this->assertEquals('ghi', $owning->id); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheCollectionFromOwningToInversedIsLoaded() + { + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdEntity', + 'ghi' + ); + + $this->assertCount(1, $owning->associatedEntities); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheCollectionFromInversedToOwningIsLoaded() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdEntity', + array('id1' => 'abc', 'id2' => 'def') + ); + + $this->assertCount(1, $inversed->associatedEntities); + } + + /** + * @depends testThatTheCollectionFromOwningToInversedIsLoaded + * @depends testThatTheCollectionFromInversedToOwningIsLoaded + */ + public function testThatTheJoinTableRowsAreRemovedWhenRemovingTheAssociation() + { + $conn = $this->_em->getConnection(); + + // remove association + + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdEntity', + array('id1' => 'abc', 'id2' => 'def') + ); + + foreach ($inversed->associatedEntities as $owning) { + $inversed->associatedEntities->removeElement($owning); + $owning->associatedEntities->removeElement($inversed); + } + + $this->_em->flush(); + $this->_em->clear(); + + // test association is removed + + $this->assertEquals(0, $conn->fetchColumn('SELECT COUNT(*) FROM vct_xref_manytomany_compositeid')); + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php new file mode 100644 index 000000000..1ff8d7ab2 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php @@ -0,0 +1,158 @@ +useModelSet('vct_manytomany'); + parent::setUp(); + + $inversed = new Entity\InversedManyToManyEntity(); + $inversed->id = 'abc'; + + $owning = new Entity\OwningManyToManyEntity(); + $owning->id = 'def'; + + $inversed->associatedEntities->add($owning); + $owning->associatedEntities->add($inversed); + + $this->_em->persist($inversed); + $this->_em->persist($owning); + + $this->_em->flush(); + $this->_em->clear(); + } + + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_xref_manytomany'); + $conn->executeUpdate('DROP TABLE vct_owning_manytomany'); + $conn->executeUpdate('DROP TABLE vct_inversed_manytomany'); + } + + public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() + { + $conn = $this->_em->getConnection(); + + $this->assertEquals('nop', $conn->fetchColumn('SELECT id FROM vct_inversed_manytomany LIMIT 1')); + + $this->assertEquals('qrs', $conn->fetchColumn('SELECT id FROM vct_owning_manytomany LIMIT 1')); + + $this->assertEquals('nop', $conn->fetchColumn('SELECT inversed_id FROM vct_xref_manytomany LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchColumn('SELECT owning_id FROM vct_xref_manytomany LIMIT 1')); + } + + /** + * @depends testThatTheValueOfIdentifiersAreConvertedInTheDatabase + */ + public function testThatEntitiesAreFetchedFromTheDatabase() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyEntity', + 'abc' + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyEntity', + 'def' + ); + + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedManyToManyEntity', $inversed); + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningManyToManyEntity', $owning); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyEntity', + 'abc' + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyEntity', + 'def' + ); + + $this->assertEquals('abc', $inversed->id); + $this->assertEquals('def', $owning->id); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheCollectionFromOwningToInversedIsLoaded() + { + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyEntity', + 'def' + ); + + $this->assertCount(1, $owning->associatedEntities); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheCollectionFromInversedToOwningIsLoaded() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyEntity', + 'abc' + ); + + $this->assertCount(1, $inversed->associatedEntities); + } + + /** + * @depends testThatTheCollectionFromOwningToInversedIsLoaded + * @depends testThatTheCollectionFromInversedToOwningIsLoaded + */ + public function testThatTheJoinTableRowsAreRemovedWhenRemovingTheAssociation() + { + $conn = $this->_em->getConnection(); + + // remove association + + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyEntity', + 'abc' + ); + + foreach ($inversed->associatedEntities as $owning) { + $inversed->associatedEntities->removeElement($owning); + $owning->associatedEntities->removeElement($inversed); + } + + $this->_em->flush(); + $this->_em->clear(); + + // test association is removed + + $this->assertEquals(0, $conn->fetchColumn('SELECT COUNT(*) FROM vct_xref_manytomany')); + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php new file mode 100644 index 000000000..d0f571415 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php @@ -0,0 +1,140 @@ +useModelSet('vct_onetomany_compositeid_foreignkey'); + parent::setUp(); + + $auxiliary = new Entity\AuxiliaryEntity(); + $auxiliary->id = 'abc'; + + $inversed = new Entity\InversedOneToManyCompositeIdForeignKeyEntity(); + $inversed->id = 'def'; + $inversed->foreignEntity = $auxiliary; + $inversed->someProperty = 'some value to be loaded'; + + $owning = new Entity\OwningManyToOneCompositeIdForeignKeyEntity(); + $owning->id = 'ghi'; + + $inversed->associatedEntities->add($owning); + $owning->associatedEntity = $inversed; + + $this->_em->persist($auxiliary); + $this->_em->persist($inversed); + $this->_em->persist($owning); + + $this->_em->flush(); + $this->_em->clear(); + } + + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_owning_manytoone_compositeid_foreignkey'); + $conn->executeUpdate('DROP TABLE vct_inversed_onetomany_compositeid_foreignkey'); + $conn->executeUpdate('DROP TABLE vct_auxiliary'); + } + + public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() + { + $conn = $this->_em->getConnection(); + + $this->assertEquals('qrs', $conn->fetchColumn('SELECT id FROM vct_inversed_onetomany_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('nop', $conn->fetchColumn('SELECT foreign_id FROM vct_inversed_onetomany_compositeid_foreignkey LIMIT 1')); + + $this->assertEquals('tuv', $conn->fetchColumn('SELECT id FROM vct_owning_manytoone_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchColumn('SELECT associated_id FROM vct_owning_manytoone_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_foreign_id FROM vct_owning_manytoone_compositeid_foreignkey LIMIT 1')); + } + + /** + * @depends testThatTheValueOfIdentifiersAreConvertedInTheDatabase + */ + public function testThatEntitiesAreFetchedFromTheDatabase() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', + array('id' => 'def', 'foreignEntity' => 'abc') + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity', + 'ghi' + ); + + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', $inversed); + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity', $owning); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', + array('id' => 'def', 'foreignEntity' => 'abc') + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity', + 'ghi' + ); + + $this->assertEquals('def', $inversed->id); + $this->assertEquals('abc', $inversed->foreignEntity->id); + $this->assertEquals('ghi', $owning->id); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheProxyFromOwningToInversedIsLoaded() + { + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity', + 'ghi' + ); + + $inversedProxy = $owning->associatedEntity; + + $this->assertEquals('some value to be loaded', $inversedProxy->someProperty); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheCollectionFromInversedToOwningIsLoaded() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', + array('id' => 'def', 'foreignEntity' => 'abc') + ); + + $this->assertCount(1, $inversed->associatedEntities); + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php new file mode 100644 index 000000000..297b46eb8 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php @@ -0,0 +1,134 @@ +useModelSet('vct_onetomany_compositeid'); + parent::setUp(); + + $inversed = new Entity\InversedOneToManyCompositeIdEntity(); + $inversed->id1 = 'abc'; + $inversed->id2 = 'def'; + $inversed->someProperty = 'some value to be loaded'; + + $owning = new Entity\OwningManyToOneCompositeIdEntity(); + $owning->id = 'ghi'; + + $inversed->associatedEntities->add($owning); + $owning->associatedEntity = $inversed; + + $this->_em->persist($inversed); + $this->_em->persist($owning); + + $this->_em->flush(); + $this->_em->clear(); + } + + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_owning_manytoone_compositeid'); + $conn->executeUpdate('DROP TABLE vct_inversed_onetomany_compositeid'); + } + + public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() + { + $conn = $this->_em->getConnection(); + + $this->assertEquals('nop', $conn->fetchColumn('SELECT id1 FROM vct_inversed_onetomany_compositeid LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchColumn('SELECT id2 FROM vct_inversed_onetomany_compositeid LIMIT 1')); + + $this->assertEquals('tuv', $conn->fetchColumn('SELECT id FROM vct_owning_manytoone_compositeid LIMIT 1')); + $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_id1 FROM vct_owning_manytoone_compositeid LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchColumn('SELECT associated_id2 FROM vct_owning_manytoone_compositeid LIMIT 1')); + } + + /** + * @depends testThatTheValueOfIdentifiersAreConvertedInTheDatabase + */ + public function testThatEntitiesAreFetchedFromTheDatabase() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdEntity', + array('id1' => 'abc', 'id2' => 'def') + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdEntity', + 'ghi' + ); + + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdEntity', $inversed); + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdEntity', $owning); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdEntity', + array('id1' => 'abc', 'id2' => 'def') + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdEntity', + 'ghi' + ); + + $this->assertEquals('abc', $inversed->id1); + $this->assertEquals('def', $inversed->id2); + $this->assertEquals('ghi', $owning->id); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheProxyFromOwningToInversedIsLoaded() + { + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdEntity', + 'ghi' + ); + + $inversedProxy = $owning->associatedEntity; + + $this->assertEquals('some value to be loaded', $inversedProxy->someProperty); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheCollectionFromInversedToOwningIsLoaded() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdEntity', + array('id1' => 'abc', 'id2' => 'def') + ); + + $this->assertCount(1, $inversed->associatedEntities); + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php new file mode 100644 index 000000000..25e9135c3 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php @@ -0,0 +1,130 @@ +useModelSet('vct_onetomany'); + parent::setUp(); + + $inversed = new Entity\InversedOneToManyEntity(); + $inversed->id = 'abc'; + $inversed->someProperty = 'some value to be loaded'; + + $owning = new Entity\OwningManyToOneEntity(); + $owning->id = 'def'; + + $inversed->associatedEntities->add($owning); + $owning->associatedEntity = $inversed; + + $this->_em->persist($inversed); + $this->_em->persist($owning); + + $this->_em->flush(); + $this->_em->clear(); + } + + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_owning_manytoone'); + $conn->executeUpdate('DROP TABLE vct_inversed_onetomany'); + } + + public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() + { + $conn = $this->_em->getConnection(); + + $this->assertEquals('nop', $conn->fetchColumn('SELECT id FROM vct_inversed_onetomany LIMIT 1')); + + $this->assertEquals('qrs', $conn->fetchColumn('SELECT id FROM vct_owning_manytoone LIMIT 1')); + $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_id FROM vct_owning_manytoone LIMIT 1')); + } + + /** + * @depends testThatTheValueOfIdentifiersAreConvertedInTheDatabase + */ + public function testThatEntitiesAreFetchedFromTheDatabase() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyEntity', + 'abc' + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneEntity', + 'def' + ); + + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToManyEntity', $inversed); + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningManyToOneEntity', $owning); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyEntity', + 'abc' + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneEntity', + 'def' + ); + + $this->assertEquals('abc', $inversed->id); + $this->assertEquals('def', $owning->id); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheProxyFromOwningToInversedIsLoaded() + { + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneEntity', + 'def' + ); + + $inversedProxy = $owning->associatedEntity; + + $this->assertEquals('some value to be loaded', $inversedProxy->someProperty); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheCollectionFromInversedToOwningIsLoaded() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyEntity', + 'abc' + ); + + $this->assertCount(1, $inversed->associatedEntities); + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php new file mode 100644 index 000000000..b3b58d245 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php @@ -0,0 +1,140 @@ +useModelSet('vct_onetoone_compositeid_foreignkey'); + parent::setUp(); + + $auxiliary = new Entity\AuxiliaryEntity(); + $auxiliary->id = 'abc'; + + $inversed = new Entity\InversedOneToOneCompositeIdForeignKeyEntity(); + $inversed->id = 'def'; + $inversed->foreignEntity = $auxiliary; + $inversed->someProperty = 'some value to be loaded'; + + $owning = new Entity\OwningOneToOneCompositeIdForeignKeyEntity(); + $owning->id = 'ghi'; + + $inversed->associatedEntity = $owning; + $owning->associatedEntity = $inversed; + + $this->_em->persist($auxiliary); + $this->_em->persist($inversed); + $this->_em->persist($owning); + + $this->_em->flush(); + $this->_em->clear(); + } + + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_owning_onetoone_compositeid_foreignkey'); + $conn->executeUpdate('DROP TABLE vct_inversed_onetoone_compositeid_foreignkey'); + $conn->executeUpdate('DROP TABLE vct_auxiliary'); + } + + public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() + { + $conn = $this->_em->getConnection(); + + $this->assertEquals('qrs', $conn->fetchColumn('SELECT id FROM vct_inversed_onetoone_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('nop', $conn->fetchColumn('SELECT foreign_id FROM vct_inversed_onetoone_compositeid_foreignkey LIMIT 1')); + + $this->assertEquals('tuv', $conn->fetchColumn('SELECT id FROM vct_owning_onetoone_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchColumn('SELECT associated_id FROM vct_owning_onetoone_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_foreign_id FROM vct_owning_onetoone_compositeid_foreignkey LIMIT 1')); + } + + /** + * @depends testThatTheValueOfIdentifiersAreConvertedInTheDatabase + */ + public function testThatEntitiesAreFetchedFromTheDatabase() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', + array('id' => 'def', 'foreignEntity' => 'abc') + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity', + 'ghi' + ); + + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', $inversed); + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity', $owning); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', + array('id' => 'def', 'foreignEntity' => 'abc') + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity', + 'ghi' + ); + + $this->assertEquals('def', $inversed->id); + $this->assertEquals('abc', $inversed->foreignEntity->id); + $this->assertEquals('ghi', $owning->id); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheProxyFromOwningToInversedIsLoaded() + { + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity', + 'ghi' + ); + + $inversedProxy = $owning->associatedEntity; + + $this->assertEquals('some value to be loaded', $inversedProxy->someProperty); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheEntityFromInversedToOwningIsEagerLoaded() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', + array('id' => 'def', 'foreignEntity' => 'abc') + ); + + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity', $inversed->associatedEntity); + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php new file mode 100644 index 000000000..0390eb7f5 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php @@ -0,0 +1,134 @@ +useModelSet('vct_onetoone_compositeid'); + parent::setUp(); + + $inversed = new Entity\InversedOneToOneCompositeIdEntity(); + $inversed->id1 = 'abc'; + $inversed->id2 = 'def'; + $inversed->someProperty = 'some value to be loaded'; + + $owning = new Entity\OwningOneToOneCompositeIdEntity(); + $owning->id = 'ghi'; + + $inversed->associatedEntity = $owning; + $owning->associatedEntity = $inversed; + + $this->_em->persist($inversed); + $this->_em->persist($owning); + + $this->_em->flush(); + $this->_em->clear(); + } + + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_owning_onetoone_compositeid'); + $conn->executeUpdate('DROP TABLE vct_inversed_onetoone_compositeid'); + } + + public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() + { + $conn = $this->_em->getConnection(); + + $this->assertEquals('nop', $conn->fetchColumn('SELECT id1 FROM vct_inversed_onetoone_compositeid LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchColumn('SELECT id2 FROM vct_inversed_onetoone_compositeid LIMIT 1')); + + $this->assertEquals('tuv', $conn->fetchColumn('SELECT id FROM vct_owning_onetoone_compositeid LIMIT 1')); + $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_id1 FROM vct_owning_onetoone_compositeid LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchColumn('SELECT associated_id2 FROM vct_owning_onetoone_compositeid LIMIT 1')); + } + + /** + * @depends testThatTheValueOfIdentifiersAreConvertedInTheDatabase + */ + public function testThatEntitiesAreFetchedFromTheDatabase() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdEntity', + array('id1' => 'abc', 'id2' => 'def') + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity', + 'ghi' + ); + + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdEntity', $inversed); + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity', $owning); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdEntity', + array('id1' => 'abc', 'id2' => 'def') + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity', + 'ghi' + ); + + $this->assertEquals('abc', $inversed->id1); + $this->assertEquals('def', $inversed->id2); + $this->assertEquals('ghi', $owning->id); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheProxyFromOwningToInversedIsLoaded() + { + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity', + 'ghi' + ); + + $inversedProxy = $owning->associatedEntity; + + $this->assertEquals('some value to be loaded', $inversedProxy->someProperty); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheEntityFromInversedToOwningIsEagerLoaded() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdEntity', + array('id1' => 'abc', 'id2' => 'def') + ); + + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity', $inversed->associatedEntity); + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php new file mode 100644 index 000000000..2cdaadcaa --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php @@ -0,0 +1,130 @@ +useModelSet('vct_onetoone'); + parent::setUp(); + + $inversed = new Entity\InversedOneToOneEntity(); + $inversed->id = 'abc'; + $inversed->someProperty = 'some value to be loaded'; + + $owning = new Entity\OwningOneToOneEntity(); + $owning->id = 'def'; + + $inversed->associatedEntity = $owning; + $owning->associatedEntity = $inversed; + + $this->_em->persist($inversed); + $this->_em->persist($owning); + + $this->_em->flush(); + $this->_em->clear(); + } + + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_owning_onetoone'); + $conn->executeUpdate('DROP TABLE vct_inversed_onetoone'); + } + + public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() + { + $conn = $this->_em->getConnection(); + + $this->assertEquals('nop', $conn->fetchColumn('SELECT id FROM vct_inversed_onetoone LIMIT 1')); + + $this->assertEquals('qrs', $conn->fetchColumn('SELECT id FROM vct_owning_onetoone LIMIT 1')); + $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_id FROM vct_owning_onetoone LIMIT 1')); + } + + /** + * @depends testThatTheValueOfIdentifiersAreConvertedInTheDatabase + */ + public function testThatEntitiesAreFetchedFromTheDatabase() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneEntity', + 'abc' + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneEntity', + 'def' + ); + + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToOneEntity', $inversed); + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningOneToOneEntity', $owning); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneEntity', + 'abc' + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneEntity', + 'def' + ); + + $this->assertEquals('abc', $inversed->id); + $this->assertEquals('def', $owning->id); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheProxyFromOwningToInversedIsLoaded() + { + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneEntity', + 'def' + ); + + $inversedProxy = $owning->associatedEntity; + + $this->assertEquals('some value to be loaded', $inversedProxy->someProperty); + } + + /** + * @depends testThatEntitiesAreFetchedFromTheDatabase + */ + public function testThatTheEntityFromInversedToOwningIsEagerLoaded() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneEntity', + 'abc' + ); + + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningOneToOneEntity', $inversed->associatedEntity); + } +} diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index bc301ecfb..0af76186c 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -199,6 +199,45 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\Quote\Phone', 'Doctrine\Tests\Models\Quote\User' ), + 'vct_onetoone' => array( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneEntity' + ), + 'vct_onetoone_compositeid' => array( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity' + ), + 'vct_onetoone_compositeid_foreignkey' => array( + 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity' + ), + 'vct_onetomany' => array( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneEntity' + ), + 'vct_onetomany_compositeid' => array( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdEntity' + ), + 'vct_onetomany_compositeid_foreignkey' => array( + 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity' + ), + 'vct_manytomany' => array( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyEntity' + ), + 'vct_manytomany_compositeid' => array( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdEntity' + ), + 'vct_manytomany_compositeid_foreignkey' => array( + 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity' + ), ); /** @@ -358,6 +397,57 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier("quote-user")); } + if (isset($this->_usedModelSets['vct_onetoone'])) { + $conn->executeUpdate('DELETE FROM vct_owning_onetoone'); + $conn->executeUpdate('DELETE FROM vct_inversed_onetoone'); + } + + if (isset($this->_usedModelSets['vct_onetoone_compositeid'])) { + $conn->executeUpdate('DELETE FROM vct_owning_onetoone_compositeid'); + $conn->executeUpdate('DELETE FROM vct_inversed_onetoone_compositeid'); + } + + if (isset($this->_usedModelSets['vct_onetoone_compositeid_foreignkey'])) { + $conn->executeUpdate('DELETE FROM vct_owning_onetoone_compositeid_foreignkey'); + $conn->executeUpdate('DELETE FROM vct_inversed_onetoone_compositeid_foreignkey'); + $conn->executeUpdate('DELETE FROM vct_auxiliary'); + } + + if (isset($this->_usedModelSets['vct_onetomany'])) { + $conn->executeUpdate('DELETE FROM vct_owning_manytoone'); + $conn->executeUpdate('DELETE FROM vct_inversed_onetomany'); + } + + if (isset($this->_usedModelSets['vct_onetomany_compositeid'])) { + $conn->executeUpdate('DELETE FROM vct_owning_manytoone_compositeid'); + $conn->executeUpdate('DELETE FROM vct_inversed_onetomany_compositeid'); + } + + if (isset($this->_usedModelSets['vct_onetomany_compositeid_foreignkey'])) { + $conn->executeUpdate('DELETE FROM vct_owning_manytoone_compositeid_foreignkey'); + $conn->executeUpdate('DELETE FROM vct_inversed_onetomany_compositeid_foreignkey'); + $conn->executeUpdate('DELETE FROM vct_auxiliary'); + } + + if (isset($this->_usedModelSets['vct_manytomany'])) { + $conn->executeUpdate('DELETE FROM vct_xref_manytomany'); + $conn->executeUpdate('DELETE FROM vct_owning_manytomany'); + $conn->executeUpdate('DELETE FROM vct_inversed_manytomany'); + } + + if (isset($this->_usedModelSets['vct_manytomany_compositeid'])) { + $conn->executeUpdate('DELETE FROM vct_xref_manytomany_compositeid'); + $conn->executeUpdate('DELETE FROM vct_owning_manytomany_compositeid'); + $conn->executeUpdate('DELETE FROM vct_inversed_manytomany_compositeid'); + } + + if (isset($this->_usedModelSets['vct_manytomany_compositeid_foreignkey'])) { + $conn->executeUpdate('DELETE FROM vct_xref_manytomany_compositeid_foreignkey'); + $conn->executeUpdate('DELETE FROM vct_owning_manytomany_compositeid_foreignkey'); + $conn->executeUpdate('DELETE FROM vct_inversed_manytomany_compositeid_foreignkey'); + $conn->executeUpdate('DELETE FROM vct_auxiliary'); + } + $this->_em->clear(); } From 4f9f7eedf5784f8d1aadf8faf6489aa9a818e430 Mon Sep 17 00:00:00 2001 From: "Jasper N. Brouwer" Date: Tue, 11 Nov 2014 14:53:09 +0100 Subject: [PATCH 02/32] Removed DDC-3380 mentions in production code --- lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 1be3ecd5b..a9e25b363 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -1773,8 +1773,6 @@ class BasicEntityPersister implements EntityPersister * Expands the parameters from the given criteria and use the correct binding types if found, * specialized for OneToMany or ManyToMany associations. * - * DDC-3380: {@see getManyToManyStatement()} and {@see getOneToManyStatement()}. - * * @param array $criteria * * @return array @@ -1799,8 +1797,6 @@ class BasicEntityPersister implements EntityPersister /** * Infers the binding type of a field by parameter type casting. * - * DDC-3380: Added optional $class argument. - * * @param string $field * @param mixed $value * @param ClassMetadata|null $class From f7b14085f2105d7dbb57597f32d1119d5f71eb62 Mon Sep 17 00:00:00 2001 From: "Jasper N. Brouwer" Date: Wed, 12 Nov 2014 15:13:17 +0100 Subject: [PATCH 03/32] Abstracted infering binding types away in a helper --- .../Collection/ManyToManyPersister.php | 4 +- .../Entity/BasicEntityPersister.php | 120 ++------------- lib/Doctrine/ORM/Utility/PersisterHelper.php | 144 ++++++++++++++++++ 3 files changed, 157 insertions(+), 111 deletions(-) create mode 100644 lib/Doctrine/ORM/Utility/PersisterHelper.php diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index 3a09079c7..448ad9904 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -25,6 +25,8 @@ use Doctrine\ORM\Persisters\SqlExpressionVisitor; use Doctrine\ORM\Persisters\SqlValueVisitor; use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\Query; +use Doctrine\ORM\UnitOfWork; +use Doctrine\ORM\Utility\PersisterHelper as Helper; /** * Persister for many-to-many collections. @@ -384,7 +386,7 @@ class ManyToManyPersister extends AbstractCollectionPersister : $sourceClass->getFieldForColumn($columnName); $params[] = $identifier[$field]; - $types[] = $this->getType($field, $sourceClass); + $types[] = Helper::getTypeOfField($field, $sourceClass, $this->em); } return array($params, $types); diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index a9e25b363..d39527128 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -863,12 +863,12 @@ class BasicEntityPersister implements EntityPersister list($params, $types) = $valueVisitor->getParamsAndTypes(); foreach ($params as $param) { - $sqlParams[] = $this->getValue($param); + $sqlParams[] = Helper::getValue($param, $this->em); } foreach ($types as $type) { list($field, $value) = $type; - $sqlTypes[] = $this->getType($field, $value); + $sqlTypes[] = $this->getType($field, $value, $this->class); } return array($sqlParams, $sqlTypes); @@ -1306,13 +1306,14 @@ class BasicEntityPersister implements EntityPersister $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); foreach ($assoc['joinColumns'] as $joinColumn) { - $type = $this->getColumnType($joinColumn['referencedColumnName'], null, $targetClass); $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 = Helper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); + $this->rsm->addMetaResult($alias, $resultColumnName, $quotedColumn, $isIdentifier, $type); } @@ -1762,8 +1763,8 @@ class BasicEntityPersister implements EntityPersister continue; // skip null values. } - $types[] = $this->getType($field, $value); - $params[] = $this->getValue($value); + $types[] = $this->getType($field, $value, $this->class); + $params[] = Helper::getValue($value, $this->em); } return array($params, $types); @@ -1788,7 +1789,7 @@ class BasicEntityPersister implements EntityPersister } $types[] = $this->getType($criterion['field'], $criterion['value'], $criterion['class']); - $params[] = $this->getValue($criterion['value']); + $params[] = Helper::getValue($criterion['value'], $this->em); } return array($params, $types); @@ -1797,7 +1798,7 @@ class BasicEntityPersister implements EntityPersister /** * Infers the binding type of a field by parameter type casting. * - * @param string $field + * @param string $fieldName * @param mixed $value * @param ClassMetadata|null $class * @@ -1805,11 +1806,9 @@ class BasicEntityPersister implements EntityPersister * * @throws \Doctrine\ORM\Query\QueryException */ - private function getType($field, $value, ClassMetadata $class = null) + private function getType($fieldName, $value, ClassMetadata $class) { - if ($class === null) { - $class = $this->class; - } + $type = Helper::getTypeOfField($fieldName, $class, $this->em); switch (true) { case (isset($this->class->fieldMappings[$field])): @@ -1867,105 +1866,6 @@ class BasicEntityPersister implements EntityPersister return $type; } - /** - * Infers the binding type of a column by parameter type casting. - * - * @param string $columnName - * @param mixed $value - * @param ClassMetadata $class - * @return int|string|null - */ - private function getColumnType($columnName, $value, ClassMetadata $class) - { - $type = null; - - switch (true) { - case (isset($class->fieldNames[$columnName])): - $fieldName = $class->fieldNames[$columnName]; - - if (isset($class->fieldMappings[$fieldName])) { - $type = $class->fieldMappings[$fieldName]['type']; - } - - break; - - default: - $type = $this->getAssociationColumnType($columnName, $class); - } - - if (is_array($value)) { - $type = Type::getType($type)->getBindingType(); - $type += Connection::ARRAY_PARAM_OFFSET; - } - - return $type; - } - - /** - * Infers the binding type of a column by traversing association mappings. - * - * @param string $columnName - * @param ClassMetadata $class - * @return string|null - */ - private function getAssociationColumnType($columnName, ClassMetadata $class) - { - foreach ($class->associationMappings as $assoc) { - foreach ($assoc['joinColumns'] as $joinColumn) { - if ($joinColumn['name'] == $columnName) { - $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); - $targetColumn = $joinColumn['referencedColumnName']; - - if (isset($targetClass->fieldNames[$targetColumn])) { - return $targetClass->fieldMappings[$targetClass->fieldNames[$targetColumn]]['type']; - } - - return $this->getAssociationColumnType($targetColumn, $class); - } - } - } - - return null; - } - - /** - * Retrieves parameter value. - * - * @param mixed $value - * - * @return mixed - */ - private function getValue($value) - { - if ( ! is_array($value)) { - return $this->getIndividualValue($value); - } - - $newValue = array(); - - foreach ($value as $itemValue) { - $newValue[] = $this->getIndividualValue($itemValue); - } - - return $newValue; - } - - /** - * Retrieves an individual parameter value. - * - * @param mixed $value - * - * @return mixed - */ - private function getIndividualValue($value) - { - if ( ! is_object($value) || ! $this->em->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($value))) { - return $value; - } - - return $this->em->getUnitOfWork()->getSingleIdentifierValue($value); - } - /** * {@inheritdoc} */ diff --git a/lib/Doctrine/ORM/Utility/PersisterHelper.php b/lib/Doctrine/ORM/Utility/PersisterHelper.php new file mode 100644 index 000000000..66a83d396 --- /dev/null +++ b/lib/Doctrine/ORM/Utility/PersisterHelper.php @@ -0,0 +1,144 @@ +. + */ + +namespace Doctrine\ORM\Utility; + +use Doctrine\Common\Persistence\Mapping\ClassMetadata; +use Doctrine\Common\Util\ClassUtils; +use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Query\QueryException; + +/** + * The PersisterHelper contains logic to infer binding types which is used in + * several persisters. + * + * @link www.doctrine-project.org + * @since 2.5 + * @author Jasper N. Brouwer + */ +class PersisterHelper +{ + /** + * @param mixed $value + * @param EntityManagerInterface $em + * + * @return mixed + */ + public static function getValue($value, EntityManagerInterface $em) + { + if ( ! is_array($value)) { + return self::getIndividualValue($value, $em); + } + + $newValue = array(); + + foreach ($value as $itemValue) { + $newValue[] = self::getIndividualValue($itemValue, $em); + } + + return $newValue; + } + + /** + * @param mixed $value + * @param EntityManagerInterface $em + * + * @return mixed + */ + private static function getIndividualValue($value, EntityManagerInterface $em) + { + if ( ! is_object($value) || ! $em->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($value))) { + return $value; + } + + return $em->getUnitOfWork()->getSingleIdentifierValue($value); + } + + /** + * @param string $fieldName + * @param ClassMetadata $class + * @param EntityManagerInterface $em + * + * @throws QueryException + * @return string|null + */ + public static function getTypeOfField($fieldName, ClassMetadata $class, EntityManagerInterface $em) + { + /** @var \Doctrine\ORM\Mapping\ClassMetadataInfo $class */ + + if (isset($class->fieldMappings[$fieldName])) { + return $class->fieldMappings[$fieldName]['type']; + } + + if ( ! isset($class->associationMappings[$fieldName])) { + return null; + } + + $assoc = $class->associationMappings[$fieldName]; + + if (count($assoc['sourceToTargetKeyColumns']) > 1) { + throw QueryException::associationPathCompositeKeyNotSupported(); + } + + $targetColumnName = $assoc['joinColumns'][0]['referencedColumnName']; + $targetClass = $em->getClassMetadata($assoc['targetEntity']); + + return self::getTypeOfColumn($targetColumnName, $targetClass, $em); + } + + /** + * @param string $columnName + * @param ClassMetadata $class + * @param EntityManagerInterface $em + * + * @return string|null + */ + public static function getTypeOfColumn($columnName, ClassMetadata $class, EntityManagerInterface $em) + { + /** @var \Doctrine\ORM\Mapping\ClassMetadataInfo $class */ + + if (isset($class->fieldNames[$columnName])) { + $fieldName = $class->fieldNames[$columnName]; + + if (isset($class->fieldMappings[$fieldName])) { + return $class->fieldMappings[$fieldName]['type']; + } + + return null; + } + + foreach ($class->associationMappings as $assoc) { + if (!isset($assoc['joinColumns'])) { + continue; + } + + foreach ($assoc['joinColumns'] as $joinColumn) { + if ($joinColumn['name'] == $columnName) { + $targetColumnName = $joinColumn['referencedColumnName']; + $targetClass = $em->getClassMetadata($assoc['targetEntity']); + + return self::getTypeOfColumn($targetColumnName, $targetClass, $em); + } + } + } + + return null; + } +} From ba3df8577b34cbf39692daf02c95f25e65278fbb Mon Sep 17 00:00:00 2001 From: "Jasper N. Brouwer" Date: Wed, 12 Nov 2014 23:04:16 +0100 Subject: [PATCH 04/32] Refined and added tests, fixed found issues - Renamed id properties so they don't coexist between entities in a test - Added tests for extra lazy one-to-many associations - Fixed production code to make tests green --- .../Entity/BasicEntityPersister.php | 11 +- .../ValueConversionType/AuxiliaryEntity.php | 2 +- ...dManyToManyCompositeIdForeignKeyEntity.php | 4 +- .../InversedManyToManyEntity.php | 2 +- ...edOneToManyCompositeIdForeignKeyEntity.php | 4 +- .../InversedOneToManyEntity.php | 2 +- .../InversedOneToManyExtraLazyEntity.php | 33 ++++++ ...sedOneToOneCompositeIdForeignKeyEntity.php | 4 +- .../InversedOneToOneEntity.php | 2 +- .../OwningManyToManyCompositeIdEntity.php | 4 +- ...gManyToManyCompositeIdForeignKeyEntity.php | 6 +- .../OwningManyToManyEntity.php | 6 +- .../OwningManyToOneCompositeIdEntity.php | 2 +- ...ngManyToOneCompositeIdForeignKeyEntity.php | 4 +- .../OwningManyToOneEntity.php | 4 +- .../OwningManyToOneExtraLazyEntity.php | 22 ++++ .../OwningOneToOneCompositeIdEntity.php | 2 +- ...ingOneToOneCompositeIdForeignKeyEntity.php | 4 +- .../OwningOneToOneEntity.php | 4 +- .../ManyToManyCompositeIdForeignKeyTest.php | 56 +++++++-- .../ManyToManyCompositeIdTest.php | 6 +- .../ValueConversionType/ManyToManyTest.php | 12 +- .../OneToManyCompositeIdForeignKeyTest.php | 54 +++++++-- .../OneToManyCompositeIdTest.php | 6 +- .../OneToManyExtraLazyTest.php | 111 ++++++++++++++++++ .../ValueConversionType/OneToManyTest.php | 12 +- .../OneToOneCompositeIdForeignKeyTest.php | 54 +++++++-- .../OneToOneCompositeIdTest.php | 6 +- .../ValueConversionType/OneToOneTest.php | 12 +- .../Doctrine/Tests/OrmFunctionalTestCase.php | 9 ++ 30 files changed, 366 insertions(+), 94 deletions(-) create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyExtraLazyEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneExtraLazyEntity.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index d39527128..740c09b40 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -1883,20 +1883,21 @@ class BasicEntityPersister implements EntityPersister . $this->getLockTablesSql(null) . ' WHERE ' . $this->getSelectConditionSQL($criteria); - list($params) = $this->expandParameters($criteria); + list($params, $types) = $this->expandParameters($criteria); if (null !== $extraConditions) { - $sql .= ' AND ' . $this->getSelectConditionCriteriaSQL($extraConditions); - list($criteriaParams, $values) = $this->expandCriteriaParameters($extraConditions); + $sql .= ' AND ' . $this->getSelectConditionCriteriaSQL($extraConditions); + list($extraParams, $extraTypes) = $this->expandCriteriaParameters($extraConditions); - $params = array_merge($params, $criteriaParams); + $params = array_merge($params, $extraParams); + $types = array_merge($types, $extraTypes); } if ($filterSql = $this->generateFilterConditionSQL($this->class, $alias)) { $sql .= ' AND ' . $filterSql; } - return (bool) $this->conn->fetchColumn($sql, $params); + return (bool) $this->conn->fetchColumn($sql, $params, 0, $types); } /** diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/AuxiliaryEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/AuxiliaryEntity.php index d37413909..89025605b 100644 --- a/tests/Doctrine/Tests/Models/ValueConversionType/AuxiliaryEntity.php +++ b/tests/Doctrine/Tests/Models/ValueConversionType/AuxiliaryEntity.php @@ -12,5 +12,5 @@ class AuxiliaryEntity * @Column(type="rot13") * @Id */ - public $id; + public $id4; } diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyCompositeIdForeignKeyEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyCompositeIdForeignKeyEntity.php index b53f559f9..9cc1a1207 100644 --- a/tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyCompositeIdForeignKeyEntity.php +++ b/tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyCompositeIdForeignKeyEntity.php @@ -14,11 +14,11 @@ class InversedManyToManyCompositeIdForeignKeyEntity * @Column(type="rot13") * @Id */ - public $id; + public $id1; /** * @ManyToOne(targetEntity="AuxiliaryEntity") - * @JoinColumn(name="foreign_id", referencedColumnName="id") + * @JoinColumn(name="foreign_id", referencedColumnName="id4") * @Id */ public $foreignEntity; diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyEntity.php index c2cab841c..3b0157655 100644 --- a/tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyEntity.php +++ b/tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyEntity.php @@ -14,7 +14,7 @@ class InversedManyToManyEntity * @Column(type="rot13") * @Id */ - public $id; + public $id1; /** * @ManyToMany(targetEntity="OwningManyToManyEntity", mappedBy="associatedEntities") diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyCompositeIdForeignKeyEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyCompositeIdForeignKeyEntity.php index 571ce8378..e2212812e 100644 --- a/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyCompositeIdForeignKeyEntity.php +++ b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyCompositeIdForeignKeyEntity.php @@ -14,11 +14,11 @@ class InversedOneToManyCompositeIdForeignKeyEntity * @Column(type="rot13") * @Id */ - public $id; + public $id1; /** * @ManyToOne(targetEntity="AuxiliaryEntity") - * @JoinColumn(name="foreign_id", referencedColumnName="id") + * @JoinColumn(name="foreign_id", referencedColumnName="id4") * @Id */ public $foreignEntity; diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyEntity.php index 8da0b10b9..ff8ec73a0 100644 --- a/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyEntity.php +++ b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyEntity.php @@ -14,7 +14,7 @@ class InversedOneToManyEntity * @Column(type="rot13") * @Id */ - public $id; + public $id1; /** * @OneToMany(targetEntity="OwningManyToOneEntity", mappedBy="associatedEntity") diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyExtraLazyEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyExtraLazyEntity.php new file mode 100644 index 000000000..26d0a58d0 --- /dev/null +++ b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToManyExtraLazyEntity.php @@ -0,0 +1,33 @@ +associatedEntities = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneCompositeIdForeignKeyEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneCompositeIdForeignKeyEntity.php index 464ca5a01..fb6d43026 100644 --- a/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneCompositeIdForeignKeyEntity.php +++ b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneCompositeIdForeignKeyEntity.php @@ -12,11 +12,11 @@ class InversedOneToOneCompositeIdForeignKeyEntity * @Column(type="rot13") * @Id */ - public $id; + public $id1; /** * @ManyToOne(targetEntity="AuxiliaryEntity") - * @JoinColumn(name="foreign_id", referencedColumnName="id") + * @JoinColumn(name="foreign_id", referencedColumnName="id4") * @Id */ public $foreignEntity; diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneEntity.php index d0483cb9c..d652908e2 100644 --- a/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneEntity.php +++ b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneEntity.php @@ -12,7 +12,7 @@ class InversedOneToOneEntity * @Column(type="rot13") * @Id */ - public $id; + public $id1; /** * @Column(type="string", name="some_property") diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyCompositeIdEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyCompositeIdEntity.php index d6d97fe03..01c08776f 100644 --- a/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyCompositeIdEntity.php +++ b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyCompositeIdEntity.php @@ -14,13 +14,13 @@ class OwningManyToManyCompositeIdEntity * @Column(type="rot13") * @Id */ - public $id; + public $id3; /** * @ManyToMany(targetEntity="InversedManyToManyCompositeIdEntity", inversedBy="associatedEntities") * @JoinTable( * name="vct_xref_manytomany_compositeid", - * joinColumns={@JoinColumn(name="owning_id", referencedColumnName="id")}, + * joinColumns={@JoinColumn(name="owning_id", referencedColumnName="id3")}, * inverseJoinColumns={ * @JoinColumn(name="inversed_id1", referencedColumnName="id1"), * @JoinColumn(name="inversed_id2", referencedColumnName="id2") diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyCompositeIdForeignKeyEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyCompositeIdForeignKeyEntity.php index 21e35b79a..abbb32d8a 100644 --- a/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyCompositeIdForeignKeyEntity.php +++ b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyCompositeIdForeignKeyEntity.php @@ -14,15 +14,15 @@ class OwningManyToManyCompositeIdForeignKeyEntity * @Column(type="rot13") * @Id */ - public $id; + public $id2; /** * @ManyToMany(targetEntity="InversedManyToManyCompositeIdForeignKeyEntity", inversedBy="associatedEntities") * @JoinTable( * name="vct_xref_manytomany_compositeid_foreignkey", - * joinColumns={@JoinColumn(name="owning_id", referencedColumnName="id")}, + * joinColumns={@JoinColumn(name="owning_id", referencedColumnName="id2")}, * inverseJoinColumns={ - * @JoinColumn(name="associated_id", referencedColumnName="id"), + * @JoinColumn(name="associated_id", referencedColumnName="id1"), * @JoinColumn(name="associated_foreign_id", referencedColumnName="foreign_id") * } * ) diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyEntity.php index b05c87874..292ff7835 100644 --- a/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyEntity.php +++ b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyEntity.php @@ -14,14 +14,14 @@ class OwningManyToManyEntity * @Column(type="rot13") * @Id */ - public $id; + public $id2; /** * @ManyToMany(targetEntity="InversedManyToManyEntity", inversedBy="associatedEntities") * @JoinTable( * name="vct_xref_manytomany", - * joinColumns={@JoinColumn(name="owning_id", referencedColumnName="id")}, - * inverseJoinColumns={@JoinColumn(name="inversed_id", referencedColumnName="id")} + * joinColumns={@JoinColumn(name="owning_id", referencedColumnName="id2")}, + * inverseJoinColumns={@JoinColumn(name="inversed_id", referencedColumnName="id1")} * ) */ public $associatedEntities; diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneCompositeIdEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneCompositeIdEntity.php index d8f8a2bab..b06b2188b 100644 --- a/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneCompositeIdEntity.php +++ b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneCompositeIdEntity.php @@ -12,7 +12,7 @@ class OwningManyToOneCompositeIdEntity * @Column(type="rot13") * @Id */ - public $id; + public $id3; /** * @ManyToOne(targetEntity="InversedOneToManyCompositeIdEntity", inversedBy="associatedEntities") diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneCompositeIdForeignKeyEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneCompositeIdForeignKeyEntity.php index 291d9cf89..b6787a418 100644 --- a/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneCompositeIdForeignKeyEntity.php +++ b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneCompositeIdForeignKeyEntity.php @@ -12,12 +12,12 @@ class OwningManyToOneCompositeIdForeignKeyEntity * @Column(type="rot13") * @Id */ - public $id; + public $id2; /** * @ManyToOne(targetEntity="InversedOneToManyCompositeIdForeignKeyEntity", inversedBy="associatedEntities") * @JoinColumns({ - * @JoinColumn(name="associated_id", referencedColumnName="id"), + * @JoinColumn(name="associated_id", referencedColumnName="id1"), * @JoinColumn(name="associated_foreign_id", referencedColumnName="foreign_id") * }) */ diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneEntity.php index 9f4afabab..b05a86b13 100644 --- a/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneEntity.php +++ b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneEntity.php @@ -12,11 +12,11 @@ class OwningManyToOneEntity * @Column(type="rot13") * @Id */ - public $id; + public $id2; /** * @ManyToOne(targetEntity="InversedOneToManyEntity", inversedBy="associatedEntities") - * @JoinColumn(name="associated_id", referencedColumnName="id") + * @JoinColumn(name="associated_id", referencedColumnName="id1") */ public $associatedEntity; } diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneExtraLazyEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneExtraLazyEntity.php new file mode 100644 index 000000000..aa4df0545 --- /dev/null +++ b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToOneExtraLazyEntity.php @@ -0,0 +1,22 @@ +id = 'abc'; + $auxiliary->id4 = 'abc'; $inversed = new Entity\InversedManyToManyCompositeIdForeignKeyEntity(); - $inversed->id = 'def'; + $inversed->id1 = 'def'; $inversed->foreignEntity = $auxiliary; $owning = new Entity\OwningManyToManyCompositeIdForeignKeyEntity(); - $owning->id = 'ghi'; + $owning->id2 = 'ghi'; $inversed->associatedEntities->add($owning); $owning->associatedEntities->add($inversed); @@ -63,10 +63,12 @@ class ManyToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase { $conn = $this->_em->getConnection(); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT id FROM vct_inversed_manytomany_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('nop', $conn->fetchColumn('SELECT id4 FROM vct_auxiliary LIMIT 1')); + + $this->assertEquals('qrs', $conn->fetchColumn('SELECT id1 FROM vct_inversed_manytomany_compositeid_foreignkey LIMIT 1')); $this->assertEquals('nop', $conn->fetchColumn('SELECT foreign_id FROM vct_inversed_manytomany_compositeid_foreignkey LIMIT 1')); - $this->assertEquals('tuv', $conn->fetchColumn('SELECT id FROM vct_owning_manytomany_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('tuv', $conn->fetchColumn('SELECT id2 FROM vct_owning_manytomany_compositeid_foreignkey LIMIT 1')); $this->assertEquals('qrs', $conn->fetchColumn('SELECT associated_id FROM vct_xref_manytomany_compositeid_foreignkey LIMIT 1')); $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_foreign_id FROM vct_xref_manytomany_compositeid_foreignkey LIMIT 1')); @@ -78,9 +80,14 @@ class ManyToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase */ public function testThatEntitiesAreFetchedFromTheDatabase() { + $auxiliary = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + 'abc' + ); + $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', - array('id' => 'def', 'foreignEntity' => 'abc') + array('id1' => 'def', 'foreignEntity' => 'abc') ); $owning = $this->_em->find( @@ -88,6 +95,7 @@ class ManyToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase 'ghi' ); + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', $auxiliary); $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', $inversed); $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity', $owning); } @@ -97,9 +105,14 @@ class ManyToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase */ public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() { + $auxiliary = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + 'abc' + ); + $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', - array('id' => 'def', 'foreignEntity' => 'abc') + array('id1' => 'def', 'foreignEntity' => 'abc') ); $owning = $this->_em->find( @@ -107,9 +120,28 @@ class ManyToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase 'ghi' ); - $this->assertEquals('def', $inversed->id); - $this->assertEquals('abc', $inversed->foreignEntity->id); - $this->assertEquals('ghi', $owning->id); + $this->assertEquals('abc', $auxiliary->id4); + $this->assertEquals('def', $inversed->id1); + $this->assertEquals('abc', $inversed->foreignEntity->id4); + $this->assertEquals('ghi', $owning->id2); + } + + /** + * @depends testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase + */ + public function testThatInversedEntityIsFetchedFromTheDatabaseUsingAuxiliaryEntityAsId() + { + $auxiliary = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + 'abc' + ); + + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', + array('id1' => 'def', 'foreignEntity' => $auxiliary) + ); + + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', $inversed); } /** @@ -132,7 +164,7 @@ class ManyToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase { $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', - array('id' => 'def', 'foreignEntity' => 'abc') + array('id1' => 'def', 'foreignEntity' => 'abc') ); $this->assertCount(1, $inversed->associatedEntities); @@ -150,7 +182,7 @@ class ManyToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', - array('id' => 'def', 'foreignEntity' => 'abc') + array('id1' => 'def', 'foreignEntity' => 'abc') ); foreach ($inversed->associatedEntities as $owning) { diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php index d0f75b4cb..a21e964a2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php @@ -32,7 +32,7 @@ class ManyToManyCompositeIdTest extends OrmFunctionalTestCase $inversed->id2 = 'def'; $owning = new Entity\OwningManyToManyCompositeIdEntity(); - $owning->id = 'ghi'; + $owning->id3 = 'ghi'; $inversed->associatedEntities->add($owning); $owning->associatedEntities->add($inversed); @@ -60,7 +60,7 @@ class ManyToManyCompositeIdTest extends OrmFunctionalTestCase $this->assertEquals('nop', $conn->fetchColumn('SELECT id1 FROM vct_inversed_manytomany_compositeid LIMIT 1')); $this->assertEquals('qrs', $conn->fetchColumn('SELECT id2 FROM vct_inversed_manytomany_compositeid LIMIT 1')); - $this->assertEquals('tuv', $conn->fetchColumn('SELECT id FROM vct_owning_manytomany_compositeid LIMIT 1')); + $this->assertEquals('tuv', $conn->fetchColumn('SELECT id3 FROM vct_owning_manytomany_compositeid LIMIT 1')); $this->assertEquals('nop', $conn->fetchColumn('SELECT inversed_id1 FROM vct_xref_manytomany_compositeid LIMIT 1')); $this->assertEquals('qrs', $conn->fetchColumn('SELECT inversed_id2 FROM vct_xref_manytomany_compositeid LIMIT 1')); @@ -103,7 +103,7 @@ class ManyToManyCompositeIdTest extends OrmFunctionalTestCase $this->assertEquals('abc', $inversed->id1); $this->assertEquals('def', $inversed->id2); - $this->assertEquals('ghi', $owning->id); + $this->assertEquals('ghi', $owning->id3); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php index 1ff8d7ab2..0d99b27e2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php @@ -28,10 +28,10 @@ class ManyToManyTest extends OrmFunctionalTestCase parent::setUp(); $inversed = new Entity\InversedManyToManyEntity(); - $inversed->id = 'abc'; + $inversed->id1 = 'abc'; $owning = new Entity\OwningManyToManyEntity(); - $owning->id = 'def'; + $owning->id2 = 'def'; $inversed->associatedEntities->add($owning); $owning->associatedEntities->add($inversed); @@ -56,9 +56,9 @@ class ManyToManyTest extends OrmFunctionalTestCase { $conn = $this->_em->getConnection(); - $this->assertEquals('nop', $conn->fetchColumn('SELECT id FROM vct_inversed_manytomany LIMIT 1')); + $this->assertEquals('nop', $conn->fetchColumn('SELECT id1 FROM vct_inversed_manytomany LIMIT 1')); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT id FROM vct_owning_manytomany LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchColumn('SELECT id2 FROM vct_owning_manytomany LIMIT 1')); $this->assertEquals('nop', $conn->fetchColumn('SELECT inversed_id FROM vct_xref_manytomany LIMIT 1')); $this->assertEquals('qrs', $conn->fetchColumn('SELECT owning_id FROM vct_xref_manytomany LIMIT 1')); @@ -98,8 +98,8 @@ class ManyToManyTest extends OrmFunctionalTestCase 'def' ); - $this->assertEquals('abc', $inversed->id); - $this->assertEquals('def', $owning->id); + $this->assertEquals('abc', $inversed->id1); + $this->assertEquals('def', $owning->id2); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php index d0f571415..dedd4dbaf 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php @@ -29,15 +29,15 @@ class OneToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase parent::setUp(); $auxiliary = new Entity\AuxiliaryEntity(); - $auxiliary->id = 'abc'; + $auxiliary->id4 = 'abc'; $inversed = new Entity\InversedOneToManyCompositeIdForeignKeyEntity(); - $inversed->id = 'def'; + $inversed->id1 = 'def'; $inversed->foreignEntity = $auxiliary; $inversed->someProperty = 'some value to be loaded'; $owning = new Entity\OwningManyToOneCompositeIdForeignKeyEntity(); - $owning->id = 'ghi'; + $owning->id2 = 'ghi'; $inversed->associatedEntities->add($owning); $owning->associatedEntity = $inversed; @@ -63,10 +63,12 @@ class OneToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase { $conn = $this->_em->getConnection(); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT id FROM vct_inversed_onetomany_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('nop', $conn->fetchColumn('SELECT id4 FROM vct_auxiliary LIMIT 1')); + + $this->assertEquals('qrs', $conn->fetchColumn('SELECT id1 FROM vct_inversed_onetomany_compositeid_foreignkey LIMIT 1')); $this->assertEquals('nop', $conn->fetchColumn('SELECT foreign_id FROM vct_inversed_onetomany_compositeid_foreignkey LIMIT 1')); - $this->assertEquals('tuv', $conn->fetchColumn('SELECT id FROM vct_owning_manytoone_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('tuv', $conn->fetchColumn('SELECT id2 FROM vct_owning_manytoone_compositeid_foreignkey LIMIT 1')); $this->assertEquals('qrs', $conn->fetchColumn('SELECT associated_id FROM vct_owning_manytoone_compositeid_foreignkey LIMIT 1')); $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_foreign_id FROM vct_owning_manytoone_compositeid_foreignkey LIMIT 1')); } @@ -76,9 +78,14 @@ class OneToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase */ public function testThatEntitiesAreFetchedFromTheDatabase() { + $auxiliary = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + 'abc' + ); + $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', - array('id' => 'def', 'foreignEntity' => 'abc') + array('id1' => 'def', 'foreignEntity' => 'abc') ); $owning = $this->_em->find( @@ -86,6 +93,7 @@ class OneToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase 'ghi' ); + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', $auxiliary); $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', $inversed); $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity', $owning); } @@ -95,9 +103,14 @@ class OneToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase */ public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() { + $auxiliary = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + 'abc' + ); + $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', - array('id' => 'def', 'foreignEntity' => 'abc') + array('id1' => 'def', 'foreignEntity' => 'abc') ); $owning = $this->_em->find( @@ -105,9 +118,28 @@ class OneToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase 'ghi' ); - $this->assertEquals('def', $inversed->id); - $this->assertEquals('abc', $inversed->foreignEntity->id); - $this->assertEquals('ghi', $owning->id); + $this->assertEquals('abc', $auxiliary->id4); + $this->assertEquals('def', $inversed->id1); + $this->assertEquals('abc', $inversed->foreignEntity->id4); + $this->assertEquals('ghi', $owning->id2); + } + + /** + * @depends testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase + */ + public function testThatInversedEntityIsFetchedFromTheDatabaseUsingAuxiliaryEntityAsId() + { + $auxiliary = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + 'abc' + ); + + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', + array('id1' => 'def', 'foreignEntity' => $auxiliary) + ); + + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', $inversed); } /** @@ -132,7 +164,7 @@ class OneToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase { $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', - array('id' => 'def', 'foreignEntity' => 'abc') + array('id1' => 'def', 'foreignEntity' => 'abc') ); $this->assertCount(1, $inversed->associatedEntities); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php index 297b46eb8..3f65e5c25 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php @@ -33,7 +33,7 @@ class OneToManyCompositeIdTest extends OrmFunctionalTestCase $inversed->someProperty = 'some value to be loaded'; $owning = new Entity\OwningManyToOneCompositeIdEntity(); - $owning->id = 'ghi'; + $owning->id3 = 'ghi'; $inversed->associatedEntities->add($owning); $owning->associatedEntity = $inversed; @@ -60,7 +60,7 @@ class OneToManyCompositeIdTest extends OrmFunctionalTestCase $this->assertEquals('nop', $conn->fetchColumn('SELECT id1 FROM vct_inversed_onetomany_compositeid LIMIT 1')); $this->assertEquals('qrs', $conn->fetchColumn('SELECT id2 FROM vct_inversed_onetomany_compositeid LIMIT 1')); - $this->assertEquals('tuv', $conn->fetchColumn('SELECT id FROM vct_owning_manytoone_compositeid LIMIT 1')); + $this->assertEquals('tuv', $conn->fetchColumn('SELECT id3 FROM vct_owning_manytoone_compositeid LIMIT 1')); $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_id1 FROM vct_owning_manytoone_compositeid LIMIT 1')); $this->assertEquals('qrs', $conn->fetchColumn('SELECT associated_id2 FROM vct_owning_manytoone_compositeid LIMIT 1')); } @@ -101,7 +101,7 @@ class OneToManyCompositeIdTest extends OrmFunctionalTestCase $this->assertEquals('abc', $inversed->id1); $this->assertEquals('def', $inversed->id2); - $this->assertEquals('ghi', $owning->id); + $this->assertEquals('ghi', $owning->id3); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php new file mode 100644 index 000000000..17429089a --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php @@ -0,0 +1,111 @@ +useModelSet('vct_onetomany_extralazy'); + parent::setUp(); + + $inversed = new Entity\InversedOneToManyExtraLazyEntity(); + $inversed->id1 = 'abc'; + + $owning1 = new Entity\OwningManyToOneExtraLazyEntity(); + $owning1->id2 = 'def'; + + $owning2 = new Entity\OwningManyToOneExtraLazyEntity(); + $owning2->id2 = 'ghi'; + + $owning3 = new Entity\OwningManyToOneExtraLazyEntity(); + $owning3->id2 = 'jkl'; + + $inversed->associatedEntities->add($owning1); + $owning1->associatedEntity = $inversed; + $inversed->associatedEntities->add($owning2); + $owning2->associatedEntity = $inversed; + $inversed->associatedEntities->add($owning3); + $owning3->associatedEntity = $inversed; + + $this->_em->persist($inversed); + $this->_em->persist($owning1); + $this->_em->persist($owning2); + $this->_em->persist($owning3); + + $this->_em->flush(); + $this->_em->clear(); + } + + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_owning_manytoone_extralazy'); + $conn->executeUpdate('DROP TABLE vct_inversed_onetomany_extralazy'); + } + + public function testThatExtraLazyCollectionIsCounted() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity', + 'abc' + ); + + $this->assertEquals(3, $inversed->associatedEntities->count()); + } + + public function testThatExtraLazyCollectionContainsAnEntity() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity', + 'abc' + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneExtraLazyEntity', + 'def' + ); + + $this->assertTrue($inversed->associatedEntities->contains($owning)); + } + + public function testThatExtraLazyCollectionContainsAnIndexbyKey() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity', + 'abc' + ); + + $this->assertTrue($inversed->associatedEntities->containsKey('def')); + } + + public function testThatASliceOfTheExtraLazyCollectionIsLoaded() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity', + 'abc' + ); + + $this->assertCount(2, $inversed->associatedEntities->slice(0, 2)); + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php index 25e9135c3..cb8d0f08a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php @@ -28,11 +28,11 @@ class OneToManyTest extends OrmFunctionalTestCase parent::setUp(); $inversed = new Entity\InversedOneToManyEntity(); - $inversed->id = 'abc'; + $inversed->id1 = 'abc'; $inversed->someProperty = 'some value to be loaded'; $owning = new Entity\OwningManyToOneEntity(); - $owning->id = 'def'; + $owning->id2 = 'def'; $inversed->associatedEntities->add($owning); $owning->associatedEntity = $inversed; @@ -56,9 +56,9 @@ class OneToManyTest extends OrmFunctionalTestCase { $conn = $this->_em->getConnection(); - $this->assertEquals('nop', $conn->fetchColumn('SELECT id FROM vct_inversed_onetomany LIMIT 1')); + $this->assertEquals('nop', $conn->fetchColumn('SELECT id1 FROM vct_inversed_onetomany LIMIT 1')); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT id FROM vct_owning_manytoone LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchColumn('SELECT id2 FROM vct_owning_manytoone LIMIT 1')); $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_id FROM vct_owning_manytoone LIMIT 1')); } @@ -96,8 +96,8 @@ class OneToManyTest extends OrmFunctionalTestCase 'def' ); - $this->assertEquals('abc', $inversed->id); - $this->assertEquals('def', $owning->id); + $this->assertEquals('abc', $inversed->id1); + $this->assertEquals('def', $owning->id2); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php index b3b58d245..fc0c6b463 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php @@ -29,15 +29,15 @@ class OneToOneCompositeIdForeignKeyTest extends OrmFunctionalTestCase parent::setUp(); $auxiliary = new Entity\AuxiliaryEntity(); - $auxiliary->id = 'abc'; + $auxiliary->id4 = 'abc'; $inversed = new Entity\InversedOneToOneCompositeIdForeignKeyEntity(); - $inversed->id = 'def'; + $inversed->id1 = 'def'; $inversed->foreignEntity = $auxiliary; $inversed->someProperty = 'some value to be loaded'; $owning = new Entity\OwningOneToOneCompositeIdForeignKeyEntity(); - $owning->id = 'ghi'; + $owning->id2 = 'ghi'; $inversed->associatedEntity = $owning; $owning->associatedEntity = $inversed; @@ -63,10 +63,12 @@ class OneToOneCompositeIdForeignKeyTest extends OrmFunctionalTestCase { $conn = $this->_em->getConnection(); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT id FROM vct_inversed_onetoone_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('nop', $conn->fetchColumn('SELECT id4 FROM vct_auxiliary LIMIT 1')); + + $this->assertEquals('qrs', $conn->fetchColumn('SELECT id1 FROM vct_inversed_onetoone_compositeid_foreignkey LIMIT 1')); $this->assertEquals('nop', $conn->fetchColumn('SELECT foreign_id FROM vct_inversed_onetoone_compositeid_foreignkey LIMIT 1')); - $this->assertEquals('tuv', $conn->fetchColumn('SELECT id FROM vct_owning_onetoone_compositeid_foreignkey LIMIT 1')); + $this->assertEquals('tuv', $conn->fetchColumn('SELECT id2 FROM vct_owning_onetoone_compositeid_foreignkey LIMIT 1')); $this->assertEquals('qrs', $conn->fetchColumn('SELECT associated_id FROM vct_owning_onetoone_compositeid_foreignkey LIMIT 1')); $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_foreign_id FROM vct_owning_onetoone_compositeid_foreignkey LIMIT 1')); } @@ -76,9 +78,14 @@ class OneToOneCompositeIdForeignKeyTest extends OrmFunctionalTestCase */ public function testThatEntitiesAreFetchedFromTheDatabase() { + $auxiliary = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + 'abc' + ); + $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', - array('id' => 'def', 'foreignEntity' => 'abc') + array('id1' => 'def', 'foreignEntity' => 'abc') ); $owning = $this->_em->find( @@ -86,6 +93,7 @@ class OneToOneCompositeIdForeignKeyTest extends OrmFunctionalTestCase 'ghi' ); + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', $auxiliary); $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', $inversed); $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity', $owning); } @@ -95,9 +103,14 @@ class OneToOneCompositeIdForeignKeyTest extends OrmFunctionalTestCase */ public function testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase() { + $auxiliary = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + 'abc' + ); + $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', - array('id' => 'def', 'foreignEntity' => 'abc') + array('id1' => 'def', 'foreignEntity' => 'abc') ); $owning = $this->_em->find( @@ -105,9 +118,28 @@ class OneToOneCompositeIdForeignKeyTest extends OrmFunctionalTestCase 'ghi' ); - $this->assertEquals('def', $inversed->id); - $this->assertEquals('abc', $inversed->foreignEntity->id); - $this->assertEquals('ghi', $owning->id); + $this->assertEquals('abc', $auxiliary->id4); + $this->assertEquals('def', $inversed->id1); + $this->assertEquals('abc', $inversed->foreignEntity->id4); + $this->assertEquals('ghi', $owning->id2); + } + + /** + * @depends testThatTheValueOfIdentifiersAreConvertedBackAfterBeingFetchedFromTheDatabase + */ + public function testThatInversedEntityIsFetchedFromTheDatabaseUsingAuxiliaryEntityAsId() + { + $auxiliary = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + 'abc' + ); + + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', + array('id1' => 'def', 'foreignEntity' => $auxiliary) + ); + + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', $inversed); } /** @@ -132,7 +164,7 @@ class OneToOneCompositeIdForeignKeyTest extends OrmFunctionalTestCase { $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', - array('id' => 'def', 'foreignEntity' => 'abc') + array('id1' => 'def', 'foreignEntity' => 'abc') ); $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity', $inversed->associatedEntity); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php index 0390eb7f5..262792169 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php @@ -33,7 +33,7 @@ class OneToOneCompositeIdTest extends OrmFunctionalTestCase $inversed->someProperty = 'some value to be loaded'; $owning = new Entity\OwningOneToOneCompositeIdEntity(); - $owning->id = 'ghi'; + $owning->id3 = 'ghi'; $inversed->associatedEntity = $owning; $owning->associatedEntity = $inversed; @@ -60,7 +60,7 @@ class OneToOneCompositeIdTest extends OrmFunctionalTestCase $this->assertEquals('nop', $conn->fetchColumn('SELECT id1 FROM vct_inversed_onetoone_compositeid LIMIT 1')); $this->assertEquals('qrs', $conn->fetchColumn('SELECT id2 FROM vct_inversed_onetoone_compositeid LIMIT 1')); - $this->assertEquals('tuv', $conn->fetchColumn('SELECT id FROM vct_owning_onetoone_compositeid LIMIT 1')); + $this->assertEquals('tuv', $conn->fetchColumn('SELECT id3 FROM vct_owning_onetoone_compositeid LIMIT 1')); $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_id1 FROM vct_owning_onetoone_compositeid LIMIT 1')); $this->assertEquals('qrs', $conn->fetchColumn('SELECT associated_id2 FROM vct_owning_onetoone_compositeid LIMIT 1')); } @@ -101,7 +101,7 @@ class OneToOneCompositeIdTest extends OrmFunctionalTestCase $this->assertEquals('abc', $inversed->id1); $this->assertEquals('def', $inversed->id2); - $this->assertEquals('ghi', $owning->id); + $this->assertEquals('ghi', $owning->id3); } /** diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php index 2cdaadcaa..fdf4fbabc 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php @@ -28,11 +28,11 @@ class OneToOneTest extends OrmFunctionalTestCase parent::setUp(); $inversed = new Entity\InversedOneToOneEntity(); - $inversed->id = 'abc'; + $inversed->id1 = 'abc'; $inversed->someProperty = 'some value to be loaded'; $owning = new Entity\OwningOneToOneEntity(); - $owning->id = 'def'; + $owning->id2 = 'def'; $inversed->associatedEntity = $owning; $owning->associatedEntity = $inversed; @@ -56,9 +56,9 @@ class OneToOneTest extends OrmFunctionalTestCase { $conn = $this->_em->getConnection(); - $this->assertEquals('nop', $conn->fetchColumn('SELECT id FROM vct_inversed_onetoone LIMIT 1')); + $this->assertEquals('nop', $conn->fetchColumn('SELECT id1 FROM vct_inversed_onetoone LIMIT 1')); - $this->assertEquals('qrs', $conn->fetchColumn('SELECT id FROM vct_owning_onetoone LIMIT 1')); + $this->assertEquals('qrs', $conn->fetchColumn('SELECT id2 FROM vct_owning_onetoone LIMIT 1')); $this->assertEquals('nop', $conn->fetchColumn('SELECT associated_id FROM vct_owning_onetoone LIMIT 1')); } @@ -96,8 +96,8 @@ class OneToOneTest extends OrmFunctionalTestCase 'def' ); - $this->assertEquals('abc', $inversed->id); - $this->assertEquals('def', $owning->id); + $this->assertEquals('abc', $inversed->id1); + $this->assertEquals('def', $owning->id2); } /** diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 0af76186c..b75137f51 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -225,6 +225,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity' ), + 'vct_onetomany_extralazy' => array( + 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneExtraLazyEntity' + ), 'vct_manytomany' => array( 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyEntity', 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyEntity' @@ -429,6 +433,11 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $conn->executeUpdate('DELETE FROM vct_auxiliary'); } + if (isset($this->_usedModelSets['vct_onetomany_extralazy'])) { + $conn->executeUpdate('DELETE FROM vct_owning_manytoone_extralazy'); + $conn->executeUpdate('DELETE FROM vct_inversed_onetomany_extralazy'); + } + if (isset($this->_usedModelSets['vct_manytomany'])) { $conn->executeUpdate('DELETE FROM vct_xref_manytomany'); $conn->executeUpdate('DELETE FROM vct_owning_manytomany'); From 7b9c6a69bd40ccaabea4756c203283c482e2156e Mon Sep 17 00:00:00 2001 From: "Jasper N. Brouwer" Date: Sat, 22 Nov 2014 11:57:10 +0100 Subject: [PATCH 05/32] Add tests for extra lazy many-to-many associations and fixed production code --- .../Collection/ManyToManyPersister.php | 40 +++-- .../InversedManyToManyExtraLazyEntity.php | 33 ++++ .../OwningManyToManyExtraLazyEntity.php | 38 +++++ .../ManyToManyExtraLazyTest.php | 160 ++++++++++++++++++ .../Doctrine/Tests/OrmFunctionalTestCase.php | 10 ++ 5 files changed, 268 insertions(+), 13 deletions(-) create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyExtraLazyEntity.php create mode 100644 tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyExtraLazyEntity.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index 448ad9904..8ebf68a16 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -534,24 +534,28 @@ class ManyToManyPersister extends AbstractCollectionPersister $indexBy = $mapping['indexBy']; $id = $this->uow->getEntityIdentifier($collection->getOwner()); - $targetEntity = $this->em->getClassMetadata($mapping['targetEntity']); + $sourceClass = $this->em->getClassMetadata($mapping['sourceEntity']); + $targetClass = $this->em->getClassMetadata($mapping['targetEntity']); - if (! $mapping['isOwningSide']) { + if ( ! $mapping['isOwningSide']) { $associationSourceClass = $this->em->getClassMetadata($mapping['targetEntity']); - $mapping = $associationSourceClass->associationMappings[$mapping['mappedBy']]; + $mapping = $associationSourceClass->associationMappings[$mapping['mappedBy']]; $joinColumns = $mapping['joinTable']['joinColumns']; - $relationMode = 'relationToTargetKeyColumns'; + $sourceRelationMode = 'relationToTargetKeyColumns'; + $targetRelationMode = 'relationToSourceKeyColumns'; } else { - $joinColumns = $mapping['joinTable']['inverseJoinColumns']; $associationSourceClass = $this->em->getClassMetadata($mapping['sourceEntity']); - $relationMode = 'relationToSourceKeyColumns'; + $joinColumns = $mapping['joinTable']['inverseJoinColumns']; + $sourceRelationMode = 'relationToSourceKeyColumns'; + $targetRelationMode = 'relationToTargetKeyColumns'; } - $quotedJoinTable = $this->quoteStrategy->getJoinTableName($mapping, $associationSourceClass, $this->platform). ' t'; + $quotedJoinTable = $this->quoteStrategy->getJoinTableName($mapping, $associationSourceClass, $this->platform) . ' t'; $whereClauses = array(); $params = array(); + $types = array(); - $joinNeeded = !in_array($indexBy, $targetEntity->identifier); + $joinNeeded = ! in_array($indexBy, $targetClass->identifier); if ($joinNeeded) { // extra join needed if indexBy is not a @id $joinConditions = array(); @@ -559,21 +563,25 @@ class ManyToManyPersister extends AbstractCollectionPersister foreach ($joinColumns as $joinTableColumn) { $joinConditions[] = 't.' . $joinTableColumn['name'] . ' = tr.' . $joinTableColumn['referencedColumnName']; } - $tableName = $this->quoteStrategy->getTableName($targetEntity, $this->platform); + $tableName = $this->quoteStrategy->getTableName($targetClass, $this->platform); $quotedJoinTable .= ' JOIN ' . $tableName . ' tr ON ' . implode(' AND ', $joinConditions); + $columnName = $targetClass->getColumnName($indexBy); - $whereClauses[] = 'tr.' . $targetEntity->getColumnName($indexBy) . ' = ?'; + $whereClauses[] = 'tr.' . $columnName . ' = ?'; $params[] = $key; - + $types[] = Helper::getTypeOfColumn($columnName, $targetClass, $this->em); } foreach ($mapping['joinTableColumns'] as $joinTableColumn) { - if (isset($mapping[$relationMode][$joinTableColumn])) { + if (isset($mapping[$sourceRelationMode][$joinTableColumn])) { + $column = $mapping[$sourceRelationMode][$joinTableColumn]; + $whereClauses[] = 't.' . $joinTableColumn . ' = ?'; $params[] = $id[$targetEntity->getFieldForColumn($mapping[$relationMode][$joinTableColumn])]; } elseif (!$joinNeeded) { $whereClauses[] = 't.' . $joinTableColumn . ' = ?'; $params[] = $key; + $types[] = Helper::getTypeOfColumn($column, $targetClass, $this->em); } } @@ -586,7 +594,7 @@ class ManyToManyPersister extends AbstractCollectionPersister } } - return array($quotedJoinTable, $whereClauses, $params); + return array($quotedJoinTable, $whereClauses, $params, $types); } /** @@ -618,6 +626,7 @@ class ManyToManyPersister extends AbstractCollectionPersister $quotedJoinTable = $this->quoteStrategy->getJoinTableName($mapping, $sourceClass, $this->platform); $whereClauses = array(); $params = array(); + $types = array(); foreach ($mapping['joinTableColumns'] as $joinTableColumn) { $whereClauses[] = ($addFilters ? 't.' : '') . $joinTableColumn . ' = ?'; @@ -625,6 +634,11 @@ class ManyToManyPersister extends AbstractCollectionPersister if (isset($mapping['relationToTargetKeyColumns'][$joinTableColumn])) { $params[] = $targetId[$targetClass->getFieldForColumn($mapping['relationToTargetKeyColumns'][$joinTableColumn])]; + $params[] = $targetClass->containsForeignIdentifier + ? $targetId[$targetClass->getFieldForColumn($column)] + : $targetId[$targetClass->fieldNames[$column]]; + $types[] = Helper::getTypeOfColumn($column, $targetClass, $this->em); + continue; } diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyExtraLazyEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyExtraLazyEntity.php new file mode 100644 index 000000000..b139fa407 --- /dev/null +++ b/tests/Doctrine/Tests/Models/ValueConversionType/InversedManyToManyExtraLazyEntity.php @@ -0,0 +1,33 @@ +associatedEntities = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyExtraLazyEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyExtraLazyEntity.php new file mode 100644 index 000000000..dda25b27d --- /dev/null +++ b/tests/Doctrine/Tests/Models/ValueConversionType/OwningManyToManyExtraLazyEntity.php @@ -0,0 +1,38 @@ +associatedEntities = new ArrayCollection(); + } +} diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php new file mode 100644 index 000000000..5d9a4dc41 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php @@ -0,0 +1,160 @@ +useModelSet('vct_manytomany_extralazy'); + parent::setUp(); + + $inversed1 = new Entity\InversedManyToManyExtraLazyEntity(); + $inversed1->id1 = 'abc'; + + $inversed2 = new Entity\InversedManyToManyExtraLazyEntity(); + $inversed2->id1 = 'def'; + + $owning1 = new Entity\OwningManyToManyExtraLazyEntity(); + $owning1->id2 = 'ghi'; + + $owning2 = new Entity\OwningManyToManyExtraLazyEntity(); + $owning2->id2 = 'jkl'; + + $inversed1->associatedEntities->add($owning1); + $owning1->associatedEntities->add($inversed1); + $inversed1->associatedEntities->add($owning2); + $owning2->associatedEntities->add($inversed1); + + $inversed2->associatedEntities->add($owning1); + $owning1->associatedEntities->add($inversed2); + $inversed2->associatedEntities->add($owning2); + $owning2->associatedEntities->add($inversed2); + + $this->_em->persist($inversed1); + $this->_em->persist($inversed2); + $this->_em->persist($owning1); + $this->_em->persist($owning2); + + $this->_em->flush(); + $this->_em->clear(); + } + + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_xref_manytomany_extralazy'); + $conn->executeUpdate('DROP TABLE vct_owning_manytomany_extralazy'); + $conn->executeUpdate('DROP TABLE vct_inversed_manytomany_extralazy'); + } + + public function testThatTheExtraLazyCollectionFromOwningToInversedIsCounted() + { + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity', + 'ghi' + ); + + $this->assertEquals(2, $owning->associatedEntities->count()); + } + + public function testThatTheExtraLazyCollectionFromInversedToOwningIsCounted() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyExtraLazyEntity', + 'abc' + ); + + $this->assertEquals(2, $inversed->associatedEntities->count()); + } + + public function testThatTheExtraLazyCollectionFromOwningToInversedContainsAnEntity() + { + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity', + 'ghi' + ); + + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyExtraLazyEntity', + 'abc' + ); + + $this->assertTrue($owning->associatedEntities->contains($inversed)); + } + + public function testThatTheExtraLazyCollectionFromInversedToOwningContainsAnEntity() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyExtraLazyEntity', + 'abc' + ); + + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity', + 'ghi' + ); + + $this->assertTrue($inversed->associatedEntities->contains($owning)); + } + + public function testThatTheExtraLazyCollectionFromOwningToInversedContainsAnIndexbyKey() + { + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity', + 'ghi' + ); + + $this->assertTrue($owning->associatedEntities->containsKey('abc')); + } + + public function testThatTheExtraLazyCollectionFromInversedToOwningContainsAnIndexbyKey() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyExtraLazyEntity', + 'abc' + ); + + $this->assertTrue($inversed->associatedEntities->containsKey('ghi')); + } + + public function testThatASliceOfTheExtraLazyCollectionFromOwningToInversedIsLoaded() + { + $owning = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity', + 'ghi' + ); + + $this->assertCount(1, $owning->associatedEntities->slice(0, 1)); + } + + public function testThatASliceOfTheExtraLazyCollectionFromInversedToOwningIsLoaded() + { + $inversed = $this->_em->find( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyExtraLazyEntity', + 'abc' + ); + + $this->assertCount(1, $inversed->associatedEntities->slice(1, 1)); + } +} diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index b75137f51..0520a15ef 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -242,6 +242,10 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity' ), + 'vct_manytomany_extralazy' => array( + 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyExtraLazyEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity' + ), ); /** @@ -457,6 +461,12 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $conn->executeUpdate('DELETE FROM vct_auxiliary'); } + if (isset($this->_usedModelSets['vct_manytomany_extralazy'])) { + $conn->executeUpdate('DELETE FROM vct_xref_manytomany_extralazy'); + $conn->executeUpdate('DELETE FROM vct_owning_manytomany_extralazy'); + $conn->executeUpdate('DELETE FROM vct_inversed_manytomany_extralazy'); + } + $this->_em->clear(); } From a0b43d0a7f669fb2a92bf8642435fd11d885fa30 Mon Sep 17 00:00:00 2001 From: "Jasper N. Brouwer" Date: Sat, 20 Dec 2014 14:26:46 +0100 Subject: [PATCH 06/32] Don't alias PersisterHelper to Helper --- .../ORM/Persisters/Collection/ManyToManyPersister.php | 10 +++++----- .../ORM/Persisters/Entity/BasicEntityPersister.php | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index 8ebf68a16..81aee6584 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -26,7 +26,7 @@ use Doctrine\ORM\Persisters\SqlValueVisitor; use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\Query; use Doctrine\ORM\UnitOfWork; -use Doctrine\ORM\Utility\PersisterHelper as Helper; +use Doctrine\ORM\Utility\PersisterHelper; /** * Persister for many-to-many collections. @@ -386,7 +386,7 @@ class ManyToManyPersister extends AbstractCollectionPersister : $sourceClass->getFieldForColumn($columnName); $params[] = $identifier[$field]; - $types[] = Helper::getTypeOfField($field, $sourceClass, $this->em); + $types[] = PersisterHelper::getTypeOfField($field, $sourceClass, $this->em); } return array($params, $types); @@ -569,7 +569,7 @@ class ManyToManyPersister extends AbstractCollectionPersister $whereClauses[] = 'tr.' . $columnName . ' = ?'; $params[] = $key; - $types[] = Helper::getTypeOfColumn($columnName, $targetClass, $this->em); + $types[] = PersisterHelper::getTypeOfColumn($columnName, $targetClass, $this->em); } foreach ($mapping['joinTableColumns'] as $joinTableColumn) { @@ -581,7 +581,7 @@ class ManyToManyPersister extends AbstractCollectionPersister } elseif (!$joinNeeded) { $whereClauses[] = 't.' . $joinTableColumn . ' = ?'; $params[] = $key; - $types[] = Helper::getTypeOfColumn($column, $targetClass, $this->em); + $types[] = PersisterHelper::getTypeOfColumn($column, $targetClass, $this->em); } } @@ -637,7 +637,7 @@ class ManyToManyPersister extends AbstractCollectionPersister $params[] = $targetClass->containsForeignIdentifier ? $targetId[$targetClass->getFieldForColumn($column)] : $targetId[$targetClass->fieldNames[$column]]; - $types[] = Helper::getTypeOfColumn($column, $targetClass, $this->em); + $types[] = PersisterHelper::getTypeOfColumn($column, $targetClass, $this->em); continue; } diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 740c09b40..4d78abf43 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -863,7 +863,7 @@ class BasicEntityPersister implements EntityPersister list($params, $types) = $valueVisitor->getParamsAndTypes(); foreach ($params as $param) { - $sqlParams[] = Helper::getValue($param, $this->em); + $sqlParams[] = PersisterHelper::getValue($param, $this->em); } foreach ($types as $type) { @@ -1312,7 +1312,7 @@ class BasicEntityPersister implements EntityPersister $columnList[] = $this->getSQLTableAlias($class->name, ($alias == 'r' ? '' : $alias) ) . '.' . $quotedColumn . ' AS ' . $resultColumnName; - $type = Helper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); + $type = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); $this->rsm->addMetaResult($alias, $resultColumnName, $quotedColumn, $isIdentifier, $type); } @@ -1764,7 +1764,7 @@ class BasicEntityPersister implements EntityPersister } $types[] = $this->getType($field, $value, $this->class); - $params[] = Helper::getValue($value, $this->em); + $params[] = PersisterHelper::getValue($value, $this->em); } return array($params, $types); @@ -1789,7 +1789,7 @@ class BasicEntityPersister implements EntityPersister } $types[] = $this->getType($criterion['field'], $criterion['value'], $criterion['class']); - $params[] = Helper::getValue($criterion['value'], $this->em); + $params[] = PersisterHelper::getValue($criterion['value'], $this->em); } return array($params, $types); From fe21f189919928c0107a9afc7fd2ea5aa4b05b37 Mon Sep 17 00:00:00 2001 From: "Jasper N. Brouwer" Date: Sat, 20 Dec 2014 14:36:09 +0100 Subject: [PATCH 07/32] Fixed doc-blocks --- lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | 4 +++- lib/Doctrine/ORM/Utility/PersisterHelper.php | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 4d78abf43..679bb7857 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -1920,7 +1920,9 @@ class BasicEntityPersister implements EntityPersister } /** - * {@inheritdoc} + * @param string $columnName + * + * @return string */ public function getSQLColumnAlias($columnName) { diff --git a/lib/Doctrine/ORM/Utility/PersisterHelper.php b/lib/Doctrine/ORM/Utility/PersisterHelper.php index 66a83d396..03d8305cc 100644 --- a/lib/Doctrine/ORM/Utility/PersisterHelper.php +++ b/lib/Doctrine/ORM/Utility/PersisterHelper.php @@ -76,8 +76,9 @@ class PersisterHelper * @param ClassMetadata $class * @param EntityManagerInterface $em * - * @throws QueryException * @return string|null + * + * @throws QueryException */ public static function getTypeOfField($fieldName, ClassMetadata $class, EntityManagerInterface $em) { From 5c1d1931b752e8ccd4c5bb6c16edb202788c87c4 Mon Sep 17 00:00:00 2001 From: "Jasper N. Brouwer" Date: Sat, 20 Dec 2014 14:38:47 +0100 Subject: [PATCH 08/32] Fixed typehints and use statements --- lib/Doctrine/ORM/Utility/PersisterHelper.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/ORM/Utility/PersisterHelper.php b/lib/Doctrine/ORM/Utility/PersisterHelper.php index 03d8305cc..5567f3fdd 100644 --- a/lib/Doctrine/ORM/Utility/PersisterHelper.php +++ b/lib/Doctrine/ORM/Utility/PersisterHelper.php @@ -20,9 +20,9 @@ namespace Doctrine\ORM\Utility; -use Doctrine\Common\Persistence\Mapping\ClassMetadata; use Doctrine\Common\Util\ClassUtils; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query\QueryException; /** @@ -49,8 +49,8 @@ class PersisterHelper $newValue = array(); - foreach ($value as $itemValue) { - $newValue[] = self::getIndividualValue($itemValue, $em); + foreach ($value as $fieldName => $fieldValue) { + $newValue[$fieldName] = self::getIndividualValue($fieldValue, $em); } return $newValue; @@ -82,8 +82,6 @@ class PersisterHelper */ public static function getTypeOfField($fieldName, ClassMetadata $class, EntityManagerInterface $em) { - /** @var \Doctrine\ORM\Mapping\ClassMetadataInfo $class */ - if (isset($class->fieldMappings[$fieldName])) { return $class->fieldMappings[$fieldName]['type']; } @@ -113,8 +111,6 @@ class PersisterHelper */ public static function getTypeOfColumn($columnName, ClassMetadata $class, EntityManagerInterface $em) { - /** @var \Doctrine\ORM\Mapping\ClassMetadataInfo $class */ - if (isset($class->fieldNames[$columnName])) { $fieldName = $class->fieldNames[$columnName]; @@ -126,7 +122,7 @@ class PersisterHelper } foreach ($class->associationMappings as $assoc) { - if (!isset($assoc['joinColumns'])) { + if ( ! isset($assoc['joinColumns'])) { continue; } From 445798ed46291f2639b3657142bd2f934d1be8a6 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 16 Jan 2015 23:33:02 +0100 Subject: [PATCH 09/32] #1178 - reverting patch and keeping tests (rebase gone awry) Also cleaning up `OrmFunctionalTestCase` --- .../Collection/ManyToManyPersister.php | 68 ++++----- .../Entity/BasicEntityPersister.php | 138 +++++++++--------- .../ORM/Functional/SchemaValidatorTest.php | 10 -- .../Doctrine/Tests/OrmFunctionalTestCase.php | 15 ++ 4 files changed, 111 insertions(+), 120 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index 81aee6584..40b1be958 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -25,8 +25,6 @@ use Doctrine\ORM\Persisters\SqlExpressionVisitor; use Doctrine\ORM\Persisters\SqlValueVisitor; use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\Query; -use Doctrine\ORM\UnitOfWork; -use Doctrine\ORM\Utility\PersisterHelper; /** * Persister for many-to-many collections. @@ -376,20 +374,22 @@ class ManyToManyPersister extends AbstractCollectionPersister $mapping = $collection->getMapping(); $identifier = $this->uow->getEntityIdentifier($collection->getOwner()); - $sourceClass = $this->em->getClassMetadata($mapping['sourceEntity']); - $params = array(); - $types = array(); - - foreach ($mapping['relationToSourceKeyColumns'] as $columnName => $refColumnName) { - $field = isset($sourceClass->fieldNames[$refColumnName]) - ? $sourceClass->fieldNames[$refColumnName] - : $sourceClass->getFieldForColumn($columnName); - - $params[] = $identifier[$field]; - $types[] = PersisterHelper::getTypeOfField($field, $sourceClass, $this->em); + // Optimization for single column identifier + if (count($mapping['relationToSourceKeyColumns']) === 1) { + return array(reset($identifier)); } - return array($params, $types); + // Composite identifier + $sourceClass = $this->em->getClassMetadata($mapping['sourceEntity']); + $params = array(); + + foreach ($mapping['relationToSourceKeyColumns'] as $columnName => $refColumnName) { + $params[] = isset($sourceClass->fieldNames[$refColumnName]) + ? $identifier[$sourceClass->fieldNames[$refColumnName]] + : $identifier[$sourceClass->getFieldForColumn($columnName)]; + } + + return $params; } /** @@ -534,28 +534,24 @@ class ManyToManyPersister extends AbstractCollectionPersister $indexBy = $mapping['indexBy']; $id = $this->uow->getEntityIdentifier($collection->getOwner()); - $sourceClass = $this->em->getClassMetadata($mapping['sourceEntity']); - $targetClass = $this->em->getClassMetadata($mapping['targetEntity']); + $targetEntity = $this->em->getClassMetadata($mapping['targetEntity']); - if ( ! $mapping['isOwningSide']) { + if (! $mapping['isOwningSide']) { $associationSourceClass = $this->em->getClassMetadata($mapping['targetEntity']); - $mapping = $associationSourceClass->associationMappings[$mapping['mappedBy']]; + $mapping = $associationSourceClass->associationMappings[$mapping['mappedBy']]; $joinColumns = $mapping['joinTable']['joinColumns']; - $sourceRelationMode = 'relationToTargetKeyColumns'; - $targetRelationMode = 'relationToSourceKeyColumns'; + $relationMode = 'relationToTargetKeyColumns'; } else { - $associationSourceClass = $this->em->getClassMetadata($mapping['sourceEntity']); $joinColumns = $mapping['joinTable']['inverseJoinColumns']; - $sourceRelationMode = 'relationToSourceKeyColumns'; - $targetRelationMode = 'relationToTargetKeyColumns'; + $associationSourceClass = $this->em->getClassMetadata($mapping['sourceEntity']); + $relationMode = 'relationToSourceKeyColumns'; } - $quotedJoinTable = $this->quoteStrategy->getJoinTableName($mapping, $associationSourceClass, $this->platform) . ' t'; + $quotedJoinTable = $this->quoteStrategy->getJoinTableName($mapping, $associationSourceClass, $this->platform). ' t'; $whereClauses = array(); $params = array(); - $types = array(); - $joinNeeded = ! in_array($indexBy, $targetClass->identifier); + $joinNeeded = !in_array($indexBy, $targetEntity->identifier); if ($joinNeeded) { // extra join needed if indexBy is not a @id $joinConditions = array(); @@ -563,25 +559,21 @@ class ManyToManyPersister extends AbstractCollectionPersister foreach ($joinColumns as $joinTableColumn) { $joinConditions[] = 't.' . $joinTableColumn['name'] . ' = tr.' . $joinTableColumn['referencedColumnName']; } - $tableName = $this->quoteStrategy->getTableName($targetClass, $this->platform); + $tableName = $this->quoteStrategy->getTableName($targetEntity, $this->platform); $quotedJoinTable .= ' JOIN ' . $tableName . ' tr ON ' . implode(' AND ', $joinConditions); - $columnName = $targetClass->getColumnName($indexBy); - $whereClauses[] = 'tr.' . $columnName . ' = ?'; + $whereClauses[] = 'tr.' . $targetEntity->getColumnName($indexBy) . ' = ?'; $params[] = $key; - $types[] = PersisterHelper::getTypeOfColumn($columnName, $targetClass, $this->em); + } foreach ($mapping['joinTableColumns'] as $joinTableColumn) { - if (isset($mapping[$sourceRelationMode][$joinTableColumn])) { - $column = $mapping[$sourceRelationMode][$joinTableColumn]; - + if (isset($mapping[$relationMode][$joinTableColumn])) { $whereClauses[] = 't.' . $joinTableColumn . ' = ?'; $params[] = $id[$targetEntity->getFieldForColumn($mapping[$relationMode][$joinTableColumn])]; } elseif (!$joinNeeded) { $whereClauses[] = 't.' . $joinTableColumn . ' = ?'; $params[] = $key; - $types[] = PersisterHelper::getTypeOfColumn($column, $targetClass, $this->em); } } @@ -594,7 +586,7 @@ class ManyToManyPersister extends AbstractCollectionPersister } } - return array($quotedJoinTable, $whereClauses, $params, $types); + return array($quotedJoinTable, $whereClauses, $params); } /** @@ -626,7 +618,6 @@ class ManyToManyPersister extends AbstractCollectionPersister $quotedJoinTable = $this->quoteStrategy->getJoinTableName($mapping, $sourceClass, $this->platform); $whereClauses = array(); $params = array(); - $types = array(); foreach ($mapping['joinTableColumns'] as $joinTableColumn) { $whereClauses[] = ($addFilters ? 't.' : '') . $joinTableColumn . ' = ?'; @@ -634,11 +625,6 @@ class ManyToManyPersister extends AbstractCollectionPersister if (isset($mapping['relationToTargetKeyColumns'][$joinTableColumn])) { $params[] = $targetId[$targetClass->getFieldForColumn($mapping['relationToTargetKeyColumns'][$joinTableColumn])]; - $params[] = $targetClass->containsForeignIdentifier - ? $targetId[$targetClass->getFieldForColumn($column)] - : $targetId[$targetClass->fieldNames[$column]]; - $types[] = PersisterHelper::getTypeOfColumn($column, $targetClass, $this->em); - continue; } diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 679bb7857..537961420 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -710,7 +710,6 @@ class BasicEntityPersister implements EntityPersister { $sql = $this->getSelectSQL($criteria, $assoc, $lockMode, $limit, null, $orderBy); list($params, $types) = $this->expandParameters($criteria); - $stmt = $this->conn->executeQuery($sql, $params, $types); if ($entity !== null) { @@ -863,12 +862,12 @@ class BasicEntityPersister implements EntityPersister list($params, $types) = $valueVisitor->getParamsAndTypes(); foreach ($params as $param) { - $sqlParams[] = PersisterHelper::getValue($param, $this->em); + $sqlParams[] = $this->getValue($param); } foreach ($types as $type) { list($field, $value) = $type; - $sqlTypes[] = $this->getType($field, $value, $this->class); + $sqlTypes[] = $this->getType($field, $value); } return array($sqlParams, $sqlTypes); @@ -966,12 +965,11 @@ class BasicEntityPersister implements EntityPersister */ private function getManyToManyStatement(array $assoc, $sourceEntity, $offset = null, $limit = null) { - $criteria = array(); - $parameters = array(); + $sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']); + $class = $sourceClass; + $association = $assoc; + $criteria = array(); - $sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']); - $class = $sourceClass; - $association = $assoc; if ( ! $assoc['isOwningSide']) { $class = $this->em->getClassMetadata($assoc['targetEntity']); @@ -986,8 +984,8 @@ class BasicEntityPersister implements EntityPersister foreach ($joinColumns as $joinColumn) { - $sourceKeyColumn = $joinColumn['referencedColumnName']; - $quotedKeyColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); + $sourceKeyColumn = $joinColumn['referencedColumnName']; + $quotedKeyColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); switch (true) { case $sourceClass->containsForeignIdentifier: @@ -1014,11 +1012,10 @@ class BasicEntityPersister implements EntityPersister } $criteria[$quotedJoinTable . '.' . $quotedKeyColumn] = $value; - $parameters[] = array('value' => $value, 'field' => $field, 'class' => $sourceClass); } $sql = $this->getSelectSQL($criteria, $assoc, null, $limit, $offset); - list($params, $types) = $this->expandToManyParameters($parameters); + list($params, $types) = $this->expandParameters($criteria); return $this->conn->executeQuery($sql, $params, $types); } @@ -1306,13 +1303,16 @@ class BasicEntityPersister implements EntityPersister $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); 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); + if (isset($targetClass->fieldNames[$joinColumn['referencedColumnName']])) { + $type = $targetClass->fieldMappings[$targetClass->fieldNames[$joinColumn['referencedColumnName']]]['type']; + } $this->rsm->addMetaResult($alias, $resultColumnName, $quotedColumn, $isIdentifier, $type); } @@ -1713,9 +1713,7 @@ class BasicEntityPersister implements EntityPersister */ private function getOneToManyStatement(array $assoc, $sourceEntity, $offset = null, $limit = null) { - $criteria = array(); - $parameters = array(); - + $criteria = array(); $owningAssoc = $this->class->associationMappings[$assoc['mappedBy']]; $sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']); @@ -1732,20 +1730,15 @@ class BasicEntityPersister implements EntityPersister } $criteria[$tableAlias . "." . $targetKeyColumn] = $value; - $parameters[] = array('value' => $value, 'field' => $field, 'class' => $sourceClass); continue; } - $field = $sourceClass->fieldNames[$sourceKeyColumn]; - $value = $sourceClass->reflFields[$field]->getValue($sourceEntity); - - $criteria[$tableAlias . "." . $targetKeyColumn] = $value; - $parameters[] = array('value' => $value, 'field' => $field, 'class' => $sourceClass); + $criteria[$tableAlias . "." . $targetKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity); } $sql = $this->getSelectSQL($criteria, $assoc, null, $limit, $offset); - list($params, $types) = $this->expandToManyParameters($parameters); + list($params, $types) = $this->expandParameters($criteria); return $this->conn->executeQuery($sql, $params, $types); } @@ -1763,53 +1756,25 @@ class BasicEntityPersister implements EntityPersister continue; // skip null values. } - $types[] = $this->getType($field, $value, $this->class); - $params[] = PersisterHelper::getValue($value, $this->em); + $types[] = $this->getType($field, $value); + $params[] = $this->getValue($value); } return array($params, $types); } /** - * Expands the parameters from the given criteria and use the correct binding types if found, - * specialized for OneToMany or ManyToMany associations. + * Infers field type to be used by parameter type casting. * - * @param array $criteria + * @param string $field + * @param mixed $value * - * @return array - */ - private function expandToManyParameters($criteria) - { - $params = array(); - $types = array(); - - foreach ($criteria as $criterion) { - if ($criterion['value'] === null) { - continue; // skip null values. - } - - $types[] = $this->getType($criterion['field'], $criterion['value'], $criterion['class']); - $params[] = PersisterHelper::getValue($criterion['value'], $this->em); - } - - return array($params, $types); - } - - /** - * Infers the binding type of a field by parameter type casting. - * - * @param string $fieldName - * @param mixed $value - * @param ClassMetadata|null $class - * - * @return int|string|null + * @return integer * * @throws \Doctrine\ORM\Query\QueryException */ - private function getType($fieldName, $value, ClassMetadata $class) + private function getType($field, $value) { - $type = Helper::getTypeOfField($fieldName, $class, $this->em); - switch (true) { case (isset($this->class->fieldMappings[$field])): $type = $this->class->fieldMappings[$field]['type']; @@ -1837,8 +1802,8 @@ class BasicEntityPersister implements EntityPersister break; - case (isset($class->associationMappings[$field])): - $assoc = $class->associationMappings[$field]; + case (isset($this->class->associationMappings[$field])): + $assoc = $this->class->associationMappings[$field]; if (count($assoc['sourceToTargetKeyColumns']) > 1) { throw Query\QueryException::associationPathCompositeKeyNotSupported(); @@ -1866,6 +1831,44 @@ class BasicEntityPersister implements EntityPersister return $type; } + /** + * Retrieves parameter value. + * + * @param mixed $value + * + * @return mixed + */ + private function getValue($value) + { + if ( ! is_array($value)) { + return $this->getIndividualValue($value); + } + + $newValue = array(); + + foreach ($value as $itemValue) { + $newValue[] = $this->getIndividualValue($itemValue); + } + + return $newValue; + } + + /** + * Retrieves an individual parameter value. + * + * @param mixed $value + * + * @return mixed + */ + private function getIndividualValue($value) + { + if ( ! is_object($value) || ! $this->em->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($value))) { + return $value; + } + + return $this->em->getUnitOfWork()->getSingleIdentifierValue($value); + } + /** * {@inheritdoc} */ @@ -1883,21 +1886,20 @@ class BasicEntityPersister implements EntityPersister . $this->getLockTablesSql(null) . ' WHERE ' . $this->getSelectConditionSQL($criteria); - list($params, $types) = $this->expandParameters($criteria); + list($params) = $this->expandParameters($criteria); if (null !== $extraConditions) { - $sql .= ' AND ' . $this->getSelectConditionCriteriaSQL($extraConditions); - list($extraParams, $extraTypes) = $this->expandCriteriaParameters($extraConditions); + $sql .= ' AND ' . $this->getSelectConditionCriteriaSQL($extraConditions); + list($criteriaParams, $values) = $this->expandCriteriaParameters($extraConditions); - $params = array_merge($params, $extraParams); - $types = array_merge($types, $extraTypes); + $params = array_merge($params, $criteriaParams); } if ($filterSql = $this->generateFilterConditionSQL($this->class, $alias)) { $sql .= ' AND ' . $filterSql; } - return (bool) $this->conn->fetchColumn($sql, $params, 0, $types); + return (bool) $this->conn->fetchColumn($sql, $params); } /** @@ -1920,9 +1922,7 @@ class BasicEntityPersister implements EntityPersister } /** - * @param string $columnName - * - * @return string + * {@inheritdoc} */ public function getSQLColumnAlias($columnName) { diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php index ad5a2dd34..948aad2ef 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php @@ -19,16 +19,6 @@ class SchemaValidatorTest extends \Doctrine\Tests\OrmFunctionalTestCase if ($modelSet == "customtype") { continue; } - - // DDC-3380: Register DBAL type for these modelsets - if (substr($modelSet, 0, 4) == 'vct_') { - if (DBALType::hasType('rot13')) { - DBALType::overrideType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } else { - DBALType::addType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } - } - $modelSets[] = array($modelSet); } return $modelSets; diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 0520a15ef..cfced6d61 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests; +use Doctrine\DBAL\Types\Type; use Doctrine\Tests\EventListener\CacheMetadataListener; use Doctrine\ORM\Cache\Logging\StatisticsCacheLogger; use Doctrine\ORM\Cache\DefaultCacheFactory; @@ -504,6 +505,8 @@ abstract class OrmFunctionalTestCase extends OrmTestCase */ protected function setUp() { + $this->setUpDBALTypes(); + $forceCreateTables = false; if ( ! isset(static::$_sharedConn)) { @@ -691,4 +694,16 @@ abstract class OrmFunctionalTestCase extends OrmTestCase { return count($this->_sqlLoggerStack->queries); } + + /** + * Configures DBAL types required in tests + */ + protected function setUpDBALTypes() + { + if (Type::hasType('rot13')) { + Type::overrideType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); + } else { + Type::addType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); + } + } } From a80532a5389fb5d53abc0648ff8e5739fe099826 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 01:40:56 +0100 Subject: [PATCH 10/32] #1178 - correcting association column type when dealing with multiple derived associations/identifier levels Since the ClassMetadata can only know about internal state, any `joinColumn` association details on the inverse side of an association need to be computed by fetching associated metadata. --- .../ORM/Persisters/Entity/BasicEntityPersister.php | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 537961420..8e83ef813 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -36,6 +36,7 @@ use Doctrine\ORM\Persisters\SqlValueVisitor; use Doctrine\ORM\Query; use Doctrine\ORM\UnitOfWork; use Doctrine\ORM\Utility\IdentifierFlattener; +use Doctrine\ORM\Utility\PersisterHelper; /** * A BasicEntityPersister maps an entity to a single table in a relational database. @@ -610,15 +611,16 @@ class BasicEntityPersister implements EntityPersister */ protected function prepareUpdateData($entity) { - $result = array(); - $uow = $this->em->getUnitOfWork(); + $versionField = null; + $result = array(); + $uow = $this->em->getUnitOfWork(); if (($versioned = $this->class->isVersioned) != false) { $versionField = $this->class->versionField; } foreach ($uow->getEntityChangeSet($entity) as $field => $change) { - if ($versioned && $versionField == $field) { + if (isset($versionField) && $versionField == $field) { continue; } @@ -668,7 +670,7 @@ class BasicEntityPersister implements EntityPersister $quotedColumn = $this->quoteStrategy->getJoinColumnName($joinColumn, $this->class, $this->platform); $this->quotedColumns[$sourceColumn] = $quotedColumn; - $this->columnTypes[$sourceColumn] = $targetClass->getTypeOfColumn($targetColumn); + $this->columnTypes[$sourceColumn] = PersisterHelper::getTypeOfColumn($targetColumn, $targetClass, $this->em); $result[$owningTable][$sourceColumn] = $newValId ? $newValId[$targetClass->getFieldForColumn($targetColumn)] : null; @@ -1426,7 +1428,7 @@ class BasicEntityPersister implements EntityPersister } if ($this->class->generatorType != ClassMetadata::GENERATOR_TYPE_IDENTITY || $this->class->identifier[0] != $name) { - $columns[] = $this->quoteStrategy->getColumnName($name, $this->class, $this->platform); + $columns[] = $this->quoteStrategy->getColumnName($name, $this->class, $this->platform); $this->columnTypes[$name] = $this->class->fieldMappings[$name]['type']; } } From aaa644395403d853c3f5a8a053658dcd11231133 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 02:45:50 +0100 Subject: [PATCH 11/32] #1178 - `PersisterHelper::getTypeOfColumn()` should not fail silently, as that makes persister bugs impossible to spot --- lib/Doctrine/ORM/Utility/PersisterHelper.php | 29 +++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Utility/PersisterHelper.php b/lib/Doctrine/ORM/Utility/PersisterHelper.php index 5567f3fdd..28b7748ed 100644 --- a/lib/Doctrine/ORM/Utility/PersisterHelper.php +++ b/lib/Doctrine/ORM/Utility/PersisterHelper.php @@ -107,7 +107,9 @@ class PersisterHelper * @param ClassMetadata $class * @param EntityManagerInterface $em * - * @return string|null + * @return string + * + * @throws \RuntimeException */ public static function getTypeOfColumn($columnName, ClassMetadata $class, EntityManagerInterface $em) { @@ -117,10 +119,9 @@ class PersisterHelper if (isset($class->fieldMappings[$fieldName])) { return $class->fieldMappings[$fieldName]['type']; } - - return null; } + // iterate over to-one association mappings foreach ($class->associationMappings as $assoc) { if ( ! isset($assoc['joinColumns'])) { continue; @@ -136,6 +137,26 @@ class PersisterHelper } } - return null; + // iterate over to-many association mappings + foreach ($class->associationMappings as $assoc) { + if ( ! (isset($assoc['joinTable']) && isset($assoc['joinTable']['joinColumns']))) { + continue; + } + + foreach ($assoc['joinTable']['joinColumns'] as $joinColumn) { + if ($joinColumn['name'] == $columnName) { + $targetColumnName = $joinColumn['referencedColumnName']; + $targetClass = $em->getClassMetadata($assoc['targetEntity']); + + return self::getTypeOfColumn($targetColumnName, $targetClass, $em); + } + } + } + + throw new \RuntimeException(sprintf( + 'Could not resolve type of column "%s" of class "%s"', + $columnName, + $class->getName() + )); } } From 91bceca7ee515994c6085ca4e4d701b51ff54715 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 02:48:05 +0100 Subject: [PATCH 12/32] #1178 - correcting collection insert/update logic to correctly cast values for custom typed columns --- .../Collection/ManyToManyPersister.php | 63 +++++++++++++------ 1 file changed, 44 insertions(+), 19 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index 40b1be958..9c4f24609 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -25,6 +25,7 @@ use Doctrine\ORM\Persisters\SqlExpressionVisitor; use Doctrine\ORM\Persisters\SqlValueVisitor; use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\Query; +use Doctrine\ORM\Utility\PersisterHelper; /** * Persister for many-to-many collections. @@ -61,15 +62,23 @@ class ManyToManyPersister extends AbstractCollectionPersister return; // ignore inverse side } - $insertSql = $this->getInsertRowSQL($collection); - $deleteSql = $this->getDeleteRowSQL($collection); + list($deleteSql, $deleteTypes) = $this->getDeleteRowSQL($collection); + list($insertSql, $insertTypes) = $this->getInsertRowSQL($collection); foreach ($collection->getDeleteDiff() as $element) { - $this->conn->executeUpdate($deleteSql, $this->getDeleteRowSQLParameters($collection, $element)); + $this->conn->executeUpdate( + $deleteSql, + $this->getDeleteRowSQLParameters($collection, $element), + $deleteTypes + ); } foreach ($collection->getInsertDiff() as $element) { - $this->conn->executeUpdate($insertSql, $this->getInsertRowSQLParameters($collection, $element)); + $this->conn->executeUpdate( + $insertSql, + $this->getInsertRowSQLParameters($collection, $element), + $insertTypes + ); } } @@ -397,24 +406,32 @@ class ManyToManyPersister extends AbstractCollectionPersister * * @param \Doctrine\ORM\PersistentCollection $collection * - * @return string + * @return string[]|string[][] ordered tuple containing the SQL to be executed and an array + * of types for bound parameters */ protected function getDeleteRowSQL(PersistentCollection $collection) { - $mapping = $collection->getMapping(); - $class = $this->em->getClassMetadata($mapping['sourceEntity']); - $columns = array(); + $mapping = $collection->getMapping(); + $class = $this->em->getClassMetadata($mapping['sourceEntity']); + $targetClass = $this->em->getClassMetadata($mapping['targetEntity']); + $columns = array(); + $types = array(); foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) { $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); + $types[] = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $class, $this->em); } foreach ($mapping['joinTable']['inverseJoinColumns'] as $joinColumn) { - $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); + $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $targetClass, $this->platform); + $types[] = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); } - return 'DELETE FROM ' . $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform) - . ' WHERE ' . implode(' = ? AND ', $columns) . ' = ?'; + return array( + 'DELETE FROM ' . $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform) + . ' WHERE ' . implode(' = ? AND ', $columns) . ' = ?', + $types, + ); } /** @@ -438,26 +455,34 @@ class ManyToManyPersister extends AbstractCollectionPersister * * @param \Doctrine\ORM\PersistentCollection $collection * - * @return string + * @return string[]|string[][] ordered tuple containing the SQL to be executed and an array + * of types for bound parameters */ protected function getInsertRowSQL(PersistentCollection $collection) { - $columns = array(); - $mapping = $collection->getMapping(); - $class = $this->em->getClassMetadata($mapping['sourceEntity']); + $columns = array(); + $types = array(); + $mapping = $collection->getMapping(); + $class = $this->em->getClassMetadata($mapping['sourceEntity']); + $targetClass = $this->em->getClassMetadata($mapping['targetEntity']); foreach ($mapping['joinTable']['joinColumns'] as $joinColumn) { - $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); + $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $targetClass, $this->platform); + $types[] = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $class, $this->em); } foreach ($mapping['joinTable']['inverseJoinColumns'] as $joinColumn) { - $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform); + $columns[] = $this->quoteStrategy->getJoinColumnName($joinColumn, $targetClass, $this->platform); + $types[] = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); } - return 'INSERT INTO ' . $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform) + return array( + 'INSERT INTO ' . $this->quoteStrategy->getJoinTableName($mapping, $class, $this->platform) . ' (' . implode(', ', $columns) . ')' . ' VALUES' - . ' (' . implode(', ', array_fill(0, count($columns), '?')) . ')'; + . ' (' . implode(', ', array_fill(0, count($columns), '?')) . ')', + $types, + ); } /** From 41900dca7628cb67d79945d37af2f641110ad5b7 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 03:40:57 +0100 Subject: [PATCH 13/32] #1178 - correctly handling initialization of collections referenced via custom DBAL types --- .../Entity/BasicEntityPersister.php | 97 ++++++++----------- 1 file changed, 43 insertions(+), 54 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 8e83ef813..f01d0a944 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -869,7 +869,7 @@ class BasicEntityPersister implements EntityPersister foreach ($types as $type) { list($field, $value) = $type; - $sqlTypes[] = $this->getType($field, $value); + $sqlTypes[] = $this->getType($field, $value, $this->class); } return array($sqlParams, $sqlTypes); @@ -971,7 +971,7 @@ class BasicEntityPersister implements EntityPersister $class = $sourceClass; $association = $assoc; $criteria = array(); - + $parameters = array(); if ( ! $assoc['isOwningSide']) { $class = $this->em->getClassMetadata($assoc['targetEntity']); @@ -1014,10 +1014,15 @@ class BasicEntityPersister implements EntityPersister } $criteria[$quotedJoinTable . '.' . $quotedKeyColumn] = $value; + $parameters[] = array( + 'value' => $value, + 'field' => $field, + 'class' => $sourceClass, + ); } $sql = $this->getSelectSQL($criteria, $assoc, null, $limit, $offset); - list($params, $types) = $this->expandParameters($criteria); + list($params, $types) = $this->expandToManyParameters($parameters); return $this->conn->executeQuery($sql, $params, $types); } @@ -1758,72 +1763,56 @@ class BasicEntityPersister implements EntityPersister continue; // skip null values. } - $types[] = $this->getType($field, $value); + $types[] = $this->getType($field, $value, $this->class); $params[] = $this->getValue($value); } return array($params, $types); } + /** + * Expands the parameters from the given criteria and use the correct binding types if found, + * specialized for OneToMany or ManyToMany associations. + * + * @param mixed[][] $criteria an array of arrays containing following: + * - field to which each criterion will be bound + * - value to be bound + * - class to which the field belongs to + * + * + * @return array + */ + private function expandToManyParameters($criteria) + { + $params = array(); + $types = array(); + + foreach ($criteria as $criterion) { + if ($criterion['value'] === null) { + continue; // skip null values. + } + + $types[] = $this->getType($criterion['field'], $criterion['value'], $criterion['class']); + $params[] = PersisterHelper::getValue($criterion['value'], $this->em); + } + + return array($params, $types); + } + /** * Infers field type to be used by parameter type casting. * - * @param string $field - * @param mixed $value + * @param string $fieldName + * @param mixed $value + * @param ClassMetadata $class * * @return integer * * @throws \Doctrine\ORM\Query\QueryException */ - private function getType($field, $value) + private function getType($fieldName, $value, ClassMetadata $class) { - switch (true) { - case (isset($this->class->fieldMappings[$field])): - $type = $this->class->fieldMappings[$field]['type']; - break; - - case (isset($this->class->associationMappings[$field]) && $this->class->associationMappings[$field]['type'] === ClassMetadata::MANY_TO_MANY): - $assoc = $this->class->associationMappings[$field]; - $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); - - if ( ! $assoc['isOwningSide']) { - $assoc = $targetClass->associationMappings[$assoc['mappedBy']]; - } - - if (count($assoc['relationToTargetKeyColumns']) > 1) { - throw Query\QueryException::associationPathCompositeKeyNotSupported(); - } - - $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); - $targetColumn = $assoc['joinTable']['inverseJoinColumns'][0]['referencedColumnName']; - $type = null; - - if (isset($targetClass->fieldNames[$targetColumn])) { - $type = $targetClass->fieldMappings[$targetClass->fieldNames[$targetColumn]]['type']; - } - - break; - - case (isset($this->class->associationMappings[$field])): - $assoc = $this->class->associationMappings[$field]; - - if (count($assoc['sourceToTargetKeyColumns']) > 1) { - throw Query\QueryException::associationPathCompositeKeyNotSupported(); - } - - $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); - $targetColumn = $assoc['joinColumns'][0]['referencedColumnName']; - $type = null; - - if (isset($targetClass->fieldNames[$targetColumn])) { - $type = $targetClass->fieldMappings[$targetClass->fieldNames[$targetColumn]]['type']; - } - - break; - - default: - $type = null; - } + $type = PersisterHelper::getTypeOfField($fieldName, $class, $this->em); if (is_array($value)) { $type = Type::getType($type)->getBindingType(); From 1e606d1ed31589bf6f83b554a99408a7730e4576 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 04:08:12 +0100 Subject: [PATCH 14/32] #1178 - adding note about `ClassMetadataInfo#getTypeOfColumn()` being unreliable/dangerous --- lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 769b80f25..bbfae15f0 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -1998,7 +1998,10 @@ class ClassMetadataInfo implements ClassMetadata * * @param string $columnName * - * @return \Doctrine\DBAL\Types\Type + * @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. */ public function getTypeOfColumn($columnName) { From c82794bff79009ee67974eed0b670b8d76e646d1 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 04:09:14 +0100 Subject: [PATCH 15/32] #1178 - handling traversal of association mapping data in lazy-loading many-to-many requests on the inverse side --- lib/Doctrine/ORM/Utility/PersisterHelper.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Utility/PersisterHelper.php b/lib/Doctrine/ORM/Utility/PersisterHelper.php index 28b7748ed..ded5e9ca0 100644 --- a/lib/Doctrine/ORM/Utility/PersisterHelper.php +++ b/lib/Doctrine/ORM/Utility/PersisterHelper.php @@ -92,11 +92,21 @@ class PersisterHelper $assoc = $class->associationMappings[$fieldName]; - if (count($assoc['sourceToTargetKeyColumns']) > 1) { + if (! $assoc['isOwningSide']) { + return self::getTypeOfField($assoc['mappedBy'], $em->getClassMetadata($assoc['targetEntity']), $em); + } + + if (($assoc['type'] & ClassMetadata::MANY_TO_MANY) > 0) { + $joinData = $assoc['joinTable']; + } else { + $joinData = $assoc; + } + + if (count($joinData['joinColumns']) > 1) { throw QueryException::associationPathCompositeKeyNotSupported(); } - $targetColumnName = $assoc['joinColumns'][0]['referencedColumnName']; + $targetColumnName = $joinData['joinColumns'][0]['referencedColumnName']; $targetClass = $em->getClassMetadata($assoc['targetEntity']); return self::getTypeOfColumn($targetColumnName, $targetClass, $em); From e39f08f6bdfd035620f29e031fa82ca74a975ca9 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 04:12:59 +0100 Subject: [PATCH 16/32] #1178 - handling correct parameter binding when counting extra-lazy collections with custom-type referenced identifiers --- .../ORM/Persisters/Collection/ManyToManyPersister.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index 9c4f24609..f21aefdf1 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -108,6 +108,7 @@ class ManyToManyPersister extends AbstractCollectionPersister { $conditions = array(); $params = array(); + $types = array(); $mapping = $collection->getMapping(); $id = $this->uow->getEntityIdentifier($collection->getOwner()); $sourceClass = $this->em->getClassMetadata($mapping['sourceEntity']); @@ -126,6 +127,7 @@ class ManyToManyPersister extends AbstractCollectionPersister $referencedName = $joinColumn['referencedColumnName']; $conditions[] = 't.' . $columnName . ' = ?'; $params[] = $id[$sourceClass->getFieldForColumn($referencedName)]; + $types[] = PersisterHelper::getTypeOfColumn($referencedName, $sourceClass, $this->em); } list($joinTargetEntitySQL, $filterSql) = $this->getFilterSql($mapping); @@ -156,7 +158,7 @@ class ManyToManyPersister extends AbstractCollectionPersister . $joinTargetEntitySQL . ' WHERE ' . implode(' AND ', $conditions); - return $this->conn->fetchColumn($sql, $params); + return $this->conn->fetchColumn($sql, $params, 0, $types); } /** From 5e49aeef6f37de17f8cfeeb4fdeee6da0243ee80 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 04:48:47 +0100 Subject: [PATCH 17/32] #1178 - handling custom types when filtering by key in extra-lazy many-to-many associations --- .../Collection/ManyToManyPersister.php | 33 +++++++++++++------ 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index f21aefdf1..5e18b557d 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -182,11 +182,11 @@ class ManyToManyPersister extends AbstractCollectionPersister throw new \BadMethodCallException("Selecting a collection by index is only supported on indexed collections."); } - list($quotedJoinTable, $whereClauses, $params) = $this->getJoinTableRestrictionsWithKey($collection, $key, true); + list($quotedJoinTable, $whereClauses, $params, $types) = $this->getJoinTableRestrictionsWithKey($collection, $key, true); $sql = 'SELECT 1 FROM ' . $quotedJoinTable . ' WHERE ' . implode(' AND ', $whereClauses); - return (bool) $this->conn->fetchColumn($sql, $params); + return (bool) $this->conn->fetchColumn($sql, $params, 0, $types); } /** @@ -552,7 +552,11 @@ class ManyToManyPersister extends AbstractCollectionPersister * @param string $key * @param boolean $addFilters Whether the filter SQL should be included or not. * - * @return array + * @return array ordered vector: + * - quoted join table name + * - where clauses to be added for filtering + * - parameters to be bound for filtering + * - types of the parameters to be bound for filtering */ private function getJoinTableRestrictionsWithKey(PersistentCollection $collection, $key, $addFilters) { @@ -560,7 +564,6 @@ class ManyToManyPersister extends AbstractCollectionPersister $mapping = $filterMapping; $indexBy = $mapping['indexBy']; $id = $this->uow->getEntityIdentifier($collection->getOwner()); - $targetEntity = $this->em->getClassMetadata($mapping['targetEntity']); if (! $mapping['isOwningSide']) { @@ -568,17 +571,20 @@ class ManyToManyPersister extends AbstractCollectionPersister $mapping = $associationSourceClass->associationMappings[$mapping['mappedBy']]; $joinColumns = $mapping['joinTable']['joinColumns']; $relationMode = 'relationToTargetKeyColumns'; + $inverseRelationMode = 'relationToSourceKeyColumns'; } else { $joinColumns = $mapping['joinTable']['inverseJoinColumns']; $associationSourceClass = $this->em->getClassMetadata($mapping['sourceEntity']); $relationMode = 'relationToSourceKeyColumns'; + $inverseRelationMode = 'relationToTargetKeyColumns'; } $quotedJoinTable = $this->quoteStrategy->getJoinTableName($mapping, $associationSourceClass, $this->platform). ' t'; $whereClauses = array(); $params = array(); + $types = array(); - $joinNeeded = !in_array($indexBy, $targetEntity->identifier); + $joinNeeded = ! in_array($indexBy, $targetEntity->identifier); if ($joinNeeded) { // extra join needed if indexBy is not a @id $joinConditions = array(); @@ -591,16 +597,23 @@ class ManyToManyPersister extends AbstractCollectionPersister $whereClauses[] = 'tr.' . $targetEntity->getColumnName($indexBy) . ' = ?'; $params[] = $key; - + $types[] = PersisterHelper::getTypeOfField($indexBy, $targetEntity, $this->em); } foreach ($mapping['joinTableColumns'] as $joinTableColumn) { if (isset($mapping[$relationMode][$joinTableColumn])) { $whereClauses[] = 't.' . $joinTableColumn . ' = ?'; - $params[] = $id[$targetEntity->getFieldForColumn($mapping[$relationMode][$joinTableColumn])]; - } elseif (!$joinNeeded) { + $column = $mapping[$relationMode][$joinTableColumn]; + $params[] = $id[$targetEntity->getFieldForColumn($mapping[$relationMode][$joinTableColumn])]; + $types[] = PersisterHelper::getTypeOfColumn($column, $targetEntity, $this->em); + } elseif ( ! $joinNeeded) { $whereClauses[] = 't.' . $joinTableColumn . ' = ?'; - $params[] = $key; + $params[] = $key; + $types[] = PersisterHelper::getTypeOfColumn( + $mapping[$inverseRelationMode][$joinTableColumn], + $targetEntity, + $this->em + ); } } @@ -613,7 +626,7 @@ class ManyToManyPersister extends AbstractCollectionPersister } } - return array($quotedJoinTable, $whereClauses, $params); + return array($quotedJoinTable, $whereClauses, $params, $types); } /** From 6e2179aa8e5fba09a06817cc43ee0ca94d82167e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 04:56:03 +0100 Subject: [PATCH 18/32] #1178 - handling custom types when filtering/removing by element in extra-lazy many-to-many associations --- .../Collection/ManyToManyPersister.php | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index 5e18b557d..002415675 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -198,11 +198,11 @@ class ManyToManyPersister extends AbstractCollectionPersister return false; } - list($quotedJoinTable, $whereClauses, $params) = $this->getJoinTableRestrictions($collection, $element, true); + list($quotedJoinTable, $whereClauses, $params, $types) = $this->getJoinTableRestrictions($collection, $element, true); $sql = 'SELECT 1 FROM ' . $quotedJoinTable . ' WHERE ' . implode(' AND ', $whereClauses); - return (bool) $this->conn->fetchColumn($sql, $params); + return (bool) $this->conn->fetchColumn($sql, $params, 0, $types); } /** @@ -214,11 +214,11 @@ class ManyToManyPersister extends AbstractCollectionPersister return false; } - list($quotedJoinTable, $whereClauses, $params) = $this->getJoinTableRestrictions($collection, $element, false); + list($quotedJoinTable, $whereClauses, $params, $types) = $this->getJoinTableRestrictions($collection, $element, false); $sql = 'DELETE FROM ' . $quotedJoinTable . ' WHERE ' . implode(' AND ', $whereClauses); - return (bool) $this->conn->executeUpdate($sql, $params); + return (bool) $this->conn->executeUpdate($sql, $params, $types); } /** @@ -634,7 +634,11 @@ class ManyToManyPersister extends AbstractCollectionPersister * @param object $element * @param boolean $addFilters Whether the filter SQL should be included or not. * - * @return array + * @return array ordered vector: + * - quoted join table name + * - where clauses to be added for filtering + * - parameters to be bound for filtering + * - types of the parameters to be bound for filtering */ private function getJoinTableRestrictions(PersistentCollection $collection, $element, $addFilters) { @@ -658,18 +662,23 @@ class ManyToManyPersister extends AbstractCollectionPersister $quotedJoinTable = $this->quoteStrategy->getJoinTableName($mapping, $sourceClass, $this->platform); $whereClauses = array(); $params = array(); + $types = array(); foreach ($mapping['joinTableColumns'] as $joinTableColumn) { $whereClauses[] = ($addFilters ? 't.' : '') . $joinTableColumn . ' = ?'; if (isset($mapping['relationToTargetKeyColumns'][$joinTableColumn])) { - $params[] = $targetId[$targetClass->getFieldForColumn($mapping['relationToTargetKeyColumns'][$joinTableColumn])]; + $targetColumn = $mapping['relationToTargetKeyColumns'][$joinTableColumn]; + $params[] = $targetId[$targetClass->getFieldForColumn($targetColumn)]; + $types[] = PersisterHelper::getTypeOfColumn($targetColumn, $targetClass, $this->em); continue; } // relationToSourceKeyColumns - $params[] = $sourceId[$sourceClass->getFieldForColumn($mapping['relationToSourceKeyColumns'][$joinTableColumn])]; + $targetColumn = $mapping['relationToSourceKeyColumns'][$joinTableColumn]; + $params[] = $sourceId[$sourceClass->getFieldForColumn($targetColumn)]; + $types[] = PersisterHelper::getTypeOfColumn($targetColumn, $targetClass, $this->em); } if ($addFilters) { @@ -683,7 +692,7 @@ class ManyToManyPersister extends AbstractCollectionPersister } } - return array($quotedJoinTable, $whereClauses, $params); + return array($quotedJoinTable, $whereClauses, $params, $types); } /** From 4eaa7ea82185c0c6973dd6d8c6dd77dd624fb680 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 05:02:28 +0100 Subject: [PATCH 19/32] #1178 - correcting class from which the type of a column should be fetched (source class when `relationToSourceKeyColumns` is used) --- lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index 002415675..606563d46 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -678,7 +678,7 @@ class ManyToManyPersister extends AbstractCollectionPersister // relationToSourceKeyColumns $targetColumn = $mapping['relationToSourceKeyColumns'][$joinTableColumn]; $params[] = $sourceId[$sourceClass->getFieldForColumn($targetColumn)]; - $types[] = PersisterHelper::getTypeOfColumn($targetColumn, $targetClass, $this->em); + $types[] = PersisterHelper::getTypeOfColumn($targetColumn, $sourceClass, $this->em); } if ($addFilters) { From 0743238b43eb53609a7afbe892a1a62f8bc09ffe Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 05:10:13 +0100 Subject: [PATCH 20/32] #1178 - minor code duplication removal --- lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index 606563d46..86e7b0923 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -604,7 +604,7 @@ class ManyToManyPersister extends AbstractCollectionPersister if (isset($mapping[$relationMode][$joinTableColumn])) { $whereClauses[] = 't.' . $joinTableColumn . ' = ?'; $column = $mapping[$relationMode][$joinTableColumn]; - $params[] = $id[$targetEntity->getFieldForColumn($mapping[$relationMode][$joinTableColumn])]; + $params[] = $id[$targetEntity->getFieldForColumn($column)]; $types[] = PersisterHelper::getTypeOfColumn($column, $targetEntity, $this->em); } elseif ( ! $joinNeeded) { $whereClauses[] = 't.' . $joinTableColumn . ' = ?'; From e5c4e6576488a948903075ec5eed28ce0e4bc588 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 05:38:37 +0100 Subject: [PATCH 21/32] #1178 - proxy identifiers should be correctly converted --- .../ValueConversionType/OneToManyCompositeIdForeignKeyTest.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php index dedd4dbaf..656847a15 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php @@ -154,6 +154,8 @@ class OneToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase $inversedProxy = $owning->associatedEntity; + $this->assertSame('def', $inversedProxy->id1, 'Proxy identifier is converted'); + $this->assertEquals('some value to be loaded', $inversedProxy->someProperty); } From 096bd90aed37dc7475d7f3f26f82d2bdee9f9200 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 05:39:02 +0100 Subject: [PATCH 22/32] #1178 - using the `PersisterHelper` to extract type of associated meta-result columns --- lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index f01d0a944..69691b9d3 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -1316,10 +1316,7 @@ class BasicEntityPersister implements EntityPersister $resultColumnName = $this->getSQLColumnAlias($joinColumn['name']); $columnList[] = $this->getSQLTableAlias($class->name, ($alias == 'r' ? '' : $alias) ) . '.' . $quotedColumn . ' AS ' . $resultColumnName; - - if (isset($targetClass->fieldNames[$joinColumn['referencedColumnName']])) { - $type = $targetClass->fieldMappings[$targetClass->fieldNames[$joinColumn['referencedColumnName']]]['type']; - } + $type = PersisterHelper::getTypeOfColumn($joinColumn['referencedColumnName'], $targetClass, $this->em); $this->rsm->addMetaResult($alias, $resultColumnName, $quotedColumn, $isIdentifier, $type); } From ce446a6f033ca46fc65911e6f40299336ddace74 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 05:55:16 +0100 Subject: [PATCH 23/32] #1178 - correcting filtering when initializing a one-to-many collection that has composite complex (custom DBAL types) identifiers --- .../Collection/OneToManyPersister.php | 12 ++++++- .../Entity/BasicEntityPersister.php | 33 ++++++++++++++----- 2 files changed, 35 insertions(+), 10 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php index ee550a922..9b14afde5 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php @@ -67,7 +67,17 @@ class OneToManyPersister extends AbstractCollectionPersister $persister = $this->uow->getEntityPersister($mapping['targetEntity']); - return $persister->load(array($mapping['mappedBy'] => $collection->getOwner(), $mapping['indexBy'] => $index), null, $mapping, array(), null, 1); + return $persister->load( + array( + $mapping['mappedBy'] => $collection->getOwner(), + $mapping['indexBy'] => $index + ), + null, + $mapping, + array(), + null, + 1 + ); } /** diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 69691b9d3..35be15752 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -864,7 +864,7 @@ class BasicEntityPersister implements EntityPersister list($params, $types) = $valueVisitor->getParamsAndTypes(); foreach ($params as $param) { - $sqlParams[] = $this->getValue($param); + $sqlParams[] = PersisterHelper::getValue($param, $this->em); } foreach ($types as $type) { @@ -1717,7 +1717,8 @@ class BasicEntityPersister implements EntityPersister */ private function getOneToManyStatement(array $assoc, $sourceEntity, $offset = null, $limit = null) { - $criteria = array(); + $criteria = array(); + $parameters = array(); $owningAssoc = $this->class->associationMappings[$assoc['mappedBy']]; $sourceClass = $this->em->getClassMetadata($assoc['sourceEntity']); @@ -1734,15 +1735,29 @@ class BasicEntityPersister implements EntityPersister } $criteria[$tableAlias . "." . $targetKeyColumn] = $value; + $parameters[] = array( + 'value' => $value, + 'field' => $field, + 'class' => $sourceClass, + ); continue; } - $criteria[$tableAlias . "." . $targetKeyColumn] = $sourceClass->reflFields[$sourceClass->fieldNames[$sourceKeyColumn]]->getValue($sourceEntity); + $field = $sourceClass->fieldNames[$sourceKeyColumn]; + $value = $sourceClass->reflFields[$field]->getValue($sourceEntity); + + $criteria[$tableAlias . "." . $targetKeyColumn] = $value; + $parameters[] = array( + 'value' => $value, + 'field' => $field, + 'class' => $sourceClass, + ); + } - $sql = $this->getSelectSQL($criteria, $assoc, null, $limit, $offset); - list($params, $types) = $this->expandParameters($criteria); + $sql = $this->getSelectSQL($criteria, $assoc, null, $limit, $offset); + list($params, $types) = $this->expandToManyParameters($parameters); return $this->conn->executeQuery($sql, $params, $types); } @@ -1874,11 +1889,11 @@ class BasicEntityPersister implements EntityPersister . $this->getLockTablesSql(null) . ' WHERE ' . $this->getSelectConditionSQL($criteria); - list($params) = $this->expandParameters($criteria); + list($params, $types) = $this->expandParameters($criteria); if (null !== $extraConditions) { - $sql .= ' AND ' . $this->getSelectConditionCriteriaSQL($extraConditions); - list($criteriaParams, $values) = $this->expandCriteriaParameters($extraConditions); + $sql .= ' AND ' . $this->getSelectConditionCriteriaSQL($extraConditions); + list($criteriaParams, $types) = $this->expandCriteriaParameters($extraConditions); $params = array_merge($params, $criteriaParams); } @@ -1887,7 +1902,7 @@ class BasicEntityPersister implements EntityPersister $sql .= ' AND ' . $filterSql; } - return (bool) $this->conn->fetchColumn($sql, $params); + return (bool) $this->conn->fetchColumn($sql, $params, 0, $types); } /** From a39b6869ca760d40edb98b5af3c9034ce426eaa7 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 06:07:36 +0100 Subject: [PATCH 24/32] #1178 - mapping between criteria parameters and types when fetching on one-to-many with additional criterions --- lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 35be15752..33854b3e2 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -1892,10 +1892,11 @@ class BasicEntityPersister implements EntityPersister list($params, $types) = $this->expandParameters($criteria); if (null !== $extraConditions) { - $sql .= ' AND ' . $this->getSelectConditionCriteriaSQL($extraConditions); - list($criteriaParams, $types) = $this->expandCriteriaParameters($extraConditions); + $sql .= ' AND ' . $this->getSelectConditionCriteriaSQL($extraConditions); + list($criteriaParams, $criteriaTypes) = $this->expandCriteriaParameters($extraConditions); $params = array_merge($params, $criteriaParams); + $types = array_merge($types, $criteriaTypes); } if ($filterSql = $this->generateFilterConditionSQL($this->class, $alias)) { From f88f5ce4549a8468cea2c3364e96fee2be42d1ea Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 06:21:16 +0100 Subject: [PATCH 25/32] #1178 - fetching actual target entity when resolving column types of it --- .../ORM/Persisters/Collection/ManyToManyPersister.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index 86e7b0923..bccf33dcc 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -602,10 +602,11 @@ class ManyToManyPersister extends AbstractCollectionPersister foreach ($mapping['joinTableColumns'] as $joinTableColumn) { if (isset($mapping[$relationMode][$joinTableColumn])) { - $whereClauses[] = 't.' . $joinTableColumn . ' = ?'; - $column = $mapping[$relationMode][$joinTableColumn]; - $params[] = $id[$targetEntity->getFieldForColumn($column)]; - $types[] = PersisterHelper::getTypeOfColumn($column, $targetEntity, $this->em); + $whereClauses[] = 't.' . $joinTableColumn . ' = ?'; + $column = $mapping[$relationMode][$joinTableColumn]; + $columnOwningClass = $this->em->getClassMetadata($mapping['targetEntity']); + $params[] = $id[$columnOwningClass->getFieldForColumn($column)]; + $types[] = PersisterHelper::getTypeOfColumn($column, $columnOwningClass, $this->em); } elseif ( ! $joinNeeded) { $whereClauses[] = 't.' . $joinTableColumn . ' = ?'; $params[] = $key; From d47f724f1656d99506721f55433833998855f77f Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 06:37:56 +0100 Subject: [PATCH 26/32] #1178 - restoring correct `getJoinTableRestrictionsWithKey` logic as per @jaspernbrouwer's previous implementation --- .../Collection/ManyToManyPersister.php | 60 ++++++++++--------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index bccf33dcc..a421b9112 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -560,23 +560,24 @@ class ManyToManyPersister extends AbstractCollectionPersister */ private function getJoinTableRestrictionsWithKey(PersistentCollection $collection, $key, $addFilters) { - $filterMapping = $collection->getMapping(); - $mapping = $filterMapping; - $indexBy = $mapping['indexBy']; - $id = $this->uow->getEntityIdentifier($collection->getOwner()); - $targetEntity = $this->em->getClassMetadata($mapping['targetEntity']); + $filterMapping = $collection->getMapping(); + $mapping = $filterMapping; + $indexBy = $mapping['indexBy']; + $id = $this->uow->getEntityIdentifier($collection->getOwner()); + $sourceClass = $this->em->getClassMetadata($mapping['sourceEntity']); + $targetClass = $this->em->getClassMetadata($mapping['targetEntity']); if (! $mapping['isOwningSide']) { $associationSourceClass = $this->em->getClassMetadata($mapping['targetEntity']); - $mapping = $associationSourceClass->associationMappings[$mapping['mappedBy']]; - $joinColumns = $mapping['joinTable']['joinColumns']; - $relationMode = 'relationToTargetKeyColumns'; - $inverseRelationMode = 'relationToSourceKeyColumns'; + $mapping = $associationSourceClass->associationMappings[$mapping['mappedBy']]; + $joinColumns = $mapping['joinTable']['joinColumns']; + $sourceRelationMode = 'relationToTargetKeyColumns'; + $targetRelationMode = 'relationToSourceKeyColumns'; } else { - $joinColumns = $mapping['joinTable']['inverseJoinColumns']; $associationSourceClass = $this->em->getClassMetadata($mapping['sourceEntity']); - $relationMode = 'relationToSourceKeyColumns'; - $inverseRelationMode = 'relationToTargetKeyColumns'; + $joinColumns = $mapping['joinTable']['inverseJoinColumns']; + $sourceRelationMode = 'relationToSourceKeyColumns'; + $targetRelationMode = 'relationToTargetKeyColumns'; } $quotedJoinTable = $this->quoteStrategy->getJoinTableName($mapping, $associationSourceClass, $this->platform). ' t'; @@ -584,7 +585,7 @@ class ManyToManyPersister extends AbstractCollectionPersister $params = array(); $types = array(); - $joinNeeded = ! in_array($indexBy, $targetEntity->identifier); + $joinNeeded = ! in_array($indexBy, $targetClass->identifier); if ($joinNeeded) { // extra join needed if indexBy is not a @id $joinConditions = array(); @@ -592,29 +593,30 @@ class ManyToManyPersister extends AbstractCollectionPersister foreach ($joinColumns as $joinTableColumn) { $joinConditions[] = 't.' . $joinTableColumn['name'] . ' = tr.' . $joinTableColumn['referencedColumnName']; } - $tableName = $this->quoteStrategy->getTableName($targetEntity, $this->platform); - $quotedJoinTable .= ' JOIN ' . $tableName . ' tr ON ' . implode(' AND ', $joinConditions); - $whereClauses[] = 'tr.' . $targetEntity->getColumnName($indexBy) . ' = ?'; - $params[] = $key; - $types[] = PersisterHelper::getTypeOfField($indexBy, $targetEntity, $this->em); + $tableName = $this->quoteStrategy->getTableName($targetClass, $this->platform); + $quotedJoinTable .= ' JOIN ' . $tableName . ' tr ON ' . implode(' AND ', $joinConditions); + $columnName = $targetClass->getColumnName($indexBy); + + $whereClauses[] = 'tr.' . $columnName . ' = ?'; + $params[] = $key; + $types[] = PersisterHelper::getTypeOfColumn($columnName, $targetClass, $this->em); } foreach ($mapping['joinTableColumns'] as $joinTableColumn) { - if (isset($mapping[$relationMode][$joinTableColumn])) { - $whereClauses[] = 't.' . $joinTableColumn . ' = ?'; - $column = $mapping[$relationMode][$joinTableColumn]; - $columnOwningClass = $this->em->getClassMetadata($mapping['targetEntity']); - $params[] = $id[$columnOwningClass->getFieldForColumn($column)]; - $types[] = PersisterHelper::getTypeOfColumn($column, $columnOwningClass, $this->em); + if (isset($mapping[$sourceRelationMode][$joinTableColumn])) { + $column = $mapping[$sourceRelationMode][$joinTableColumn]; + $whereClauses[] = 't.' . $joinTableColumn . ' = ?'; + $params[] = $sourceClass->containsForeignIdentifier + ? $id[$sourceClass->getFieldForColumn($column)] + : $id[$sourceClass->fieldNames[$column]]; + $types[] = PersisterHelper::getTypeOfColumn($column, $sourceClass, $this->em); } elseif ( ! $joinNeeded) { + $column = $mapping[$targetRelationMode][$joinTableColumn]; + $whereClauses[] = 't.' . $joinTableColumn . ' = ?'; $params[] = $key; - $types[] = PersisterHelper::getTypeOfColumn( - $mapping[$inverseRelationMode][$joinTableColumn], - $targetEntity, - $this->em - ); + $types[] = PersisterHelper::getTypeOfColumn($column, $targetClass, $this->em); } } From b32c779c372f6b02df2c8db94153680863a82647 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 06:38:24 +0100 Subject: [PATCH 27/32] #1178 - minor typo (method names) --- .../ValueConversionType/ManyToManyExtraLazyTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php index 5d9a4dc41..5d3173f40 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php @@ -118,7 +118,7 @@ class ManyToManyExtraLazyTest extends OrmFunctionalTestCase $this->assertTrue($inversed->associatedEntities->contains($owning)); } - public function testThatTheExtraLazyCollectionFromOwningToInversedContainsAnIndexbyKey() + public function testThatTheExtraLazyCollectionFromOwningToInversedContainsAnIndexByKey() { $owning = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity', @@ -128,7 +128,7 @@ class ManyToManyExtraLazyTest extends OrmFunctionalTestCase $this->assertTrue($owning->associatedEntities->containsKey('abc')); } - public function testThatTheExtraLazyCollectionFromInversedToOwningContainsAnIndexbyKey() + public function testThatTheExtraLazyCollectionFromInversedToOwningContainsAnIndexByKey() { $inversed = $this->_em->find( 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyExtraLazyEntity', From edf054cd0c6ff76a7752c132d6d3d3fb7bcb0c5c Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 06:41:03 +0100 Subject: [PATCH 28/32] #1178 - removing duplicate configuration of the rot13 DBAL type --- .../ManyToManyCompositeIdForeignKeyTest.php | 7 +------ .../ValueConversionType/ManyToManyCompositeIdTest.php | 7 +------ .../ValueConversionType/ManyToManyExtraLazyTest.php | 6 ------ .../ORM/Functional/ValueConversionType/ManyToManyTest.php | 7 +------ .../OneToManyCompositeIdForeignKeyTest.php | 7 +------ .../ValueConversionType/OneToManyCompositeIdTest.php | 7 +------ .../ValueConversionType/OneToManyExtraLazyTest.php | 7 +------ .../ORM/Functional/ValueConversionType/OneToManyTest.php | 7 +------ .../OneToOneCompositeIdForeignKeyTest.php | 6 ------ .../ValueConversionType/OneToOneCompositeIdTest.php | 6 ------ .../ORM/Functional/ValueConversionType/OneToOneTest.php | 7 +------ 11 files changed, 8 insertions(+), 66 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php index 21e281219..877d1a279 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php @@ -19,13 +19,8 @@ class ManyToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase { public function setUp() { - if (DBALType::hasType('rot13')) { - DBALType::overrideType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } else { - DBALType::addType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } - $this->useModelSet('vct_manytomany_compositeid_foreignkey'); + parent::setUp(); $auxiliary = new Entity\AuxiliaryEntity(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php index a21e964a2..6b56073a3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php @@ -18,13 +18,8 @@ class ManyToManyCompositeIdTest extends OrmFunctionalTestCase { public function setUp() { - if (DBALType::hasType('rot13')) { - DBALType::overrideType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } else { - DBALType::addType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } - $this->useModelSet('vct_manytomany_compositeid'); + parent::setUp(); $inversed = new Entity\InversedManyToManyCompositeIdEntity(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php index 5d3173f40..3d1df24b8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php @@ -19,12 +19,6 @@ class ManyToManyExtraLazyTest extends OrmFunctionalTestCase { public function setUp() { - if (DBALType::hasType('rot13')) { - DBALType::overrideType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } else { - DBALType::addType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } - $this->useModelSet('vct_manytomany_extralazy'); parent::setUp(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php index 0d99b27e2..66193fb14 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php @@ -18,13 +18,8 @@ class ManyToManyTest extends OrmFunctionalTestCase { public function setUp() { - if (DBALType::hasType('rot13')) { - DBALType::overrideType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } else { - DBALType::addType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } - $this->useModelSet('vct_manytomany'); + parent::setUp(); $inversed = new Entity\InversedManyToManyEntity(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php index 656847a15..17a8ea873 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php @@ -19,13 +19,8 @@ class OneToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase { public function setUp() { - if (DBALType::hasType('rot13')) { - DBALType::overrideType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } else { - DBALType::addType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } - $this->useModelSet('vct_onetomany_compositeid_foreignkey'); + parent::setUp(); $auxiliary = new Entity\AuxiliaryEntity(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php index 3f65e5c25..c094afa78 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php @@ -18,13 +18,8 @@ class OneToManyCompositeIdTest extends OrmFunctionalTestCase { public function setUp() { - if (DBALType::hasType('rot13')) { - DBALType::overrideType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } else { - DBALType::addType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } - $this->useModelSet('vct_onetomany_compositeid'); + parent::setUp(); $inversed = new Entity\InversedOneToManyCompositeIdEntity(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php index 17429089a..bb9006782 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php @@ -19,13 +19,8 @@ class OneToManyExtraLazyTest extends OrmFunctionalTestCase { public function setUp() { - if (DBALType::hasType('rot13')) { - DBALType::overrideType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } else { - DBALType::addType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } - $this->useModelSet('vct_onetomany_extralazy'); + parent::setUp(); $inversed = new Entity\InversedOneToManyExtraLazyEntity(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php index cb8d0f08a..e83453714 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php @@ -18,13 +18,8 @@ class OneToManyTest extends OrmFunctionalTestCase { public function setUp() { - if (DBALType::hasType('rot13')) { - DBALType::overrideType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } else { - DBALType::addType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } - $this->useModelSet('vct_onetomany'); + parent::setUp(); $inversed = new Entity\InversedOneToManyEntity(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php index fc0c6b463..4a595c21f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php @@ -19,12 +19,6 @@ class OneToOneCompositeIdForeignKeyTest extends OrmFunctionalTestCase { public function setUp() { - if (DBALType::hasType('rot13')) { - DBALType::overrideType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } else { - DBALType::addType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } - $this->useModelSet('vct_onetoone_compositeid_foreignkey'); parent::setUp(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php index 262792169..96daa6016 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php @@ -18,12 +18,6 @@ class OneToOneCompositeIdTest extends OrmFunctionalTestCase { public function setUp() { - if (DBALType::hasType('rot13')) { - DBALType::overrideType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } else { - DBALType::addType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } - $this->useModelSet('vct_onetoone_compositeid'); parent::setUp(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php index fdf4fbabc..15e45f9fe 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php @@ -18,13 +18,8 @@ class OneToOneTest extends OrmFunctionalTestCase { public function setUp() { - if (DBALType::hasType('rot13')) { - DBALType::overrideType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } else { - DBALType::addType('rot13', 'Doctrine\Tests\DbalTypes\Rot13Type'); - } - $this->useModelSet('vct_onetoone'); + parent::setUp(); $inversed = new Entity\InversedOneToOneEntity(); From 584839d38a8f7dea22133d98a0948deb31d9dca5 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 06:44:01 +0100 Subject: [PATCH 29/32] #1178 - moved private method to the bottom of the class --- lib/Doctrine/ORM/Utility/PersisterHelper.php | 72 ++++++++++---------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/lib/Doctrine/ORM/Utility/PersisterHelper.php b/lib/Doctrine/ORM/Utility/PersisterHelper.php index ded5e9ca0..a5ba6bd1f 100644 --- a/lib/Doctrine/ORM/Utility/PersisterHelper.php +++ b/lib/Doctrine/ORM/Utility/PersisterHelper.php @@ -35,42 +35,6 @@ use Doctrine\ORM\Query\QueryException; */ class PersisterHelper { - /** - * @param mixed $value - * @param EntityManagerInterface $em - * - * @return mixed - */ - public static function getValue($value, EntityManagerInterface $em) - { - if ( ! is_array($value)) { - return self::getIndividualValue($value, $em); - } - - $newValue = array(); - - foreach ($value as $fieldName => $fieldValue) { - $newValue[$fieldName] = self::getIndividualValue($fieldValue, $em); - } - - return $newValue; - } - - /** - * @param mixed $value - * @param EntityManagerInterface $em - * - * @return mixed - */ - private static function getIndividualValue($value, EntityManagerInterface $em) - { - if ( ! is_object($value) || ! $em->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($value))) { - return $value; - } - - return $em->getUnitOfWork()->getSingleIdentifierValue($value); - } - /** * @param string $fieldName * @param ClassMetadata $class @@ -169,4 +133,40 @@ class PersisterHelper $class->getName() )); } + + /** + * @param mixed $value + * @param EntityManagerInterface $em + * + * @return mixed + */ + public static function getValue($value, EntityManagerInterface $em) + { + if ( ! is_array($value)) { + return self::getIndividualValue($value, $em); + } + + $newValue = array(); + + foreach ($value as $fieldName => $fieldValue) { + $newValue[$fieldName] = self::getIndividualValue($fieldValue, $em); + } + + return $newValue; + } + + /** + * @param mixed $value + * @param EntityManagerInterface $em + * + * @return mixed + */ + private static function getIndividualValue($value, EntityManagerInterface $em) + { + if ( ! is_object($value) || ! $em->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($value))) { + return $value; + } + + return $em->getUnitOfWork()->getSingleIdentifierValue($value); + } } From 131a39bad43216d69549a47d9da6cdc37234031a Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 06:44:57 +0100 Subject: [PATCH 30/32] #1178 - s/getValue/getIdentifierValues --- lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php | 4 ++-- lib/Doctrine/ORM/Utility/PersisterHelper.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php index 33854b3e2..c53e817c1 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php @@ -864,7 +864,7 @@ class BasicEntityPersister implements EntityPersister list($params, $types) = $valueVisitor->getParamsAndTypes(); foreach ($params as $param) { - $sqlParams[] = PersisterHelper::getValue($param, $this->em); + $sqlParams[] = PersisterHelper::getIdentifierValues($param, $this->em); } foreach ($types as $type) { @@ -1805,7 +1805,7 @@ class BasicEntityPersister implements EntityPersister } $types[] = $this->getType($criterion['field'], $criterion['value'], $criterion['class']); - $params[] = PersisterHelper::getValue($criterion['value'], $this->em); + $params[] = PersisterHelper::getIdentifierValues($criterion['value'], $this->em); } return array($params, $types); diff --git a/lib/Doctrine/ORM/Utility/PersisterHelper.php b/lib/Doctrine/ORM/Utility/PersisterHelper.php index a5ba6bd1f..6c3af11da 100644 --- a/lib/Doctrine/ORM/Utility/PersisterHelper.php +++ b/lib/Doctrine/ORM/Utility/PersisterHelper.php @@ -140,7 +140,7 @@ class PersisterHelper * * @return mixed */ - public static function getValue($value, EntityManagerInterface $em) + public static function getIdentifierValues($value, EntityManagerInterface $em) { if ( ! is_array($value)) { return self::getIndividualValue($value, $em); From 270254093005c2c3601dbe5b4c8ea72164b9bdc3 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 07:31:22 +0100 Subject: [PATCH 31/32] #1178 - simplified `ValueConversionType` tests by using a single model-set for the entire subset of tests (faster as well) --- .../InversedOneToOneCompositeIdEntity.php | 2 +- .../OwningOneToOneCompositeIdEntity.php | 2 +- .../ORM/Functional/SchemaValidatorTest.php | 1 - .../ManyToManyCompositeIdForeignKeyTest.php | 13 +-- .../ManyToManyCompositeIdTest.php | 12 +-- .../ManyToManyExtraLazyTest.php | 12 +-- .../ValueConversionType/ManyToManyTest.php | 12 +-- .../OneToManyCompositeIdForeignKeyTest.php | 12 +-- .../OneToManyCompositeIdTest.php | 11 +-- .../OneToManyExtraLazyTest.php | 11 +-- .../ValueConversionType/OneToManyTest.php | 11 +-- .../OneToOneCompositeIdForeignKeyTest.php | 12 +-- .../OneToOneCompositeIdTest.php | 21 ++--- .../ValueConversionType/OneToOneTest.php | 11 +-- .../Doctrine/Tests/OrmFunctionalTestCase.php | 89 ++++--------------- 15 files changed, 36 insertions(+), 196 deletions(-) diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneCompositeIdEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneCompositeIdEntity.php index 631b22b8b..4a2a89a0f 100644 --- a/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneCompositeIdEntity.php +++ b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneCompositeIdEntity.php @@ -26,7 +26,7 @@ class InversedOneToOneCompositeIdEntity public $someProperty; /** - * @OneToOne(targetEntity="OwningOneToOneCompositeIdEntity", mappedBy="associatedEntity") + * @OneToOne(targetEntity="OwningOneToOneCompositeIdEntity", mappedBy="associatedComposite") */ public $associatedEntity; } diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/OwningOneToOneCompositeIdEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/OwningOneToOneCompositeIdEntity.php index bf4282cc1..0798deadc 100644 --- a/tests/Doctrine/Tests/Models/ValueConversionType/OwningOneToOneCompositeIdEntity.php +++ b/tests/Doctrine/Tests/Models/ValueConversionType/OwningOneToOneCompositeIdEntity.php @@ -21,5 +21,5 @@ class OwningOneToOneCompositeIdEntity * @JoinColumn(name="associated_id2", referencedColumnName="id2") * }) */ - public $associatedEntity; + public $associatedComposite; } diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php index 948aad2ef..c09f336c9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\ORM\Tools\SchemaValidator; /** diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php index 877d1a279..255a342bb 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -19,7 +18,7 @@ class ManyToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct_manytomany_compositeid_foreignkey'); + $this->useModelSet('vct'); parent::setUp(); @@ -44,16 +43,6 @@ class ManyToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase $this->_em->clear(); } - public static function tearDownAfterClass() - { - $conn = static::$_sharedConn; - - $conn->executeUpdate('DROP TABLE vct_xref_manytomany_compositeid_foreignkey'); - $conn->executeUpdate('DROP TABLE vct_owning_manytomany_compositeid_foreignkey'); - $conn->executeUpdate('DROP TABLE vct_inversed_manytomany_compositeid_foreignkey'); - $conn->executeUpdate('DROP TABLE vct_auxiliary'); - } - public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php index 6b56073a3..45f9b0371 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -18,7 +17,7 @@ class ManyToManyCompositeIdTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct_manytomany_compositeid'); + $this->useModelSet('vct'); parent::setUp(); @@ -39,15 +38,6 @@ class ManyToManyCompositeIdTest extends OrmFunctionalTestCase $this->_em->clear(); } - public static function tearDownAfterClass() - { - $conn = static::$_sharedConn; - - $conn->executeUpdate('DROP TABLE vct_xref_manytomany_compositeid'); - $conn->executeUpdate('DROP TABLE vct_owning_manytomany_compositeid'); - $conn->executeUpdate('DROP TABLE vct_inversed_manytomany_compositeid'); - } - public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php index 3d1df24b8..34f1406ea 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -19,7 +18,7 @@ class ManyToManyExtraLazyTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct_manytomany_extralazy'); + $this->useModelSet('vct'); parent::setUp(); $inversed1 = new Entity\InversedManyToManyExtraLazyEntity(); @@ -53,15 +52,6 @@ class ManyToManyExtraLazyTest extends OrmFunctionalTestCase $this->_em->clear(); } - public static function tearDownAfterClass() - { - $conn = static::$_sharedConn; - - $conn->executeUpdate('DROP TABLE vct_xref_manytomany_extralazy'); - $conn->executeUpdate('DROP TABLE vct_owning_manytomany_extralazy'); - $conn->executeUpdate('DROP TABLE vct_inversed_manytomany_extralazy'); - } - public function testThatTheExtraLazyCollectionFromOwningToInversedIsCounted() { $owning = $this->_em->find( diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php index 66193fb14..345d90238 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -18,7 +17,7 @@ class ManyToManyTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct_manytomany'); + $this->useModelSet('vct'); parent::setUp(); @@ -38,15 +37,6 @@ class ManyToManyTest extends OrmFunctionalTestCase $this->_em->clear(); } - public static function tearDownAfterClass() - { - $conn = static::$_sharedConn; - - $conn->executeUpdate('DROP TABLE vct_xref_manytomany'); - $conn->executeUpdate('DROP TABLE vct_owning_manytomany'); - $conn->executeUpdate('DROP TABLE vct_inversed_manytomany'); - } - public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php index 17a8ea873..ed5a124ab 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -19,7 +18,7 @@ class OneToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct_onetomany_compositeid_foreignkey'); + $this->useModelSet('vct'); parent::setUp(); @@ -45,15 +44,6 @@ class OneToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase $this->_em->clear(); } - public static function tearDownAfterClass() - { - $conn = static::$_sharedConn; - - $conn->executeUpdate('DROP TABLE vct_owning_manytoone_compositeid_foreignkey'); - $conn->executeUpdate('DROP TABLE vct_inversed_onetomany_compositeid_foreignkey'); - $conn->executeUpdate('DROP TABLE vct_auxiliary'); - } - public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php index c094afa78..64764e7e0 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -18,7 +17,7 @@ class OneToManyCompositeIdTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct_onetomany_compositeid'); + $this->useModelSet('vct'); parent::setUp(); @@ -40,14 +39,6 @@ class OneToManyCompositeIdTest extends OrmFunctionalTestCase $this->_em->clear(); } - public static function tearDownAfterClass() - { - $conn = static::$_sharedConn; - - $conn->executeUpdate('DROP TABLE vct_owning_manytoone_compositeid'); - $conn->executeUpdate('DROP TABLE vct_inversed_onetomany_compositeid'); - } - public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php index bb9006782..312e270e9 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -19,7 +18,7 @@ class OneToManyExtraLazyTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct_onetomany_extralazy'); + $this->useModelSet('vct'); parent::setUp(); @@ -51,14 +50,6 @@ class OneToManyExtraLazyTest extends OrmFunctionalTestCase $this->_em->clear(); } - public static function tearDownAfterClass() - { - $conn = static::$_sharedConn; - - $conn->executeUpdate('DROP TABLE vct_owning_manytoone_extralazy'); - $conn->executeUpdate('DROP TABLE vct_inversed_onetomany_extralazy'); - } - public function testThatExtraLazyCollectionIsCounted() { $inversed = $this->_em->find( diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php index e83453714..40034268c 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -18,7 +17,7 @@ class OneToManyTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct_onetomany'); + $this->useModelSet('vct'); parent::setUp(); @@ -39,14 +38,6 @@ class OneToManyTest extends OrmFunctionalTestCase $this->_em->clear(); } - public static function tearDownAfterClass() - { - $conn = static::$_sharedConn; - - $conn->executeUpdate('DROP TABLE vct_owning_manytoone'); - $conn->executeUpdate('DROP TABLE vct_inversed_onetomany'); - } - public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php index 4a595c21f..d8cb52836 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -19,7 +18,7 @@ class OneToOneCompositeIdForeignKeyTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct_onetoone_compositeid_foreignkey'); + $this->useModelSet('vct'); parent::setUp(); $auxiliary = new Entity\AuxiliaryEntity(); @@ -44,15 +43,6 @@ class OneToOneCompositeIdForeignKeyTest extends OrmFunctionalTestCase $this->_em->clear(); } - public static function tearDownAfterClass() - { - $conn = static::$_sharedConn; - - $conn->executeUpdate('DROP TABLE vct_owning_onetoone_compositeid_foreignkey'); - $conn->executeUpdate('DROP TABLE vct_inversed_onetoone_compositeid_foreignkey'); - $conn->executeUpdate('DROP TABLE vct_auxiliary'); - } - public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php index 96daa6016..4c4aa7958 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -18,7 +17,8 @@ class OneToOneCompositeIdTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct_onetoone_compositeid'); + $this->useModelSet('vct'); + parent::setUp(); $inversed = new Entity\InversedOneToOneCompositeIdEntity(); @@ -30,7 +30,7 @@ class OneToOneCompositeIdTest extends OrmFunctionalTestCase $owning->id3 = 'ghi'; $inversed->associatedEntity = $owning; - $owning->associatedEntity = $inversed; + $owning->associatedComposite = $inversed; $this->_em->persist($inversed); $this->_em->persist($owning); @@ -39,14 +39,6 @@ class OneToOneCompositeIdTest extends OrmFunctionalTestCase $this->_em->clear(); } - public static function tearDownAfterClass() - { - $conn = static::$_sharedConn; - - $conn->executeUpdate('DROP TABLE vct_owning_onetoone_compositeid'); - $conn->executeUpdate('DROP TABLE vct_inversed_onetoone_compositeid'); - } - public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); @@ -108,7 +100,7 @@ class OneToOneCompositeIdTest extends OrmFunctionalTestCase 'ghi' ); - $inversedProxy = $owning->associatedEntity; + $inversedProxy = $owning->associatedComposite; $this->assertEquals('some value to be loaded', $inversedProxy->someProperty); } @@ -123,6 +115,9 @@ class OneToOneCompositeIdTest extends OrmFunctionalTestCase array('id1' => 'abc', 'id2' => 'def') ); - $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity', $inversed->associatedEntity); + $this->assertInstanceOf( + 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity', + $inversed->associatedEntity + ); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php index 15e45f9fe..2be60207e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; -use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -18,7 +17,7 @@ class OneToOneTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct_onetoone'); + $this->useModelSet('vct'); parent::setUp(); @@ -39,14 +38,6 @@ class OneToOneTest extends OrmFunctionalTestCase $this->_em->clear(); } - public static function tearDownAfterClass() - { - $conn = static::$_sharedConn; - - $conn->executeUpdate('DROP TABLE vct_owning_onetoone'); - $conn->executeUpdate('DROP TABLE vct_inversed_onetoone'); - } - public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index cfced6d61..0f2964b19 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests; use Doctrine\DBAL\Types\Type; +use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Tests\EventListener\CacheMetadataListener; use Doctrine\ORM\Cache\Logging\StatisticsCacheLogger; use Doctrine\ORM\Cache\DefaultCacheFactory; @@ -41,7 +42,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase protected $_em; /** - * @var \Doctrine\ORM\Tools\SchemaTool + * @var SchemaTool */ protected $_schemaTool; @@ -200,52 +201,30 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\Quote\Phone', 'Doctrine\Tests\Models\Quote\User' ), - 'vct_onetoone' => array( + 'vct' => array( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneEntity' - ), - 'vct_onetoone_compositeid' => array( + 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneEntity', 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity' - ), - 'vct_onetoone_compositeid_foreignkey' => array( + 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity', 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity' - ), - 'vct_onetomany' => array( + 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity', 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneEntity' - ), - 'vct_onetomany_compositeid' => array( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneEntity', 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdEntity' - ), - 'vct_onetomany_compositeid_foreignkey' => array( - 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdEntity', 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity' - ), - 'vct_onetomany_extralazy' => array( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity', 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneExtraLazyEntity' - ), - 'vct_manytomany' => array( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneExtraLazyEntity', 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyEntity' - ), - 'vct_manytomany_compositeid' => array( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyEntity', 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdEntity' - ), - 'vct_manytomany_compositeid_foreignkey' => array( - 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdEntity', 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity' - ), - 'vct_manytomany_extralazy' => array( + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity', 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyExtraLazyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity' + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity', ), ); @@ -406,63 +385,33 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier("quote-user")); } - if (isset($this->_usedModelSets['vct_onetoone'])) { + if (isset($this->_usedModelSets['vct'])) { $conn->executeUpdate('DELETE FROM vct_owning_onetoone'); $conn->executeUpdate('DELETE FROM vct_inversed_onetoone'); - } - - if (isset($this->_usedModelSets['vct_onetoone_compositeid'])) { $conn->executeUpdate('DELETE FROM vct_owning_onetoone_compositeid'); $conn->executeUpdate('DELETE FROM vct_inversed_onetoone_compositeid'); - } - - if (isset($this->_usedModelSets['vct_onetoone_compositeid_foreignkey'])) { $conn->executeUpdate('DELETE FROM vct_owning_onetoone_compositeid_foreignkey'); $conn->executeUpdate('DELETE FROM vct_inversed_onetoone_compositeid_foreignkey'); $conn->executeUpdate('DELETE FROM vct_auxiliary'); - } - - if (isset($this->_usedModelSets['vct_onetomany'])) { $conn->executeUpdate('DELETE FROM vct_owning_manytoone'); $conn->executeUpdate('DELETE FROM vct_inversed_onetomany'); - } - - if (isset($this->_usedModelSets['vct_onetomany_compositeid'])) { $conn->executeUpdate('DELETE FROM vct_owning_manytoone_compositeid'); $conn->executeUpdate('DELETE FROM vct_inversed_onetomany_compositeid'); - } - - if (isset($this->_usedModelSets['vct_onetomany_compositeid_foreignkey'])) { $conn->executeUpdate('DELETE FROM vct_owning_manytoone_compositeid_foreignkey'); $conn->executeUpdate('DELETE FROM vct_inversed_onetomany_compositeid_foreignkey'); $conn->executeUpdate('DELETE FROM vct_auxiliary'); - } - - if (isset($this->_usedModelSets['vct_onetomany_extralazy'])) { $conn->executeUpdate('DELETE FROM vct_owning_manytoone_extralazy'); $conn->executeUpdate('DELETE FROM vct_inversed_onetomany_extralazy'); - } - - if (isset($this->_usedModelSets['vct_manytomany'])) { $conn->executeUpdate('DELETE FROM vct_xref_manytomany'); $conn->executeUpdate('DELETE FROM vct_owning_manytomany'); $conn->executeUpdate('DELETE FROM vct_inversed_manytomany'); - } - - if (isset($this->_usedModelSets['vct_manytomany_compositeid'])) { $conn->executeUpdate('DELETE FROM vct_xref_manytomany_compositeid'); $conn->executeUpdate('DELETE FROM vct_owning_manytomany_compositeid'); $conn->executeUpdate('DELETE FROM vct_inversed_manytomany_compositeid'); - } - - if (isset($this->_usedModelSets['vct_manytomany_compositeid_foreignkey'])) { $conn->executeUpdate('DELETE FROM vct_xref_manytomany_compositeid_foreignkey'); $conn->executeUpdate('DELETE FROM vct_owning_manytomany_compositeid_foreignkey'); $conn->executeUpdate('DELETE FROM vct_inversed_manytomany_compositeid_foreignkey'); $conn->executeUpdate('DELETE FROM vct_auxiliary'); - } - - if (isset($this->_usedModelSets['vct_manytomany_extralazy'])) { $conn->executeUpdate('DELETE FROM vct_xref_manytomany_extralazy'); $conn->executeUpdate('DELETE FROM vct_owning_manytomany_extralazy'); $conn->executeUpdate('DELETE FROM vct_inversed_manytomany_extralazy'); @@ -507,14 +456,8 @@ abstract class OrmFunctionalTestCase extends OrmTestCase { $this->setUpDBALTypes(); - $forceCreateTables = false; - if ( ! isset(static::$_sharedConn)) { static::$_sharedConn = TestUtil::getConnection(); - - if (static::$_sharedConn->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { - $forceCreateTables = true; - } } if (isset($GLOBALS['DOCTRINE_MARK_SQL_LOGS'])) { @@ -527,7 +470,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase if ( ! $this->_em) { $this->_em = $this->_getEntityManager(); - $this->_schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->_em); + $this->_schemaTool = new SchemaTool($this->_em); } $classes = array(); From 67f59dc25687f286bda250c98077e63f0050a9de Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 08:01:31 +0100 Subject: [PATCH 32/32] Revert "#1178 - simplified `ValueConversionType` tests by using a single model-set for the entire subset of tests (faster as well)" This reverts commit 270254093005c2c3601dbe5b4c8ea72164b9bdc3. --- .../InversedOneToOneCompositeIdEntity.php | 2 +- .../OwningOneToOneCompositeIdEntity.php | 2 +- .../ORM/Functional/SchemaValidatorTest.php | 1 + .../ManyToManyCompositeIdForeignKeyTest.php | 13 ++- .../ManyToManyCompositeIdTest.php | 12 ++- .../ManyToManyExtraLazyTest.php | 12 ++- .../ValueConversionType/ManyToManyTest.php | 12 ++- .../OneToManyCompositeIdForeignKeyTest.php | 12 ++- .../OneToManyCompositeIdTest.php | 11 ++- .../OneToManyExtraLazyTest.php | 11 ++- .../ValueConversionType/OneToManyTest.php | 11 ++- .../OneToOneCompositeIdForeignKeyTest.php | 12 ++- .../OneToOneCompositeIdTest.php | 21 +++-- .../ValueConversionType/OneToOneTest.php | 11 ++- .../Doctrine/Tests/OrmFunctionalTestCase.php | 89 +++++++++++++++---- 15 files changed, 196 insertions(+), 36 deletions(-) diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneCompositeIdEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneCompositeIdEntity.php index 4a2a89a0f..631b22b8b 100644 --- a/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneCompositeIdEntity.php +++ b/tests/Doctrine/Tests/Models/ValueConversionType/InversedOneToOneCompositeIdEntity.php @@ -26,7 +26,7 @@ class InversedOneToOneCompositeIdEntity public $someProperty; /** - * @OneToOne(targetEntity="OwningOneToOneCompositeIdEntity", mappedBy="associatedComposite") + * @OneToOne(targetEntity="OwningOneToOneCompositeIdEntity", mappedBy="associatedEntity") */ public $associatedEntity; } diff --git a/tests/Doctrine/Tests/Models/ValueConversionType/OwningOneToOneCompositeIdEntity.php b/tests/Doctrine/Tests/Models/ValueConversionType/OwningOneToOneCompositeIdEntity.php index 0798deadc..bf4282cc1 100644 --- a/tests/Doctrine/Tests/Models/ValueConversionType/OwningOneToOneCompositeIdEntity.php +++ b/tests/Doctrine/Tests/Models/ValueConversionType/OwningOneToOneCompositeIdEntity.php @@ -21,5 +21,5 @@ class OwningOneToOneCompositeIdEntity * @JoinColumn(name="associated_id2", referencedColumnName="id2") * }) */ - public $associatedComposite; + public $associatedEntity; } diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php b/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php index c09f336c9..948aad2ef 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaValidatorTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional; +use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\ORM\Tools\SchemaValidator; /** diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php index 255a342bb..877d1a279 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdForeignKeyTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -18,7 +19,7 @@ class ManyToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct'); + $this->useModelSet('vct_manytomany_compositeid_foreignkey'); parent::setUp(); @@ -43,6 +44,16 @@ class ManyToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase $this->_em->clear(); } + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_xref_manytomany_compositeid_foreignkey'); + $conn->executeUpdate('DROP TABLE vct_owning_manytomany_compositeid_foreignkey'); + $conn->executeUpdate('DROP TABLE vct_inversed_manytomany_compositeid_foreignkey'); + $conn->executeUpdate('DROP TABLE vct_auxiliary'); + } + public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php index 45f9b0371..6b56073a3 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyCompositeIdTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -17,7 +18,7 @@ class ManyToManyCompositeIdTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct'); + $this->useModelSet('vct_manytomany_compositeid'); parent::setUp(); @@ -38,6 +39,15 @@ class ManyToManyCompositeIdTest extends OrmFunctionalTestCase $this->_em->clear(); } + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_xref_manytomany_compositeid'); + $conn->executeUpdate('DROP TABLE vct_owning_manytomany_compositeid'); + $conn->executeUpdate('DROP TABLE vct_inversed_manytomany_compositeid'); + } + public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php index 34f1406ea..3d1df24b8 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyExtraLazyTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -18,7 +19,7 @@ class ManyToManyExtraLazyTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct'); + $this->useModelSet('vct_manytomany_extralazy'); parent::setUp(); $inversed1 = new Entity\InversedManyToManyExtraLazyEntity(); @@ -52,6 +53,15 @@ class ManyToManyExtraLazyTest extends OrmFunctionalTestCase $this->_em->clear(); } + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_xref_manytomany_extralazy'); + $conn->executeUpdate('DROP TABLE vct_owning_manytomany_extralazy'); + $conn->executeUpdate('DROP TABLE vct_inversed_manytomany_extralazy'); + } + public function testThatTheExtraLazyCollectionFromOwningToInversedIsCounted() { $owning = $this->_em->find( diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php index 345d90238..66193fb14 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/ManyToManyTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -17,7 +18,7 @@ class ManyToManyTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct'); + $this->useModelSet('vct_manytomany'); parent::setUp(); @@ -37,6 +38,15 @@ class ManyToManyTest extends OrmFunctionalTestCase $this->_em->clear(); } + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_xref_manytomany'); + $conn->executeUpdate('DROP TABLE vct_owning_manytomany'); + $conn->executeUpdate('DROP TABLE vct_inversed_manytomany'); + } + public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php index ed5a124ab..17a8ea873 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdForeignKeyTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -18,7 +19,7 @@ class OneToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct'); + $this->useModelSet('vct_onetomany_compositeid_foreignkey'); parent::setUp(); @@ -44,6 +45,15 @@ class OneToManyCompositeIdForeignKeyTest extends OrmFunctionalTestCase $this->_em->clear(); } + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_owning_manytoone_compositeid_foreignkey'); + $conn->executeUpdate('DROP TABLE vct_inversed_onetomany_compositeid_foreignkey'); + $conn->executeUpdate('DROP TABLE vct_auxiliary'); + } + public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php index 64764e7e0..c094afa78 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyCompositeIdTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -17,7 +18,7 @@ class OneToManyCompositeIdTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct'); + $this->useModelSet('vct_onetomany_compositeid'); parent::setUp(); @@ -39,6 +40,14 @@ class OneToManyCompositeIdTest extends OrmFunctionalTestCase $this->_em->clear(); } + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_owning_manytoone_compositeid'); + $conn->executeUpdate('DROP TABLE vct_inversed_onetomany_compositeid'); + } + public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php index 312e270e9..bb9006782 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyExtraLazyTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -18,7 +19,7 @@ class OneToManyExtraLazyTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct'); + $this->useModelSet('vct_onetomany_extralazy'); parent::setUp(); @@ -50,6 +51,14 @@ class OneToManyExtraLazyTest extends OrmFunctionalTestCase $this->_em->clear(); } + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_owning_manytoone_extralazy'); + $conn->executeUpdate('DROP TABLE vct_inversed_onetomany_extralazy'); + } + public function testThatExtraLazyCollectionIsCounted() { $inversed = $this->_em->find( diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php index 40034268c..e83453714 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToManyTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -17,7 +18,7 @@ class OneToManyTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct'); + $this->useModelSet('vct_onetomany'); parent::setUp(); @@ -38,6 +39,14 @@ class OneToManyTest extends OrmFunctionalTestCase $this->_em->clear(); } + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_owning_manytoone'); + $conn->executeUpdate('DROP TABLE vct_inversed_onetomany'); + } + public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php index d8cb52836..4a595c21f 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdForeignKeyTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -18,7 +19,7 @@ class OneToOneCompositeIdForeignKeyTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct'); + $this->useModelSet('vct_onetoone_compositeid_foreignkey'); parent::setUp(); $auxiliary = new Entity\AuxiliaryEntity(); @@ -43,6 +44,15 @@ class OneToOneCompositeIdForeignKeyTest extends OrmFunctionalTestCase $this->_em->clear(); } + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_owning_onetoone_compositeid_foreignkey'); + $conn->executeUpdate('DROP TABLE vct_inversed_onetoone_compositeid_foreignkey'); + $conn->executeUpdate('DROP TABLE vct_auxiliary'); + } + public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php index 4c4aa7958..96daa6016 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneCompositeIdTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -17,8 +18,7 @@ class OneToOneCompositeIdTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct'); - + $this->useModelSet('vct_onetoone_compositeid'); parent::setUp(); $inversed = new Entity\InversedOneToOneCompositeIdEntity(); @@ -30,7 +30,7 @@ class OneToOneCompositeIdTest extends OrmFunctionalTestCase $owning->id3 = 'ghi'; $inversed->associatedEntity = $owning; - $owning->associatedComposite = $inversed; + $owning->associatedEntity = $inversed; $this->_em->persist($inversed); $this->_em->persist($owning); @@ -39,6 +39,14 @@ class OneToOneCompositeIdTest extends OrmFunctionalTestCase $this->_em->clear(); } + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_owning_onetoone_compositeid'); + $conn->executeUpdate('DROP TABLE vct_inversed_onetoone_compositeid'); + } + public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); @@ -100,7 +108,7 @@ class OneToOneCompositeIdTest extends OrmFunctionalTestCase 'ghi' ); - $inversedProxy = $owning->associatedComposite; + $inversedProxy = $owning->associatedEntity; $this->assertEquals('some value to be loaded', $inversedProxy->someProperty); } @@ -115,9 +123,6 @@ class OneToOneCompositeIdTest extends OrmFunctionalTestCase array('id1' => 'abc', 'id2' => 'def') ); - $this->assertInstanceOf( - 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity', - $inversed->associatedEntity - ); + $this->assertInstanceOf('Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity', $inversed->associatedEntity); } } diff --git a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php index 2be60207e..15e45f9fe 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ValueConversionType/OneToOneTest.php @@ -2,6 +2,7 @@ namespace Doctrine\Tests\ORM\Functional\ValueConversionType; +use Doctrine\DBAL\Types\Type as DBALType; use Doctrine\Tests\Models\ValueConversionType as Entity; use Doctrine\Tests\OrmFunctionalTestCase; @@ -17,7 +18,7 @@ class OneToOneTest extends OrmFunctionalTestCase { public function setUp() { - $this->useModelSet('vct'); + $this->useModelSet('vct_onetoone'); parent::setUp(); @@ -38,6 +39,14 @@ class OneToOneTest extends OrmFunctionalTestCase $this->_em->clear(); } + public static function tearDownAfterClass() + { + $conn = static::$_sharedConn; + + $conn->executeUpdate('DROP TABLE vct_owning_onetoone'); + $conn->executeUpdate('DROP TABLE vct_inversed_onetoone'); + } + public function testThatTheValueOfIdentifiersAreConvertedInTheDatabase() { $conn = $this->_em->getConnection(); diff --git a/tests/Doctrine/Tests/OrmFunctionalTestCase.php b/tests/Doctrine/Tests/OrmFunctionalTestCase.php index 0f2964b19..cfced6d61 100644 --- a/tests/Doctrine/Tests/OrmFunctionalTestCase.php +++ b/tests/Doctrine/Tests/OrmFunctionalTestCase.php @@ -3,7 +3,6 @@ namespace Doctrine\Tests; use Doctrine\DBAL\Types\Type; -use Doctrine\ORM\Tools\SchemaTool; use Doctrine\Tests\EventListener\CacheMetadataListener; use Doctrine\ORM\Cache\Logging\StatisticsCacheLogger; use Doctrine\ORM\Cache\DefaultCacheFactory; @@ -42,7 +41,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase protected $_em; /** - * @var SchemaTool + * @var \Doctrine\ORM\Tools\SchemaTool */ protected $_schemaTool; @@ -201,30 +200,52 @@ abstract class OrmFunctionalTestCase extends OrmTestCase 'Doctrine\Tests\Models\Quote\Phone', 'Doctrine\Tests\Models\Quote\User' ), - 'vct' => array( + 'vct_onetoone' => array( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneEntity' + ), + 'vct_onetoone_compositeid' => array( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdEntity' + ), + 'vct_onetoone_compositeid_foreignkey' => array( 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', 'Doctrine\Tests\Models\ValueConversionType\InversedOneToOneCompositeIdForeignKeyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningOneToOneCompositeIdForeignKeyEntity' + ), + 'vct_onetomany' => array( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneEntity' + ), + 'vct_onetomany_compositeid' => array( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdEntity' + ), + 'vct_onetomany_compositeid_foreignkey' => array( + 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyCompositeIdForeignKeyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneCompositeIdForeignKeyEntity' + ), + 'vct_onetomany_extralazy' => array( 'Doctrine\Tests\Models\ValueConversionType\InversedOneToManyExtraLazyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneExtraLazyEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToOneExtraLazyEntity' + ), + 'vct_manytomany' => array( 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyEntity' + ), + 'vct_manytomany_compositeid' => array( 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdEntity' + ), + 'vct_manytomany_compositeid_foreignkey' => array( + 'Doctrine\Tests\Models\ValueConversionType\AuxiliaryEntity', 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyCompositeIdForeignKeyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyCompositeIdForeignKeyEntity' + ), + 'vct_manytomany_extralazy' => array( 'Doctrine\Tests\Models\ValueConversionType\InversedManyToManyExtraLazyEntity', - 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity', + 'Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity' ), ); @@ -385,33 +406,63 @@ abstract class OrmFunctionalTestCase extends OrmTestCase $conn->executeUpdate('DELETE FROM ' . $platform->quoteIdentifier("quote-user")); } - if (isset($this->_usedModelSets['vct'])) { + if (isset($this->_usedModelSets['vct_onetoone'])) { $conn->executeUpdate('DELETE FROM vct_owning_onetoone'); $conn->executeUpdate('DELETE FROM vct_inversed_onetoone'); + } + + if (isset($this->_usedModelSets['vct_onetoone_compositeid'])) { $conn->executeUpdate('DELETE FROM vct_owning_onetoone_compositeid'); $conn->executeUpdate('DELETE FROM vct_inversed_onetoone_compositeid'); + } + + if (isset($this->_usedModelSets['vct_onetoone_compositeid_foreignkey'])) { $conn->executeUpdate('DELETE FROM vct_owning_onetoone_compositeid_foreignkey'); $conn->executeUpdate('DELETE FROM vct_inversed_onetoone_compositeid_foreignkey'); $conn->executeUpdate('DELETE FROM vct_auxiliary'); + } + + if (isset($this->_usedModelSets['vct_onetomany'])) { $conn->executeUpdate('DELETE FROM vct_owning_manytoone'); $conn->executeUpdate('DELETE FROM vct_inversed_onetomany'); + } + + if (isset($this->_usedModelSets['vct_onetomany_compositeid'])) { $conn->executeUpdate('DELETE FROM vct_owning_manytoone_compositeid'); $conn->executeUpdate('DELETE FROM vct_inversed_onetomany_compositeid'); + } + + if (isset($this->_usedModelSets['vct_onetomany_compositeid_foreignkey'])) { $conn->executeUpdate('DELETE FROM vct_owning_manytoone_compositeid_foreignkey'); $conn->executeUpdate('DELETE FROM vct_inversed_onetomany_compositeid_foreignkey'); $conn->executeUpdate('DELETE FROM vct_auxiliary'); + } + + if (isset($this->_usedModelSets['vct_onetomany_extralazy'])) { $conn->executeUpdate('DELETE FROM vct_owning_manytoone_extralazy'); $conn->executeUpdate('DELETE FROM vct_inversed_onetomany_extralazy'); + } + + if (isset($this->_usedModelSets['vct_manytomany'])) { $conn->executeUpdate('DELETE FROM vct_xref_manytomany'); $conn->executeUpdate('DELETE FROM vct_owning_manytomany'); $conn->executeUpdate('DELETE FROM vct_inversed_manytomany'); + } + + if (isset($this->_usedModelSets['vct_manytomany_compositeid'])) { $conn->executeUpdate('DELETE FROM vct_xref_manytomany_compositeid'); $conn->executeUpdate('DELETE FROM vct_owning_manytomany_compositeid'); $conn->executeUpdate('DELETE FROM vct_inversed_manytomany_compositeid'); + } + + if (isset($this->_usedModelSets['vct_manytomany_compositeid_foreignkey'])) { $conn->executeUpdate('DELETE FROM vct_xref_manytomany_compositeid_foreignkey'); $conn->executeUpdate('DELETE FROM vct_owning_manytomany_compositeid_foreignkey'); $conn->executeUpdate('DELETE FROM vct_inversed_manytomany_compositeid_foreignkey'); $conn->executeUpdate('DELETE FROM vct_auxiliary'); + } + + if (isset($this->_usedModelSets['vct_manytomany_extralazy'])) { $conn->executeUpdate('DELETE FROM vct_xref_manytomany_extralazy'); $conn->executeUpdate('DELETE FROM vct_owning_manytomany_extralazy'); $conn->executeUpdate('DELETE FROM vct_inversed_manytomany_extralazy'); @@ -456,8 +507,14 @@ abstract class OrmFunctionalTestCase extends OrmTestCase { $this->setUpDBALTypes(); + $forceCreateTables = false; + if ( ! isset(static::$_sharedConn)) { static::$_sharedConn = TestUtil::getConnection(); + + if (static::$_sharedConn->getDriver() instanceof \Doctrine\DBAL\Driver\PDOSqlite\Driver) { + $forceCreateTables = true; + } } if (isset($GLOBALS['DOCTRINE_MARK_SQL_LOGS'])) { @@ -470,7 +527,7 @@ abstract class OrmFunctionalTestCase extends OrmTestCase if ( ! $this->_em) { $this->_em = $this->_getEntityManager(); - $this->_schemaTool = new SchemaTool($this->_em); + $this->_schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->_em); } $classes = array();