Commit f38584a5 authored by Benjamin Eberlei's avatar Benjamin Eberlei

DDC-545 - Add unittest for all drivers uniqueConstraint capabilities, fix bug...

DDC-545 - Add unittest for all drivers uniqueConstraint capabilities, fix bug in XML Driver that disallowed using them
parent 025735e7
......@@ -118,15 +118,17 @@ class XmlDriver extends AbstractFileDriver
// Evaluate <unique-constraints..>
if (isset($xmlRoot->{'unique-constraints'})) {
foreach ($xmlRoot->{'unique-constraints'}->{'unique-constraint'} as $unique) {
if (is_string($unique['columns'])) {
$columns = explode(',', $unique['columns']);
$columns = explode(',', (string)$unique['columns']);
if (isset($unique['name'])) {
$metadata->table['uniqueConstraints'][(string)$unique['name']] = array(
'columns' => $columns
);
} else {
$columns = $unique['columns'];
$metadata->table['uniqueConstraints'][] = array(
'columns' => $columns
);
}
$metadata->table['uniqueConstraints'][$unique['name']] = array(
'columns' => $columns
);
}
}
......
......@@ -36,6 +36,23 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
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
* @param ClassMetadata $class
......@@ -206,7 +223,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
/**
* @Entity
* @HasLifecycleCallbacks
* @Table(name="cms_users")
* @Table(name="cms_users", uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"name", "user_email"})})
*/
class User
{
......@@ -369,5 +386,8 @@ class User
),
'orderBy' => NULL,
));
$metadata->table['uniqueConstraints'] = array(
'search_idx' => array('columns' => array('name', 'user_email')),
);
}
}
\ No newline at end of file
......@@ -102,4 +102,7 @@ $metadata->mapManyToMany(array(
),
),
'orderBy' => NULL,
));
\ No newline at end of file
));
$metadata->table['uniqueConstraints'] = array(
'search_idx' => array('columns' => array('name', 'user_email')),
);
\ No newline at end of file
......@@ -6,6 +6,10 @@
http://www.doctrine-project.org/schemas/orm/doctrine-mapping.xsd">
<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-callback type="prePersist" method="doStuffOnPrePersist"/>
......
......@@ -51,4 +51,7 @@ Doctrine\Tests\ORM\Mapping\User:
- all
lifecycleCallbacks:
prePersist: [ doStuffOnPrePersist, doOtherStuffOnPrePersistToo ]
postPersist: [ doStuffOnPostPersist ]
\ No newline at end of file
postPersist: [ doStuffOnPostPersist ]
uniqueConstraints:
search_idx:
columns: name,user_email
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment