From 2fac6272a1a4521555c1cc9040ca021a5faca1e1 Mon Sep 17 00:00:00 2001 From: Gareth Evans Date: Wed, 3 Dec 2014 11:18:29 +0000 Subject: [PATCH 1/3] Checks key exists rather than isset If the default value is set to `null`, `isset` will return `false` even though the key is actually there for a reason. --- lib/Doctrine/ORM/Tools/SchemaTool.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index db9438c9f..7b088f578 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -433,7 +433,7 @@ class SchemaTool $knownOptions = array('comment', 'unsigned', 'fixed', 'default'); foreach ($knownOptions as $knownOption) { - if ( isset($mapping['options'][$knownOption])) { + if (array_key_exists($knownOption, $mapping['options'])) { $options[$knownOption] = $mapping['options'][$knownOption]; unset($mapping['options'][$knownOption]); From c1000d23db908031cfe6fb1f6810acd615e28dbd Mon Sep 17 00:00:00 2001 From: Gareth Evans Date: Wed, 3 Dec 2014 19:37:53 +0000 Subject: [PATCH 2/3] Added test that passes following previous commit --- .../Models/NullDefault/NullDefaultColumn.php | 23 +++++++++++++++++++ .../Tests/ORM/Tools/SchemaToolTest.php | 17 ++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/Doctrine/Tests/Models/NullDefault/NullDefaultColumn.php diff --git a/tests/Doctrine/Tests/Models/NullDefault/NullDefaultColumn.php b/tests/Doctrine/Tests/Models/NullDefault/NullDefaultColumn.php new file mode 100644 index 000000000..a8e28060e --- /dev/null +++ b/tests/Doctrine/Tests/Models/NullDefault/NullDefaultColumn.php @@ -0,0 +1,23 @@ +assertEquals(count($classes), $listener->tableCalls); $this->assertTrue($listener->schemaCalled); } + + public function testNullDefaultNotAddedToCustomSchemaOptions() + { + $em = $this->_getTestEntityManager(); + $schemaTool = new SchemaTool($em); + + $classes = array( + $em->getClassMetadata('Doctrine\Tests\Models\NullDefault\NullDefaultColumn'), + ); + + $customSchemaOptions = $schemaTool->getSchemaFromMetadata($classes) + ->getTable('null-default') + ->getColumn('null-default') + ->getCustomSchemaOptions(); + + $this->assertSame(array(), $customSchemaOptions); + } } /** From 78ba7f107313d7511b3b72ecc988cb61a5a85cc2 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Mon, 8 Dec 2014 01:34:30 +0100 Subject: [PATCH 3/3] #1202 - simplified test and test asset --- .../Models/NullDefault/NullDefaultColumn.php | 16 +++------------- .../Doctrine/Tests/ORM/Tools/SchemaToolTest.php | 4 ++-- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/tests/Doctrine/Tests/Models/NullDefault/NullDefaultColumn.php b/tests/Doctrine/Tests/Models/NullDefault/NullDefaultColumn.php index a8e28060e..37545537f 100644 --- a/tests/Doctrine/Tests/Models/NullDefault/NullDefaultColumn.php +++ b/tests/Doctrine/Tests/Models/NullDefault/NullDefaultColumn.php @@ -2,22 +2,12 @@ namespace Doctrine\Tests\Models\NullDefault; -/** - * @Entity - * @Table(name="null-default") - */ +/** @Entity */ class NullDefaultColumn { - - /** - * @Id - * @GeneratedValue - * @Column(type="integer") - */ + /** @Id @GeneratedValue @Column(type="integer") */ public $id; - /** - * @Column(name="`null-default`",nullable=true,options={"default":NULL}) - */ + /** @Column(options={"default":NULL}) */ public $nullDefault; } diff --git a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php index 0629ead73..abae9977f 100644 --- a/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/SchemaToolTest.php @@ -110,8 +110,8 @@ class SchemaToolTest extends \Doctrine\Tests\OrmTestCase ); $customSchemaOptions = $schemaTool->getSchemaFromMetadata($classes) - ->getTable('null-default') - ->getColumn('null-default') + ->getTable('NullDefaultColumn') + ->getColumn('nullDefault') ->getCustomSchemaOptions(); $this->assertSame(array(), $customSchemaOptions);