From 1f08acb5760135f51cb341779df2326e6f25a8a4 Mon Sep 17 00:00:00 2001 From: Benjamin Eberlei Date: Wed, 1 May 2013 10:42:28 +0200 Subject: [PATCH] [DBAL-483] Pass default values to DBAL mapping layer correctly to fix default comparision bug. --- lib/Doctrine/ORM/Tools/SchemaTool.php | 20 ++----- .../ORM/Functional/SchemaTool/DBAL483Test.php | 56 +++++++++++++++++++ .../ORM/Functional/SchemaTool/DDC214Test.php | 8 +-- 3 files changed, 65 insertions(+), 19 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php diff --git a/lib/Doctrine/ORM/Tools/SchemaTool.php b/lib/Doctrine/ORM/Tools/SchemaTool.php index f66a49d15..d6f6fc960 100644 --- a/lib/Doctrine/ORM/Tools/SchemaTool.php +++ b/lib/Doctrine/ORM/Tools/SchemaTool.php @@ -398,22 +398,14 @@ class SchemaTool } if (isset($mapping['options'])) { - if (isset($mapping['options']['comment'])) { - $options['comment'] = $mapping['options']['comment']; + $knownOptions = array('comment', 'unsigned', 'fixed', 'default'); - unset($mapping['options']['comment']); - } + foreach ($knownOptions as $knownOption) { + if ( isset($mapping['options'][$knownOption])) { + $options[$knownOption] = $mapping['options'][$knownOption]; - if (isset($mapping['options']['unsigned'])) { - $options['unsigned'] = $mapping['options']['unsigned']; - - unset($mapping['options']['unsigned']); - } - - if (isset($mapping['options']['fixed'])) { - $options['fixed'] = $mapping['options']['fixed']; - - unset($mapping['options']['fixed']); + unset($mapping['options'][$knownOption]); + } } $options['customSchemaOptions'] = $mapping['options']; diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php new file mode 100644 index 000000000..0c76edf73 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DBAL483Test.php @@ -0,0 +1,56 @@ +_em->getConnection(); + + $this->schemaTool = new Tools\SchemaTool($this->_em); + } + + /** + * @group DBAL-483 + */ + public function testDefaultValueIsComparedCorrectly() + { + $class = $this->_em->getClassMetadata(__NAMESPACE__ . '\\DBAL483Default'); + + $this->schemaTool->createSchema(array($class)); + + $updateSql = $this->schemaTool->getUpdateSchemaSql(array($class)); + + $updateSql = array_filter($updateSql, function ($sql) { + return strpos($sql, 'DBAL483') !== false; + }); + + $this->assertEquals(0, count($updateSql)); + } +} + +/** + * @Entity + */ +class DBAL483Default +{ + /** + * @Id @Column(type="integer") @GeneratedValue + */ + public $id; + + /** + * @Column(type="integer", options={"default": 0}) + */ + public $num; + + /** + * @Column(type="string", options={"default": "foo"}) + */ + public $str = "foo"; +} diff --git a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php index 9b428c71e..22d2b1f8e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/SchemaTool/DDC214Test.php @@ -4,9 +4,6 @@ namespace Doctrine\Tests\ORM\Functional\SchemaTool; use Doctrine\ORM\Tools; - -require_once __DIR__ . '/../../../TestInit.php'; - /** * WARNING: This test should be run as last test! It can affect others very easily! */ @@ -15,7 +12,8 @@ class DDC214Test extends \Doctrine\Tests\OrmFunctionalTestCase private $classes = array(); private $schemaTool = null; - public function setUp() { + public function setUp() + { parent::setUp(); $conn = $this->_em->getConnection(); @@ -88,4 +86,4 @@ class DDC214Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(0, count($sql), "SQL: " . implode(PHP_EOL, $sql)); } -} \ No newline at end of file +}