Added tests for 41e830ca68
, thereby finding two issues with XML and YAML Driver handling of Sequence-Generator
This commit is contained in:
parent
9cee8bf890
commit
6c7aaa727c
6 changed files with 50 additions and 9 deletions
|
@ -207,7 +207,7 @@ class XmlDriver extends AbstractFileDriver
|
|||
$metadata->setSequenceGeneratorDefinition(array(
|
||||
'sequenceName' => (string)$seqGenerator['sequence-name'],
|
||||
'allocationSize' => (string)$seqGenerator['allocation-size'],
|
||||
'initialValue' => (string)$seqGeneratorAnnot['initial-value']
|
||||
'initialValue' => (string)$seqGenerator['initial-value']
|
||||
));
|
||||
} else if (isset($idElement->{'table-generator'})) {
|
||||
throw MappingException::tableIdGeneratorNotImplemented($className);
|
||||
|
|
|
@ -135,6 +135,10 @@ class YamlDriver extends AbstractFileDriver
|
|||
if (isset($element['id'])) {
|
||||
// Evaluate identifier settings
|
||||
foreach ($element['id'] as $name => $idElement) {
|
||||
if (!isset($idElement['type'])) {
|
||||
throw MappingException::propertyTypeIsRequired($className, $name);
|
||||
}
|
||||
|
||||
$mapping = array(
|
||||
'id' => true,
|
||||
'fieldName' => $name,
|
||||
|
@ -151,6 +155,12 @@ class YamlDriver extends AbstractFileDriver
|
|||
$metadata->setIdGeneratorType(constant('Doctrine\ORM\Mapping\ClassMetadata::GENERATOR_TYPE_'
|
||||
. 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
|
|||
. 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'])) {
|
||||
$mapping['columnName'] = $fieldMapping['column'];
|
||||
}
|
||||
|
|
|
@ -52,6 +52,23 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
|||
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
|
||||
|
@ -227,7 +244,12 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
|||
*/
|
||||
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;
|
||||
|
||||
/**
|
||||
|
@ -389,5 +411,10 @@ class User
|
|||
$metadata->table['uniqueConstraints'] = array(
|
||||
'search_idx' => array('columns' => array('name', 'user_email')),
|
||||
);
|
||||
$metadata->setSequenceGeneratorDefinition(array(
|
||||
'sequenceName' => 'tablename_seq',
|
||||
'allocationSize' => 100,
|
||||
'initialValue' => 1,
|
||||
));
|
||||
}
|
||||
}
|
|
@ -105,4 +105,9 @@ $metadata->mapManyToMany(array(
|
|||
));
|
||||
$metadata->table['uniqueConstraints'] = array(
|
||||
'search_idx' => array('columns' => array('name', 'user_email')),
|
||||
);
|
||||
);
|
||||
$metadata->setSequenceGeneratorDefinition(array(
|
||||
'sequenceName' => 'tablename_seq',
|
||||
'allocationSize' => 100,
|
||||
'initialValue' => 1,
|
||||
));
|
|
@ -18,6 +18,7 @@
|
|||
</lifecycle-callbacks>
|
||||
|
||||
<id name="id" type="integer" column="id">
|
||||
<sequence-generator sequence-name="tablename_seq" allocation-size="100" initial-value="1" />
|
||||
<generator strategy="AUTO"/>
|
||||
</id>
|
||||
|
||||
|
|
|
@ -6,6 +6,10 @@ Doctrine\Tests\ORM\Mapping\User:
|
|||
type: integer
|
||||
generator:
|
||||
strategy: AUTO
|
||||
sequenceGenerator:
|
||||
sequenceName: tablename_seq
|
||||
allocationSize: 100
|
||||
initialValue: 1
|
||||
fields:
|
||||
name:
|
||||
type: string
|
||||
|
|
Loading…
Add table
Reference in a new issue