From fac820f0e29d3dbfb185d27bd9816066b0a2dc10 Mon Sep 17 00:00:00 2001 From: jsor Date: Fri, 27 Jan 2012 11:05:47 +0100 Subject: [PATCH] Complete custom column option implementation - Support for xml driver - Tests --- doctrine-mapping.xsd | 1 + lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 8 ++++---- .../Tests/ORM/Mapping/AbstractMappingDriverTest.php | 6 +++++- .../ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php | 1 + .../Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml | 9 ++++++++- .../Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml | 4 ++++ 6 files changed, 23 insertions(+), 6 deletions(-) diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index 5dd510ff1..227af4403 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -182,6 +182,7 @@ + diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index e8e2a80a6..a528346e6 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -196,10 +196,6 @@ class XmlDriver extends AbstractFileDriver $mapping['unique'] = ((string)$fieldMapping['unique'] == "false") ? false : true; } - if (isset($fieldMapping['options'])) { - $mapping['options'] = (array)$fieldMapping['options']; - } - if (isset($fieldMapping['nullable'])) { $mapping['nullable'] = ((string)$fieldMapping['nullable'] == "false") ? false : true; } @@ -212,6 +208,10 @@ class XmlDriver extends AbstractFileDriver $mapping['columnDefinition'] = (string)$fieldMapping['column-definition']; } + if (isset($fieldMapping->options)) { + $mapping['options'] = $this->_parseOptions($fieldMapping->options->children()); + } + $metadata->mapField($mapping); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 6e440a457..369c8fdeb 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -144,6 +144,9 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase $this->assertTrue($class->fieldMappings['name']['nullable']); $this->assertTrue($class->fieldMappings['name']['unique']); + $expected = array('foo' => 'bar', 'baz' => array('key' => 'val')); + $this->assertEquals($expected, $class->fieldMappings['name']['options']); + return $class; } @@ -454,7 +457,7 @@ class User public $id; /** - * @Column(length=50, nullable=true, unique=true) + * @Column(length=50, nullable=true, unique=true, options={"foo": "bar", "baz": {"key": "val"}}) */ public $name; @@ -530,6 +533,7 @@ class User 'unique' => true, 'nullable' => true, 'columnName' => 'name', + 'options' => array('foo' => 'bar', 'baz' => array('key' => 'val')), )); $metadata->mapField(array( 'fieldName' => 'email', diff --git a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php index b9ce24ccd..df4dedda5 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php +++ b/tests/Doctrine/Tests/ORM/Mapping/php/Doctrine.Tests.ORM.Mapping.User.php @@ -27,6 +27,7 @@ $metadata->mapField(array( 'unique' => true, 'nullable' => true, 'columnName' => 'name', + 'options' => array('foo' => 'bar', 'baz' => array('key' => 'val')), )); $metadata->mapField(array( 'fieldName' => 'email', diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml index 44521e827..18f4d5819 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.ORM.Mapping.User.dcm.xml @@ -37,7 +37,14 @@ - + + + + + + + diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml index 7a39a874a..5c1018560 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.User.dcm.yml @@ -22,6 +22,10 @@ Doctrine\Tests\ORM\Mapping\User: length: 50 nullable: true unique: true + options: + foo: bar + baz: + key: val email: type: string column: user_email