1
0
mirror of synced 2024-12-13 22:56:04 +03:00

DDC-545 - Add unittest for all drivers uniqueConstraint capabilities, fix bug in XML Driver that disallowed using them

This commit is contained in:
Benjamin Eberlei 2010-04-28 20:27:53 +02:00
parent 025735e730
commit f38584a51e
5 changed files with 42 additions and 10 deletions

View File

@ -118,15 +118,17 @@ class XmlDriver extends AbstractFileDriver
// Evaluate <unique-constraints..> // Evaluate <unique-constraints..>
if (isset($xmlRoot->{'unique-constraints'})) { if (isset($xmlRoot->{'unique-constraints'})) {
foreach ($xmlRoot->{'unique-constraints'}->{'unique-constraint'} as $unique) { foreach ($xmlRoot->{'unique-constraints'}->{'unique-constraint'} as $unique) {
if (is_string($unique['columns'])) { $columns = explode(',', (string)$unique['columns']);
$columns = explode(',', $unique['columns']);
if (isset($unique['name'])) {
$metadata->table['uniqueConstraints'][(string)$unique['name']] = array(
'columns' => $columns
);
} else { } else {
$columns = $unique['columns']; $metadata->table['uniqueConstraints'][] = array(
'columns' => $columns
);
} }
$metadata->table['uniqueConstraints'][$unique['name']] = array(
'columns' => $columns
);
} }
} }

View File

@ -36,6 +36,23 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
return $class; return $class;
} }
/**
* @depends testEntityTableNameAndInheritance
* @param ClassMetadata $class
*/
public function testEntityUniqueConstraints($class)
{
$this->assertArrayHasKey('uniqueConstraints', $class->table,
'ClassMetadata should have uniqueConstraints key in table property when Unique Constraints are set.');
$this->assertEquals(array(
"search_idx" => array("columns" => array("name", "user_email"))
), $class->table['uniqueConstraints']);
return $class;
}
/** /**
* @depends testEntityTableNameAndInheritance * @depends testEntityTableNameAndInheritance
* @param ClassMetadata $class * @param ClassMetadata $class
@ -206,7 +223,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
/** /**
* @Entity * @Entity
* @HasLifecycleCallbacks * @HasLifecycleCallbacks
* @Table(name="cms_users") * @Table(name="cms_users", uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"name", "user_email"})})
*/ */
class User class User
{ {
@ -369,5 +386,8 @@ class User
), ),
'orderBy' => NULL, 'orderBy' => NULL,
)); ));
$metadata->table['uniqueConstraints'] = array(
'search_idx' => array('columns' => array('name', 'user_email')),
);
} }
} }

View File

@ -102,4 +102,7 @@ $metadata->mapManyToMany(array(
), ),
), ),
'orderBy' => NULL, 'orderBy' => NULL,
)); ));
$metadata->table['uniqueConstraints'] = array(
'search_idx' => array('columns' => array('name', 'user_email')),
);

View File

@ -6,6 +6,10 @@
http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd"> http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<entity name="Doctrine\Tests\ORM\Mapping\User" table="cms_users"> <entity name="Doctrine\Tests\ORM\Mapping\User" table="cms_users">
<unique-constraints>
<unique-constraint columns="name,user_email" name="search_idx" />
</unique-constraints>
<lifecycle-callbacks> <lifecycle-callbacks>
<lifecycle-callback type="prePersist" method="doStuffOnPrePersist"/> <lifecycle-callback type="prePersist" method="doStuffOnPrePersist"/>

View File

@ -51,4 +51,7 @@ Doctrine\Tests\ORM\Mapping\User:
- all - all
lifecycleCallbacks: lifecycleCallbacks:
prePersist: [ doStuffOnPrePersist, doOtherStuffOnPrePersistToo ] prePersist: [ doStuffOnPrePersist, doOtherStuffOnPrePersistToo ]
postPersist: [ doStuffOnPostPersist ] postPersist: [ doStuffOnPostPersist ]
uniqueConstraints:
search_idx:
columns: name,user_email