From 86fddfed9a88456a5a30a2ea8269cf2c410d6ca6 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Sat, 20 Oct 2012 00:28:38 -0300 Subject: [PATCH] Fix DDC-2069 --- .../ORM/Mapping/Driver/YamlDriver.php | 4 ++- .../ORM/Mapping/YamlMappingDriverTest.php | 31 +++++++++++++++++++ ...ne.Tests.ORM.Mapping.DDC2069Entity.dcm.yml | 15 +++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.DDC2069Entity.dcm.yml diff --git a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php index 4ade73960..ea53ef28b 100644 --- a/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php +++ b/lib/Doctrine/ORM/Mapping/Driver/YamlDriver.php @@ -198,6 +198,7 @@ class YamlDriver extends FileDriver if (is_string($index['columns'])) { $columns = explode(',', $index['columns']); + $columns = array_map('trim', $columns); } else { $columns = $index['columns']; } @@ -217,6 +218,7 @@ class YamlDriver extends FileDriver if (is_string($unique['columns'])) { $columns = explode(',', $unique['columns']); + $columns = array_map('trim', $columns); } else { $columns = $unique['columns']; } @@ -628,7 +630,7 @@ class YamlDriver extends FileDriver $mapping['type'] = $column['type']; if (isset($params[1])) { - $column['length'] = substr($params[1], 0, strlen($params[1]) - 1); + $column['length'] = (integer) substr($params[1], 0, strlen($params[1]) - 1); } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php index 91dd7e3bd..555184458 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/YamlMappingDriverTest.php @@ -54,4 +54,35 @@ class YamlMappingDriverTest extends AbstractMappingDriverTest $this->createClassMetadata('Doctrine\Tests\Models\Generic\SerializationModel'); } + /** + * @group DDC-2069 + */ + public function testSpacesShouldBeIgnoredWhenUseExplode() + { + $metadata = $this->createClassMetadata(__NAMESPACE__.'\DDC2069Entity'); + $unique = $metadata->table['uniqueConstraints'][0]['columns']; + $indexes = $metadata->table['indexes'][0]['columns']; + + $nameField = $metadata->fieldMappings['name']; + $valueField = $metadata->fieldMappings['value']; + + $this->assertEquals('name', $unique[0]); + $this->assertEquals('value', $unique[1]); + + $this->assertEquals('value', $indexes[0]); + $this->assertEquals('name', $indexes[1]); + + $this->assertEquals(255, $nameField['length']); + $this->assertEquals(255, $valueField['length']); + } + } + +class DDC2069Entity +{ + public $id; + + public $name; + + public $value; +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.DDC2069Entity.dcm.yml b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.DDC2069Entity.dcm.yml new file mode 100644 index 000000000..88ab2da20 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Mapping/yaml/Doctrine.Tests.ORM.Mapping.DDC2069Entity.dcm.yml @@ -0,0 +1,15 @@ +Doctrine\Tests\ORM\Mapping\DDC2069Entity: + type: entity + id: + id: + fields: + name: + type: string ( 255 ) + value: + type: string ( 255 ) + uniqueConstraints: + 0: + columns: name, value + indexes: + 0: + columns: value, name \ No newline at end of file