Merge pull request #526 from FabioBatSilva/DDC-2172
[DDC-2172] Fix EntityGenerator get literal type
This commit is contained in:
commit
29f0b678cf
@ -157,6 +157,38 @@ class EntityGenerator
|
||||
Type::SIMPLE_ARRAY => 'array',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array Hash-map to handle generator types string.
|
||||
*/
|
||||
protected static $generatorStrategyMap = array(
|
||||
ClassMetadataInfo::GENERATOR_TYPE_AUTO => 'AUTO',
|
||||
ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE => 'SEQUENCE',
|
||||
ClassMetadataInfo::GENERATOR_TYPE_TABLE => 'TABLE',
|
||||
ClassMetadataInfo::GENERATOR_TYPE_IDENTITY => 'IDENTITY',
|
||||
ClassMetadataInfo::GENERATOR_TYPE_NONE => 'NONE',
|
||||
ClassMetadataInfo::GENERATOR_TYPE_UUID => 'UUID',
|
||||
ClassMetadataInfo::GENERATOR_TYPE_CUSTOM => 'CUSTOM'
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array Hash-map to handle the change tracking policy string.
|
||||
*/
|
||||
protected static $changeTrackingPolicyMap = array(
|
||||
ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT => 'DEFERRED_IMPLICIT',
|
||||
ClassMetadataInfo::CHANGETRACKING_DEFERRED_EXPLICIT => 'DEFERRED_EXPLICIT',
|
||||
ClassMetadataInfo::CHANGETRACKING_NOTIFY => 'NOTIFY',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var array Hash-map to handle the inheritance type string.
|
||||
*/
|
||||
protected static $inheritanceTypeMap = array(
|
||||
ClassMetadataInfo::INHERITANCE_TYPE_NONE => 'NONE',
|
||||
ClassMetadataInfo::INHERITANCE_TYPE_JOINED => 'JOINED',
|
||||
ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE => 'SINGLE_TABLE',
|
||||
ClassMetadataInfo::INHERITANCE_TYPE_TABLE_PER_CLASS => 'TABLE_PER_CLASS',
|
||||
);
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
@ -1226,63 +1258,45 @@ public function __construct()
|
||||
return implode("\n", $lines);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $type The inheritance type used by the class and it's subclasses.
|
||||
* @return string The literal string for the inheritance type.
|
||||
* @throws \InvalidArgumentException When the inheritance type does not exists.
|
||||
*/
|
||||
protected function getInheritanceTypeString($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case ClassMetadataInfo::INHERITANCE_TYPE_NONE:
|
||||
return 'NONE';
|
||||
|
||||
case ClassMetadataInfo::INHERITANCE_TYPE_JOINED:
|
||||
return 'JOINED';
|
||||
|
||||
case ClassMetadataInfo::INHERITANCE_TYPE_SINGLE_TABLE:
|
||||
return 'SINGLE_TABLE';
|
||||
|
||||
case ClassMetadataInfo::INHERITANCE_TYPE_TABLE_PER_CLASS:
|
||||
return 'PER_CLASS';
|
||||
|
||||
default:
|
||||
throw new \InvalidArgumentException('Invalid provided InheritanceType: ' . $type);
|
||||
if ( ! isset(self::$inheritanceTypeMap[$type])) {
|
||||
throw new \InvalidArgumentException(sprintf('Invalid provided InheritanceType: %s', $type));
|
||||
}
|
||||
|
||||
return self::$inheritanceTypeMap[$type];
|
||||
}
|
||||
|
||||
protected function getChangeTrackingPolicyString($policy)
|
||||
/**
|
||||
* @param integer $type The policy used for change-tracking for the mapped class.
|
||||
* @return string The literal string for the change-tracking type.
|
||||
* @throws \InvalidArgumentException When the change-tracking type does not exists.
|
||||
*/
|
||||
protected function getChangeTrackingPolicyString($type)
|
||||
{
|
||||
switch ($policy) {
|
||||
case ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT:
|
||||
return 'DEFERRED_IMPLICIT';
|
||||
|
||||
case ClassMetadataInfo::CHANGETRACKING_DEFERRED_EXPLICIT:
|
||||
return 'DEFERRED_EXPLICIT';
|
||||
|
||||
case ClassMetadataInfo::CHANGETRACKING_NOTIFY:
|
||||
return 'NOTIFY';
|
||||
|
||||
default:
|
||||
throw new \InvalidArgumentException('Invalid provided ChangeTrackingPolicy: ' . $policy);
|
||||
if ( ! isset(self::$changeTrackingPolicyMap[$type])) {
|
||||
throw new \InvalidArgumentException(sprintf('Invalid provided ChangeTrackingPolicy: %s', $type));
|
||||
}
|
||||
|
||||
return self::$changeTrackingPolicyMap[$type];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param integer $type The generator to use for the mapped class.
|
||||
* @return string The literal string for the generetor type.
|
||||
* @throws \InvalidArgumentException When the generator type does not exists.
|
||||
*/
|
||||
protected function getIdGeneratorTypeString($type)
|
||||
{
|
||||
switch ($type) {
|
||||
case ClassMetadataInfo::GENERATOR_TYPE_AUTO:
|
||||
return 'AUTO';
|
||||
|
||||
case ClassMetadataInfo::GENERATOR_TYPE_SEQUENCE:
|
||||
return 'SEQUENCE';
|
||||
|
||||
case ClassMetadataInfo::GENERATOR_TYPE_TABLE:
|
||||
return 'TABLE';
|
||||
|
||||
case ClassMetadataInfo::GENERATOR_TYPE_IDENTITY:
|
||||
return 'IDENTITY';
|
||||
|
||||
case ClassMetadataInfo::GENERATOR_TYPE_NONE:
|
||||
return 'NONE';
|
||||
|
||||
default:
|
||||
throw new \InvalidArgumentException('Invalid provided IdGeneratorType: ' . $type);
|
||||
if ( ! isset(self::$generatorStrategyMap[$type])) {
|
||||
throw new \InvalidArgumentException(sprintf('Invalid provided IdGeneratorType: %s', $type));
|
||||
}
|
||||
|
||||
return self::$generatorStrategyMap[$type];
|
||||
}
|
||||
}
|
||||
|
@ -340,6 +340,87 @@ class EntityGeneratorTest extends \Doctrine\Tests\OrmTestCase
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-2172
|
||||
*/
|
||||
public function testGetInheritanceTypeString()
|
||||
{
|
||||
$reflection = new \ReflectionClass('\Doctrine\ORM\Mapping\ClassMetadata');
|
||||
$method = new \ReflectionMethod($this->_generator, 'getInheritanceTypeString');
|
||||
$constants = $reflection->getConstants();
|
||||
$pattern = '/^INHERITANCE_TYPE_/';
|
||||
|
||||
$method->setAccessible(true);
|
||||
|
||||
foreach ($constants as $name => $value) {
|
||||
if( ! preg_match($pattern, $name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$expected = preg_replace($pattern, '', $name);
|
||||
$actual = $method->invoke($this->_generator, $value);
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
$this->setExpectedException('\InvalidArgumentException', 'Invalid provided InheritanceType: INVALID');
|
||||
$method->invoke($this->_generator, 'INVALID');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-2172
|
||||
*/
|
||||
public function testGetChangeTrackingPolicyString()
|
||||
{
|
||||
$reflection = new \ReflectionClass('\Doctrine\ORM\Mapping\ClassMetadata');
|
||||
$method = new \ReflectionMethod($this->_generator, 'getChangeTrackingPolicyString');
|
||||
$constants = $reflection->getConstants();
|
||||
$pattern = '/^CHANGETRACKING_/';
|
||||
|
||||
$method->setAccessible(true);
|
||||
|
||||
foreach ($constants as $name => $value) {
|
||||
if( ! preg_match($pattern, $name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$expected = preg_replace($pattern, '', $name);
|
||||
$actual = $method->invoke($this->_generator, $value);
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
$this->setExpectedException('\InvalidArgumentException', 'Invalid provided ChangeTrackingPolicy: INVALID');
|
||||
$method->invoke($this->_generator, 'INVALID');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-2172
|
||||
*/
|
||||
public function testGetIdGeneratorTypeString()
|
||||
{
|
||||
$reflection = new \ReflectionClass('\Doctrine\ORM\Mapping\ClassMetadata');
|
||||
$method = new \ReflectionMethod($this->_generator, 'getIdGeneratorTypeString');
|
||||
$constants = $reflection->getConstants();
|
||||
$pattern = '/^GENERATOR_TYPE_/';
|
||||
|
||||
$method->setAccessible(true);
|
||||
|
||||
foreach ($constants as $name => $value) {
|
||||
if( ! preg_match($pattern, $name)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$expected = preg_replace($pattern, '', $name);
|
||||
$actual = $method->invoke($this->_generator, $value);
|
||||
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
$this->setExpectedException('\InvalidArgumentException', 'Invalid provided IdGeneratorType: INVALID');
|
||||
$method->invoke($this->_generator, 'INVALID');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getEntityTypeAliasDataProvider
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user