Commit 6c7aaa72 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Added tests for 41e830ca, thereby finding two...

Added tests for 41e830ca, thereby finding two issues with XML and YAML Driver handling of Sequence-Generator
parent 9cee8bf8
...@@ -207,7 +207,7 @@ class XmlDriver extends AbstractFileDriver ...@@ -207,7 +207,7 @@ class XmlDriver extends AbstractFileDriver
$metadata->setSequenceGeneratorDefinition(array( $metadata->setSequenceGeneratorDefinition(array(
'sequenceName' => (string)$seqGenerator['sequence-name'], 'sequenceName' => (string)$seqGenerator['sequence-name'],
'allocationSize' => (string)$seqGenerator['allocation-size'], 'allocationSize' => (string)$seqGenerator['allocation-size'],
'initialValue' => (string)$seqGeneratorAnnot['initial-value'] 'initialValue' => (string)$seqGenerator['initial-value']
)); ));
} else if (isset($idElement->{'table-generator'})) { } else if (isset($idElement->{'table-generator'})) {
throw MappingException::tableIdGeneratorNotImplemented($className); throw MappingException::tableIdGeneratorNotImplemented($className);
......
...@@ -135,6 +135,10 @@ class YamlDriver extends AbstractFileDriver ...@@ -135,6 +135,10 @@ class YamlDriver extends AbstractFileDriver
if (isset($element['id'])) { if (isset($element['id'])) {
// Evaluate identifier settings // Evaluate identifier settings
foreach ($element['id'] as $name => $idElement) { foreach ($element['id'] as $name => $idElement) {
if (!isset($idElement['type'])) {
throw MappingException::propertyTypeIsRequired($className, $name);
}
$mapping = array( $mapping = array(
'id' => true, 'id' => true,
'fieldName' => $name, 'fieldName' => $name,
...@@ -151,6 +155,12 @@ class YamlDriver extends AbstractFileDriver ...@@ -151,6 +155,12 @@ class YamlDriver extends AbstractFileDriver
$metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_' $metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_'
. strtoupper($idElement['generator']['strategy']))); . strtoupper($idElement['generator']['strategy'])));
} }
// Check for SequenceGenerator/TableGenerator definition
if (isset($idElement['sequenceGenerator'])) {
$metadata->setSequenceGeneratorDefinition($idElement['sequenceGenerator']);
} else if (isset($idElement['tableGenerator'])) {
throw MappingException::tableIdGeneratorNotImplemented($className);
}
} }
} }
...@@ -177,12 +187,6 @@ class YamlDriver extends AbstractFileDriver ...@@ -177,12 +187,6 @@ class YamlDriver extends AbstractFileDriver
. strtoupper($fieldMapping['generator']['strategy']))); . strtoupper($fieldMapping['generator']['strategy'])));
} }
} }
// Check for SequenceGenerator/TableGenerator definition
if (isset($fieldMapping['sequenceGenerator'])) {
$metadata->setSequenceGeneratorDefinition($fieldMapping['sequenceGenerator']);
} else if (isset($fieldMapping['tableGenerator'])) {
throw MappingException::tableIdGeneratorNotImplemented($className);
}
if (isset($fieldMapping['column'])) { if (isset($fieldMapping['column'])) {
$mapping['columnName'] = $fieldMapping['column']; $mapping['columnName'] = $fieldMapping['column'];
} }
......
...@@ -52,6 +52,23 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase ...@@ -52,6 +52,23 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
return $class; return $class;
} }
/**
* @depends testEntityTableNameAndInheritance
* @param ClassMetadata $class
*/
public function testEntitySequence($class)
{
$this->assertType('array', $class->sequenceGeneratorDefinition, 'No Sequence Definition set on this driver.');
$this->assertEquals(
array(
'sequenceName' => 'tablename_seq',
'allocationSize' => 100,
'initialValue' => 1,
),
$class->sequenceGeneratorDefinition
);
}
/** /**
* @depends testEntityTableNameAndInheritance * @depends testEntityTableNameAndInheritance
...@@ -227,7 +244,12 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase ...@@ -227,7 +244,12 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
*/ */
class User class User
{ {
/** @Id @Column(type="integer") @generatedValue(strategy="AUTO") */ /**
* @Id
* @Column(type="integer")
* @generatedValue(strategy="AUTO")
* @SequenceGenerator(sequenceName="tablename_seq", initialValue=1, allocationSize=100)
**/
public $id; public $id;
/** /**
...@@ -389,5 +411,10 @@ class User ...@@ -389,5 +411,10 @@ class User
$metadata->table['uniqueConstraints'] = array( $metadata->table['uniqueConstraints'] = array(
'search_idx' => array('columns' => array('name', 'user_email')), 'search_idx' => array('columns' => array('name', 'user_email')),
); );
$metadata->setSequenceGeneratorDefinition(array(
'sequenceName' => 'tablename_seq',
'allocationSize' => 100,
'initialValue' => 1,
));
} }
} }
\ No newline at end of file
...@@ -105,4 +105,9 @@ $metadata->mapManyToMany(array( ...@@ -105,4 +105,9 @@ $metadata->mapManyToMany(array(
)); ));
$metadata->table['uniqueConstraints'] = array( $metadata->table['uniqueConstraints'] = array(
'search_idx' => array('columns' => array('name', 'user_email')), 'search_idx' => array('columns' => array('name', 'user_email')),
); );
\ No newline at end of file $metadata->setSequenceGeneratorDefinition(array(
'sequenceName' => 'tablename_seq',
'allocationSize' => 100,
'initialValue' => 1,
));
\ No newline at end of file
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
</lifecycle-callbacks> </lifecycle-callbacks>
<id name="id" type="integer" column="id"> <id name="id" type="integer" column="id">
<sequence-generator sequence-name="tablename_seq" allocation-size="100" initial-value="1" />
<generator strategy="AUTO"/> <generator strategy="AUTO"/>
</id> </id>
......
...@@ -6,6 +6,10 @@ Doctrine\Tests\ORM\Mapping\User: ...@@ -6,6 +6,10 @@ Doctrine\Tests\ORM\Mapping\User:
type: integer type: integer
generator: generator:
strategy: AUTO strategy: AUTO
sequenceGenerator:
sequenceName: tablename_seq
allocationSize: 100
initialValue: 1
fields: fields:
name: name:
type: string type: string
......
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