From 928c32d61626255bf514eadfcdf10288d08a6e09 Mon Sep 17 00:00:00 2001 From: Jan Kramer Date: Sat, 7 Dec 2013 16:04:48 +0100 Subject: [PATCH 1/2] Update XML schema to reflect addition of embeddables --- doctrine-mapping.xsd | 18 ++++++++++++++++++ lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 2 +- .../Tests/Models/ValueObjects/Name.php | 9 +++++++++ .../Tests/Models/ValueObjects/Person.php | 9 +++++++++ ...rine.Tests.Models.ValueObjects.Name.dcm.xml | 10 ++++++++++ ...ne.Tests.Models.ValueObjects.Person.dcm.xml | 12 ++++++++++++ 6 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/Models/ValueObjects/Name.php create mode 100644 tests/Doctrine/Tests/Models/ValueObjects/Person.php create mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Name.dcm.xml create mode 100644 tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Person.dcm.xml diff --git a/doctrine-mapping.xsd b/doctrine-mapping.xsd index f9c774d57..b66e027e9 100644 --- a/doctrine-mapping.xsd +++ b/doctrine-mapping.xsd @@ -17,6 +17,7 @@ + @@ -166,6 +167,7 @@ + @@ -212,6 +214,16 @@ + + + + + + + + + + @@ -274,6 +286,12 @@ + + + + + + diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 3b8bf7e99..95d6ad817 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -248,7 +248,7 @@ class XmlDriver extends FileDriver $mapping = array( 'fieldName' => (string) $embeddedMapping['name'], 'class' => (string) $embeddedMapping['class'], - 'columnPrefix' => isset($embeddedMapping['class']) ? (string) $embeddedMapping['class'] : null, + 'columnPrefix' => isset($embeddedMapping['column-prefix']) ? (string) $embeddedMapping['column-prefix'] : null, ); $metadata->mapEmbedded($mapping); } diff --git a/tests/Doctrine/Tests/Models/ValueObjects/Name.php b/tests/Doctrine/Tests/Models/ValueObjects/Name.php new file mode 100644 index 000000000..1c8360324 --- /dev/null +++ b/tests/Doctrine/Tests/Models/ValueObjects/Name.php @@ -0,0 +1,9 @@ + + + + + + + diff --git a/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Person.dcm.xml b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Person.dcm.xml new file mode 100644 index 000000000..c2480bca7 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/xml/Doctrine.Tests.Models.ValueObjects.Person.dcm.xml @@ -0,0 +1,12 @@ + + + + + + + + + From fbb7b5ad8e06766cbf1f99cc7f23055958d43da7 Mon Sep 17 00:00:00 2001 From: Jan Kramer Date: Sat, 7 Dec 2013 16:40:54 +0100 Subject: [PATCH 2/2] Fix XmlDriver to accept embeddables --- lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php | 5 ++++ .../ORM/Mapping/XmlMappingDriverTest.php | 25 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php index 95d6ad817..7fb780407 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/XmlDriver.php @@ -754,6 +754,11 @@ class XmlDriver extends FileDriver $className = (string)$mappedSuperClass['name']; $result[$className] = $mappedSuperClass; } + } else if (isset($xmlElement->embeddable)) { + foreach ($xmlElement->embeddable as $embeddableElement) { + $embeddableName = (string) $embeddableElement['name']; + $result[$embeddableName] = $embeddableElement; + } } return $result; diff --git a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php index 42b871f1e..6d3ed77d1 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/XmlMappingDriverTest.php @@ -3,6 +3,7 @@ namespace Doctrine\Tests\ORM\Mapping; use Doctrine\ORM\Mapping\ClassMetadata, + Doctrine\ORM\Mapping\ClassMetadataFactory, Doctrine\ORM\Mapping\Driver\XmlDriver, Doctrine\ORM\Mapping\Driver\YamlDriver; @@ -38,7 +39,7 @@ class XmlMappingDriverTest extends AbstractMappingDriverTest { $driver = $this->_loadDriver(); $em = $this->_getTestEntityManager(); - $factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory(); + $factory = new ClassMetadataFactory(); $em->getConfiguration()->setMetadataDriverImpl($driver); $factory->setEntityManager($em); @@ -52,6 +53,28 @@ class XmlMappingDriverTest extends AbstractMappingDriverTest $this->assertTrue($class->associationMappings['article']['id']); } + public function testEmbeddableMapping() + { + $class = $this->createClassMetadata('Doctrine\Tests\Models\ValueObjects\Name'); + + $this->assertEquals(true, $class->isEmbeddedClass); + } + + public function testEmbeddedMapping() + { + $class = $this->createClassMetadata('Doctrine\Tests\Models\ValueObjects\Person'); + + $this->assertEquals( + array( + 'name' => array( + 'class' => 'Doctrine\Tests\Models\ValueObjects\Name', + 'columnPrefix' => 'nm_' + ) + ), + $class->embeddedClasses + ); + } + /** * @group DDC-1468 *