1
0
mirror of synced 2025-02-10 17:29:27 +03:00

Merge pull request #6130 from kalimatas/fix-xml-option-boolean

#6129 Added unit test for boolean option values.
This commit is contained in:
Marco Pivetta 2016-11-17 21:24:44 +01:00 committed by GitHub
commit f1bf045af3
6 changed files with 45 additions and 15 deletions

View File

@ -661,10 +661,13 @@ class XmlDriver extends FileDriver
$value = (string) $option; $value = (string) $option;
} }
$attr = $option->attributes(); $attributes = $option->attributes();
if (isset($attr->name)) { if (isset($attributes->name)) {
$array[(string) $attr->name] = $value; $nameAttribute = (string) $attributes->name;
$array[$nameAttribute] = in_array($nameAttribute, ['unsigned', 'fixed'])
? $this->evaluateBoolean($value)
: $value;
} else { } else {
$array[] = $value; $array[] = $value;
} }

View File

@ -210,11 +210,14 @@ abstract class AbstractMappingDriverTest extends OrmTestCase
/** /**
* @depends testEntityTableNameAndInheritance * @depends testEntityTableNameAndInheritance
*
* @param ClassMetadata $class * @param ClassMetadata $class
*
* @return ClassMetadata
*/ */
public function testFieldOptions($class) public function testFieldOptions(ClassMetadata $class)
{ {
$expected = array('foo' => 'bar', 'baz' => array('key' => 'val')); $expected = ['foo' => 'bar', 'baz' => ['key' => 'val'], 'fixed' => false];
$this->assertEquals($expected, $class->fieldMappings['name']['options']); $this->assertEquals($expected, $class->fieldMappings['name']['options']);
return $class; return $class;
@ -226,7 +229,7 @@ abstract class AbstractMappingDriverTest extends OrmTestCase
*/ */
public function testIdFieldOptions($class) public function testIdFieldOptions($class)
{ {
$this->assertEquals(array('foo' => 'bar'), $class->fieldMappings['id']['options']); $this->assertEquals(['foo' => 'bar', 'unsigned' => false], $class->fieldMappings['id']['options']);
return $class; return $class;
} }
@ -244,6 +247,26 @@ abstract class AbstractMappingDriverTest extends OrmTestCase
return $class; return $class;
} }
/**
* @group #6129
*
* @depends testLoadMapping
*
* @param ClassMetadata $class
*
* @return ClassMetadata
*/
public function testBooleanValuesForOptionIsSetCorrectly(ClassMetadata $class)
{
$this->assertInternalType('bool', $class->fieldMappings['id']['options']['unsigned']);
$this->assertFalse($class->fieldMappings['id']['options']['unsigned']);
$this->assertInternalType('bool', $class->fieldMappings['name']['options']['fixed']);
$this->assertFalse($class->fieldMappings['name']['options']['fixed']);
return $class;
}
/** /**
* @depends testIdentifier * @depends testIdentifier
* @param ClassMetadata $class * @param ClassMetadata $class
@ -1048,14 +1071,14 @@ class User
{ {
/** /**
* @Id * @Id
* @Column(type="integer", options={"foo": "bar"}) * @Column(type="integer", options={"foo": "bar", "unsigned": false})
* @generatedValue(strategy="AUTO") * @generatedValue(strategy="AUTO")
* @SequenceGenerator(sequenceName="tablename_seq", initialValue=1, allocationSize=100) * @SequenceGenerator(sequenceName="tablename_seq", initialValue=1, allocationSize=100)
**/ **/
public $id; public $id;
/** /**
* @Column(length=50, nullable=true, unique=true, options={"foo": "bar", "baz": {"key": "val"}}) * @Column(length=50, nullable=true, unique=true, options={"foo": "bar", "baz": {"key": "val"}, "fixed": false})
*/ */
public $name; public $name;
@ -1129,7 +1152,7 @@ class User
'fieldName' => 'id', 'fieldName' => 'id',
'type' => 'integer', 'type' => 'integer',
'columnName' => 'id', 'columnName' => 'id',
'options' => array('foo' => 'bar'), 'options' => array('foo' => 'bar', 'unsigned' => false),
)); ));
$metadata->mapField(array( $metadata->mapField(array(
'fieldName' => 'name', 'fieldName' => 'name',
@ -1138,7 +1161,7 @@ class User
'unique' => true, 'unique' => true,
'nullable' => true, 'nullable' => true,
'columnName' => 'name', 'columnName' => 'name',
'options' => array('foo' => 'bar', 'baz' => array('key' => 'val')), 'options' => array('foo' => 'bar', 'baz' => array('key' => 'val'), 'fixed' => false),
)); ));
$metadata->mapField(array( $metadata->mapField(array(
'fieldName' => 'email', 'fieldName' => 'email',

View File

@ -34,7 +34,7 @@ class XmlMappingDriverTest extends AbstractMappingDriverTest
} }
/** /**
* @expectedException Doctrine\ORM\Cache\CacheException * @expectedException \Doctrine\ORM\Cache\CacheException
* @expectedExceptionMessage Entity association field "Doctrine\Tests\ORM\Mapping\XMLSLC#foo" not configured as part of the second-level cache. * @expectedExceptionMessage Entity association field "Doctrine\Tests\ORM\Mapping\XMLSLC#foo" not configured as part of the second-level cache.
*/ */
public function testFailingSecondLevelCacheAssociation() public function testFailingSecondLevelCacheAssociation()
@ -132,7 +132,7 @@ class XmlMappingDriverTest extends AbstractMappingDriverTest
/** /**
* @group DDC-1468 * @group DDC-1468
* *
* @expectedException Doctrine\Common\Persistence\Mapping\MappingException * @expectedException \Doctrine\Common\Persistence\Mapping\MappingException
* @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml' for class 'Doctrine\Tests\Models\Generic\SerializationModel'. * @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.Generic.SerializationModel.dcm.xml' for class 'Doctrine\Tests\Models\Generic\SerializationModel'.
*/ */
public function testInvalidMappingFileException() public function testInvalidMappingFileException()

View File

@ -19,7 +19,7 @@ $metadata->mapField(array(
'fieldName' => 'id', 'fieldName' => 'id',
'type' => 'integer', 'type' => 'integer',
'columnName' => 'id', 'columnName' => 'id',
'options' => array('foo' => 'bar'), 'options' => array('foo' => 'bar', 'unsigned' => false),
)); ));
$metadata->mapField(array( $metadata->mapField(array(
'fieldName' => 'name', 'fieldName' => 'name',
@ -28,7 +28,7 @@ $metadata->mapField(array(
'unique' => true, 'unique' => true,
'nullable' => true, 'nullable' => true,
'columnName' => 'name', 'columnName' => 'name',
'options' => array('foo' => 'bar', 'baz' => array('key' => 'val')), 'options' => array('foo' => 'bar', 'baz' => array('key' => 'val'), 'fixed' => false),
)); ));
$metadata->mapField(array( $metadata->mapField(array(
'fieldName' => 'email', 'fieldName' => 'email',

View File

@ -41,6 +41,7 @@
<sequence-generator sequence-name="tablename_seq" allocation-size="100" initial-value="1" /> <sequence-generator sequence-name="tablename_seq" allocation-size="100" initial-value="1" />
<options> <options>
<option name="foo">bar</option> <option name="foo">bar</option>
<option name="unsigned">false</option>
</options> </options>
</id> </id>
@ -50,6 +51,7 @@
<option name="baz"> <option name="baz">
<option name="key">val</option> <option name="key">val</option>
</option> </option>
<option name="fixed">false</option>
</options> </options>
</field> </field>
<field name="email" column="user_email" type="string" column-definition="CHAR(32) NOT NULL" /> <field name="email" column="user_email" type="string" column-definition="CHAR(32) NOT NULL" />

View File

@ -18,6 +18,7 @@ Doctrine\Tests\ORM\Mapping\User:
initialValue: 1 initialValue: 1
options: options:
foo: bar foo: bar
unsigned: false
fields: fields:
name: name:
type: string type: string
@ -28,6 +29,7 @@ Doctrine\Tests\ORM\Mapping\User:
foo: bar foo: bar
baz: baz:
key: val key: val
fixed: false
email: email:
type: string type: string
column: user_email column: user_email