From 25342b706dbfbf8dfe9535706942c66b70d03a4e Mon Sep 17 00:00:00 2001 From: Adam Pancutt Date: Tue, 15 Oct 2013 12:36:47 +0100 Subject: [PATCH] Added support for field options to FieldBuilder --- .../ORM/Mapping/Builder/FieldBuilder.php | 29 +++++++++++++++++++ .../ORM/Mapping/ClassMetadataBuilderTest.php | 7 +++++ 2 files changed, 36 insertions(+) diff --git a/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php b/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php index f517dd343..75f2fe3c8 100644 --- a/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php +++ b/lib/Doctrine/ORM/Mapping/Builder/FieldBuilder.php @@ -153,6 +153,35 @@ class FieldBuilder return $this; } + /** + * Sets an option. + * + * @param string $name + * @param mixed $value + * + * @return FieldBuilder + */ + public function option($name, $value) + { + if (!array_key_exists('options', $this->mapping)) { + $this->mapping['options'] = array(); + } + $this->mapping['options'][$name] = $value; + return $this; + } + + /** + * Sets unsigned option. + * + * @param bool $flag + * + * @return FieldBuilder + */ + public function unsigned($flag = true) + { + return $this->option('unsigned', (bool)$flag); + } + /** * @param string $strategy * diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php index f14b60b3f..cb60b92b4 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataBuilderTest.php @@ -174,6 +174,13 @@ class ClassMetadataBuilderTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals(array('columnName' => 'id', 'fieldName' => 'id', 'id' => true, 'type' => 'integer'), $this->cm->fieldMappings['id']); } + public function testCreateUnsignedOptionField() + { + $this->builder->createField('state', 'integer')->unsigned()->build(); + + $this->assertEquals(array('fieldName' => 'state', 'type' => 'integer', 'options' => array('unsigned' => true), 'columnName' => 'state'), $this->cm->fieldMappings['state']); + } + public function testAddLifecycleEvent() { $this->builder->addLifecycleEvent('getStatus', 'postLoad');