1
0
mirror of synced 2025-01-18 22:41:43 +03:00

[DBAL-483] Pass default values to DBAL mapping layer correctly to fix default comparision bug.

This commit is contained in:
Benjamin Eberlei 2013-05-01 10:42:28 +02:00
parent d513e0f084
commit 1f08acb576
3 changed files with 65 additions and 19 deletions

View File

@ -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'];

View File

@ -0,0 +1,56 @@
<?php
namespace Doctrine\Tests\ORM\Functional\SchemaTool;
use Doctrine\ORM\Tools;
class DBAL483Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
public function setUp()
{
parent::setUp();
$conn = $this->_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";
}

View File

@ -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));
}
}
}