diff --git a/lib/Doctrine/ORM/AbstractQuery.php b/lib/Doctrine/ORM/AbstractQuery.php index dd9d1c81a..5c7f0747a 100644 --- a/lib/Doctrine/ORM/AbstractQuery.php +++ b/lib/Doctrine/ORM/AbstractQuery.php @@ -458,6 +458,16 @@ abstract class AbstractQuery return isset($this->_hints[$name]) ? $this->_hints[$name] : false; } + /** + * Return the key value map of query hints that are currently set. + * + * @return array + */ + public function getHints() + { + return $this->_hints; + } + /** * Executes the query and returns an IterableResult that can be used to incrementally * iterate over the result. @@ -496,10 +506,10 @@ abstract class AbstractQuery // Check result cache if ($this->_useResultCache && $cacheDriver = $this->getResultCacheDriver()) { - $id = $this->_getResultCacheId(); + list($id, $hash) = $this->getResultCacheId(); $cached = $this->_expireResultCache ? false : $cacheDriver->fetch($id); - if ($cached === false) { + if ($cached === false || !isset($cached[$id])) { // Cache miss. $stmt = $this->_doExecute(); @@ -512,7 +522,7 @@ abstract class AbstractQuery return $result; } else { // Cache hit. - return $cached; + return $cached[$id]; } } @@ -546,12 +556,12 @@ abstract class AbstractQuery * Will return the configured id if it exists otherwise a hash will be * automatically generated for you. * - * @return string $id + * @return array ($id, $hash) */ - protected function _getResultCacheId() + protected function getResultCacheId() { if ($this->_resultCacheId) { - return $this->_resultCacheId; + return array($this->_resultCacheId, $this->_resultCacheId); } else { $params = $this->_params; foreach ($params AS $key => $value) { @@ -563,13 +573,16 @@ abstract class AbstractQuery $idValues = $class->getIdentifierValues($value); } $params[$key] = $idValues; + } else { + $params[$key] = $value; } } $sql = $this->getSql(); ksort($this->_hints); - return md5(implode(";", (array)$sql) . var_export($params, true) . - var_export($this->_hints, true)."&hydrationMode=".$this->_hydrationMode); + $key = implode(";", (array)$sql) . var_export($params, true) . + var_export($this->_hints, true)."&hydrationMode=".$this->_hydrationMode; + return array($key, md5($key)); } } diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index ad8c0840c..302cc6b54 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -194,6 +194,7 @@ abstract class AbstractHydrator $cache[$key]['isMetaColumn'] = true; $cache[$key]['fieldName'] = $fieldName; $cache[$key]['dqlAlias'] = $this->_rsm->columnOwnerMap[$key]; + $classMetadata = $this->_em->getClassMetadata($this->_rsm->aliasMap[$cache[$key]['dqlAlias']]); $cache[$key]['isIdentifier'] = $classMetadata->isIdentifier($fieldName); } } diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 4ac7e87c0..353f47128 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -658,8 +658,8 @@ class ClassMetadataInfo protected function _validateAndCompleteFieldMapping(array &$mapping) { // Check mandatory fields - if ( ! isset($mapping['fieldName'])) { - throw MappingException::missingFieldName($this->name, $mapping); + if ( ! isset($mapping['fieldName']) || strlen($mapping['fieldName']) == 0) { + throw MappingException::missingFieldName($this->name); } if ( ! isset($mapping['type'])) { // Default to string @@ -749,8 +749,8 @@ class ClassMetadataInfo // Mandatory attributes for both sides // Mandatory: fieldName, targetEntity - if ( ! isset($mapping['fieldName'])) { - throw MappingException::missingFieldName(); + if ( ! isset($mapping['fieldName']) || strlen($mapping['fieldName']) == 0) { + throw MappingException::missingFieldName($this->name); } if ( ! isset($mapping['targetEntity'])) { throw MappingException::missingTargetEntity($mapping['fieldName']); diff --git a/lib/Doctrine/ORM/Mapping/MappingException.php b/lib/Doctrine/ORM/Mapping/MappingException.php index c8bc52771..11e35808c 100644 --- a/lib/Doctrine/ORM/Mapping/MappingException.php +++ b/lib/Doctrine/ORM/Mapping/MappingException.php @@ -48,9 +48,9 @@ class MappingException extends \Doctrine\ORM\ORMException return new self("Id generators can't be used with a composite id."); } - public static function missingFieldName() + public static function missingFieldName($entity) { - return new self("The association mapping misses the 'fieldName' attribute."); + return new self("The field or association mapping misses the 'fieldName' attribute in entity '$entity'."); } public static function missingTargetEntity($fieldName) diff --git a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php index e626d17a2..242a500df 100644 --- a/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/BasicEntityPersister.php @@ -28,7 +28,9 @@ use PDO, Doctrine\ORM\Query, Doctrine\ORM\PersistentCollection, Doctrine\ORM\Mapping\MappingException, - Doctrine\ORM\Mapping\ClassMetadata; + Doctrine\ORM\Mapping\ClassMetadata, + Doctrine\ORM\Events, + Doctrine\ORM\Event\LifecycleEventArgs; /** * A BasicEntityPersiter maps an entity to a single table in a relational database. @@ -223,7 +225,7 @@ class BasicEntityPersister } if ($this->_class->isVersioned) { - $this->_assignDefaultVersionValue($this->_class, $entity, $id); + $this->assignDefaultVersionValue($entity, $id); } } @@ -238,22 +240,33 @@ class BasicEntityPersister * by the preceding INSERT statement and assigns it back in to the * entities version field. * - * @param Doctrine\ORM\Mapping\ClassMetadata $class * @param object $entity * @param mixed $id */ - protected function _assignDefaultVersionValue($class, $entity, $id) + protected function assignDefaultVersionValue($entity, $id) { - $versionField = $this->_class->versionField; - $identifier = $this->_class->getIdentifierColumnNames(); - $versionFieldColumnName = $this->_class->getColumnName($versionField); + $value = $this->fetchVersionValue($this->_class, $id); + $this->_class->setFieldValue($entity, $this->_class->versionField, $value); + } + + /** + * Fetch the current version value of a versioned entity. + * + * @param Doctrine\ORM\Mapping\ClassMetadata $versionedClass + * @param mixed $id + * @return mixed + */ + protected function fetchVersionValue($versionedClass, $id) + { + $versionField = $versionedClass->versionField; + $identifier = $versionedClass->getIdentifierColumnNames(); + $versionFieldColumnName = $versionedClass->getColumnName($versionField); //FIXME: Order with composite keys might not be correct - $sql = "SELECT " . $versionFieldColumnName . " FROM " . $class->getQuotedTableName($this->_platform) + $sql = "SELECT " . $versionFieldColumnName . " FROM " . $versionedClass->getQuotedTableName($this->_platform) . " WHERE " . implode(' = ? AND ', $identifier) . " = ?"; $value = $this->_conn->fetchColumn($sql, array_values((array)$id)); - $value = Type::getType($class->fieldMappings[$versionField]['type'])->convertToPHPValue($value, $this->_platform); - $this->_class->setFieldValue($entity, $versionField, $value); + return Type::getType($versionedClass->fieldMappings[$versionField]['type'])->convertToPHPValue($value, $this->_platform); } /** @@ -282,7 +295,7 @@ class BasicEntityPersister if ($this->_class->isVersioned) { $id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity); - $this->_assignDefaultVersionValue($this->_class, $entity, $id); + $this->assignDefaultVersionValue($entity, $id); } } } @@ -693,6 +706,14 @@ class BasicEntityPersister } $this->_em->getUnitOfWork()->setOriginalEntityData($entity, $newData); + + if (isset($this->_class->lifecycleCallbacks[Events::postLoad])) { + $this->_class->invokeLifecycleCallbacks(Events::postLoad, $entity); + } + $evm = $this->_em->getEventManager(); + if ($evm->hasListeners(Events::postLoad)) { + $evm->dispatchEvent(Events::postLoad, new LifecycleEventArgs($entity, $this->_em)); + } } /** diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index 9ae242a45..8aa784001 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -108,10 +108,6 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister return; } - if ($this->_class->isVersioned) { - $versionedClass = $this->_getVersionedClassMetadata(); - } - $postInsertIds = array(); $idGen = $this->_class->idGenerator; $isPostInsertId = $idGen->isPostInsertGenerator(); @@ -177,8 +173,8 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $stmt->closeCursor(); } - if (isset($versionedClass)) { - $this->_assignDefaultVersionValue($versionedClass, $entity, $id); + if ($this->_class->isVersioned) { + $this->assignDefaultVersionValue($entity, $id); } $this->_queuedInserts = array(); @@ -208,7 +204,7 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $this->_updateTable($entity, $versionedClass->getQuotedTableName($this->_platform), array(), true); $id = $this->_em->getUnitOfWork()->getEntityIdentifier($entity); - $this->_assignDefaultVersionValue($this->_class, $entity, $id); + $this->assignDefaultVersionValue($entity, $id); } } } @@ -428,4 +424,13 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister return $columns; } + + /** + * {@inheritdoc} + */ + protected function assignDefaultVersionValue($entity, $id) + { + $value = $this->fetchVersionValue($this->_getVersionedClassMetadata(), $id); + $this->_class->setFieldValue($entity, $this->_class->versionField, $value); + } } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php index 797bc29a8..8c1a8fea1 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php @@ -63,6 +63,10 @@ class ConvertMappingCommand extends Console\Command\Command 'dest-path', InputArgument::REQUIRED, 'The path to generate your entities classes.' ), + new InputOption( + 'force', null, InputOption::VALUE_NONE, + 'Force to overwrite existing mapping files.' + ), new InputOption( 'from-database', null, null, 'Whether or not to convert mapping information from existing database.' ), @@ -73,10 +77,24 @@ class ConvertMappingCommand extends Console\Command\Command new InputOption( 'num-spaces', null, InputOption::VALUE_OPTIONAL, 'Defines the number of indentation spaces', 4 - ) + ), )) ->setHelp(<<one-time command. It should not be necessary for +you to call this method multiple times, escpecially when using the --from-database +flag. + +Converting an existing databsae schema into mapping files only solves about 70-80% +of the necessary mapping information. Additionally the detection from an existing +database cannot detect inverse associations, inheritance types, +entities with foreign keys as primary keys and many of the +semantical operations on associations such as cascade. + +Hint: There is no need to convert YAML or XML mapping files to annotations +every time you make changes. All mapping drivers are first class citizens +in Doctrine 2 and can be used as runtime mapping for the ORM. EOT ); } @@ -121,6 +139,7 @@ EOT $cme = new ClassMetadataExporter(); $exporter = $cme->getExporter($toType, $destPath); + $exporter->setOverwriteExistingFiles( ($input->getOption('force') !== false) ); if ($toType == 'annotation') { $entityGenerator = new EntityGenerator(); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php index f69b5167f..198db0d6c 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php @@ -85,6 +85,23 @@ class GenerateEntitiesCommand extends Console\Command\Command )) ->setHelp(<<--update-entities or --regenerate-entities flags your exisiting +code gets overwritten. The EntityGenerator will only append new code to your +file and will not delete the old code. However this approach may still be prone +to error and we suggest you use code repositories such as GIT or SVN to make +backups of your code. + +It makes sense to generate the entity code if you are using entities as Data +Access Objects only and dont put much additional logic on them. If you are +however putting much more logic on the entities you should refrain from using +the entity-generator and code your entities manually. + +Important: Even if you specified Inheritance options in your +XML or YAML Mapping files the generator cannot generate the base and +child classes for you correctly, because it doesn't know which +class is supposed to extend which. You have to adjust the entity +code manually for inheritance to work! EOT ); } diff --git a/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php b/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php index 983d0f69d..467332b64 100644 --- a/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php +++ b/lib/Doctrine/ORM/Tools/Export/Driver/AbstractExporter.php @@ -23,6 +23,7 @@ namespace Doctrine\ORM\Tools\Export\Driver; use Doctrine\ORM\Mapping\ClassMetadataInfo; +use Doctrine\ORM\Tools\Export\ExportException; /** * Abstract base class which is to be used for the Exporter drivers @@ -39,12 +40,18 @@ abstract class AbstractExporter protected $_metadata = array(); protected $_outputDir; protected $_extension; + protected $_overwriteExistingFiles = false; public function __construct($dir = null) { $this->_outputDir = $dir; } + public function setOverwriteExistingFiles($overwrite) + { + $this->_overwriteExistingFiles = $overwrite; + } + /** * Converts a single ClassMetadata instance to the exported format * and returns it @@ -110,6 +117,9 @@ abstract class AbstractExporter if ( ! is_dir($dir)) { mkdir($dir, 0777, true); } + if (file_exists($path) && !$this->_overwriteExistingFiles) { + throw ExportException::attemptOverwriteExistingFile($path); + } file_put_contents($path, $output); } } diff --git a/lib/Doctrine/ORM/Tools/Export/ExportException.php b/lib/Doctrine/ORM/Tools/Export/ExportException.php index 6e7826e44..5ba8bd26b 100644 --- a/lib/Doctrine/ORM/Tools/Export/ExportException.php +++ b/lib/Doctrine/ORM/Tools/Export/ExportException.php @@ -15,4 +15,9 @@ class ExportException extends ORMException { return new self("The mapping driver '$type' does not exist"); } + + public static function attemptOverwriteExistingFile($file) + { + return new self("Attempting to overwrite an existing file '".$file."'."); + } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index 726793d8d..1edbd38a1 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -179,7 +179,7 @@ class SchemaTool $this->_gatherColumn($class, $idMapping, $table); $columnName = $class->getQuotedColumnName($class->identifier[0], $this->_platform); // TODO: This seems rather hackish, can we optimize it? - $table->getColumn($class->identifier[0])->setAutoincrement(false); + $table->getColumn($columnName)->setAutoincrement(false); $pkColumns[] = $columnName; diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index f35c20eff..d0f5bc022 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -462,6 +462,7 @@ class UnitOfWork implements PropertyChangedListener // A PersistentCollection was de-referenced, so delete it. if ( ! in_array($orgValue, $this->collectionDeletions, true)) { $this->collectionDeletions[] = $orgValue; + $changeSet[$propName] = $orgValue; // Signal changeset, to-many assocs will be ignored. } } } else if ($isChangeTrackingNotify) { diff --git a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php index 36a9fca4c..1ddd7a8ff 100644 --- a/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/LifecycleCallbackTest.php @@ -82,6 +82,27 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertTrue($reference->postLoadCallbackInvoked); } + /** + * @group DDC-958 + */ + public function testPostLoadTriggeredOnRefresh() + { + $entity = new LifecycleCallbackTestEntity; + $entity->value = 'hello'; + $this->_em->persist($entity); + $this->_em->flush(); + $id = $entity->getId(); + + $this->_em->clear(); + + $reference = $this->_em->find('Doctrine\Tests\ORM\Functional\LifecycleCallbackTestEntity', $id); + $this->assertTrue($reference->postLoadCallbackInvoked); + $reference->postLoadCallbackInvoked = false; + + $this->_em->refresh($reference); + $this->assertTrue($reference->postLoadCallbackInvoked, "postLoad should be invoked when refresh() is called."); + } + /** * @group DDC-113 */ diff --git a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php index c2df6c467..4ac1a8d00 100644 --- a/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/ManyToManyBasicAssociationTest.php @@ -3,7 +3,8 @@ namespace Doctrine\Tests\ORM\Functional; use Doctrine\Tests\Models\CMS\CmsUser, - Doctrine\Tests\Models\CMS\CmsGroup; + Doctrine\Tests\Models\CMS\CmsGroup, + Doctrine\Common\Collections\ArrayCollection; require_once __DIR__ . '/../../TestInit.php'; @@ -308,4 +309,37 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa $this->_em->createQuery("DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE SIZE(u.groups) = 10")->execute(); $this->_em->createQuery("UPDATE Doctrine\Tests\Models\CMS\CmsUser u SET u.status = 'inactive' WHERE SIZE(u.groups) = 10")->execute(); } + + /** + * @group DDC-978 + */ + public function testClearAndResetCollection() + { + $user = $this->addCmsUserGblancoWithGroups(2); + $group1 = new CmsGroup; + $group1->name = 'Developers_New1'; + $group2 = new CmsGroup; + $group2->name = 'Developers_New2'; + + $this->_em->persist($group1); + $this->_em->persist($group2); + $this->_em->flush(); + $this->_em->clear(); + + $user = $this->_em->find(get_class($user), $user->id); + + $coll = new ArrayCollection(array($group1, $group2)); + $user->groups = $coll; + $this->_em->flush(); + $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $user->groups, + "UnitOfWork should have replaced ArrayCollection with PersistentCollection."); + $this->_em->flush(); + + $this->_em->clear(); + + $user = $this->_em->find(get_class($user), $user->id); + $this->assertEquals(2, count($user->groups)); + $this->assertEquals('Developers_New1', $user->groups[0]->name); + $this->assertEquals('Developers_New2', $user->groups[1]->name); + } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC960Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC960Test.php new file mode 100644 index 000000000..99a29a57a --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC960Test.php @@ -0,0 +1,92 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC960Root'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC960Child') + )); + } catch(\Exception $e) { + + } + } + + /** + * @group DDC-960 + */ + public function testUpdateRootVersion() + { + $child = new DDC960Child('Test'); + $this->_em->persist($child); + $this->_em->flush(); + + $child->setName("Test2"); + + $this->_em->flush(); + + $this->assertEquals(2, $child->getVersion()); + } +} + +/** + * @Entity + * @InheritanceType("JOINED") + * @DiscriminatorMap({ + * "root" = "DDC960Root", + * "child" = "DDC960Child" + * }) + */ +class DDC960Root +{ + /** + * @Id @GeneratedValue @Column(type="integer") + */ + private $id; + + /** + * @Column(type="integer") @Version + */ + private $version; + + public function getId() + { + return $this->id; + } + + public function getVersion() + { + return $this->version; + } +} + +/** + * @Entity + */ +class DDC960Child extends DDC960Root +{ + /** + * @column(type="string") + * @var string + */ + private $name; + + public function __construct($name) + { + $this->name = $name; + } + + public function setName($name) + { + $this->name = $name; + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php index 1de9b5885..f618f6b3a 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php @@ -379,4 +379,15 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase 'joinColumns' => array(), )); } + + /** + * @group DDC-996 + */ + public function testEmptyFieldNameThrowsException() + { + $this->setExpectedException('Doctrine\ORM\Mapping\MappingException', + "The field or association mapping misses the 'fieldName' attribute in entity 'Doctrine\Tests\Models\CMS\CmsUser'."); + $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm->mapField(array('fieldName' => '')); + } } diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index 98458c6bd..c5f36f387 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -86,4 +86,17 @@ class QueryTest extends \Doctrine\Tests\OrmTestCase $this->assertSame($q2, $q); } + + /** + * @group DDC-968 + */ + public function testHints() + { + $q = $this->_em->createQuery("select a from Doctrine\Tests\Models\CMS\CmsArticle a"); + $q->setHint('foo', 'bar')->setHint('bar', 'baz'); + + $this->assertEquals('bar', $q->getHint('foo')); + $this->assertEquals('baz', $q->getHint('bar')); + $this->assertEquals(array('foo' => 'bar', 'bar' => 'baz'), $q->getHints()); + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php b/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php index b944c26d9..c0af3a7f3 100644 --- a/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/ConvertDoctrine1SchemaTest.php @@ -69,6 +69,7 @@ class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase $converter = new ConvertDoctrine1Schema(__DIR__ . '/doctrine1schema'); $exporter = $cme->getExporter('yml', __DIR__ . '/convert'); + $exporter->setOverwriteExistingFiles(true); $exporter->setMetadata($converter->getMetadata()); $exporter->export(); @@ -80,8 +81,8 @@ class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase $cmf = new DisconnectedClassMetadataFactory(); $cmf->setEntityManager($em); $metadata = $cmf->getAllMetadata(); - $profileClass = $metadata[0]; - $userClass = $metadata[1]; + $profileClass = $cmf->getMetadataFor('Profile'); + $userClass = $cmf->getMetadataFor('User'); $this->assertEquals(2, count($metadata)); $this->assertEquals('Profile', $profileClass->name); @@ -96,9 +97,12 @@ class ConvertDoctrine1SchemaTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals('User', $profileClass->associationMappings['User']['targetEntity']); $this->assertEquals('username', $userClass->table['uniqueConstraints']['username']['columns'][0]); + } - unlink(__DIR__ . '/convert/User.dcm.yml'); - unlink(__DIR__ . '/convert/Profile.dcm.yml'); - rmdir(__DIR__ . '/convert'); + public function tearDown() + { + @unlink(__DIR__ . '/convert/User.dcm.yml'); + @unlink(__DIR__ . '/convert/Profile.dcm.yml'); + @rmdir(__DIR__ . '/convert'); } }