Commit 53209d99 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Fix for both DDC-710 and DDC-693, added many tests for null conversion and...

Fix for both DDC-710 and  DDC-693, added many tests for null conversion and additional tests for the empty value conversion
parent 669aed8f
......@@ -42,7 +42,7 @@ class BooleanType extends Type
public function convertToPHPValue($value, AbstractPlatform $platform)
{
return (bool) $value;
return (null === $value) ? null : (bool) $value;
}
public function getName()
......
......@@ -42,6 +42,6 @@ class DecimalType extends Type
public function convertToPHPValue($value, AbstractPlatform $platform)
{
return (double) $value;
return (null === $value) ? null : (double) $value;
}
}
\ No newline at end of file
......@@ -42,7 +42,7 @@ class SmallIntType extends Type
public function convertToPHPValue($value, AbstractPlatform $platform)
{
return (int) $value;
return (null === $value) ? null : (int) $value;
}
public function getBindingType()
......
......@@ -21,15 +21,16 @@ class BooleanTest extends \Doctrine\Tests\DbalTestCase
public function testBooleanConvertsToDatabaseValue()
{
$this->assertTrue(
is_integer($this->_type->convertToDatabaseValue(1, $this->_platform))
);
$this->assertType('integer', $this->_type->convertToDatabaseValue(1, $this->_platform));
}
public function testBooleanConvertsToPHPValue()
{
$this->assertTrue(
is_bool($this->_type->convertToPHPValue(0, $this->_platform))
);
$this->assertType('bool', $this->_type->convertToPHPValue(0, $this->_platform));
}
public function testBooleanNullConvertsToPHPValue()
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
}
\ No newline at end of file
......@@ -21,8 +21,11 @@ class DecimalTest extends \Doctrine\Tests\DbalTestCase
public function testDecimalConvertsToPHPValue()
{
$this->assertTrue(
is_float($this->_type->convertToPHPValue('5.5', $this->_platform))
);
$this->assertType('float', $this->_type->convertToPHPValue('5.5', $this->_platform));
}
public function testDecimalNullConvertsToPHPValue()
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
}
\ No newline at end of file
......@@ -21,12 +21,12 @@ class IntegerTest extends \Doctrine\Tests\DbalTestCase
public function testIntegerConvertsToPHPValue()
{
$this->assertTrue(
is_integer($this->_type->convertToPHPValue('1', $this->_platform))
);
$this->assertType('integer', $this->_type->convertToPHPValue('1', $this->_platform));
$this->assertType('integer', $this->_type->convertToPHPValue('0', $this->_platform));
}
$this->assertTrue(
is_null($this->_type->convertToPHPValue(null, $this->_platform))
);
public function testIntegerNullConvertsToPHPValue()
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
}
\ No newline at end of file
......@@ -26,16 +26,12 @@ class ObjectTest extends \Doctrine\Tests\DbalTestCase
public function testObjectConvertsToDatabaseValue()
{
$this->assertTrue(
is_string($this->_type->convertToDatabaseValue(new \stdClass(), $this->_platform))
);
$this->assertType('string', $this->_type->convertToDatabaseValue(new \stdClass(), $this->_platform));
}
public function testObjectConvertsToPHPValue()
{
$this->assertTrue(
is_object($this->_type->convertToPHPValue(serialize(new \stdClass), $this->_platform))
);
$this->assertType('object', $this->_type->convertToPHPValue(serialize(new \stdClass), $this->_platform));
}
public function testConversionFailure()
......
......@@ -19,10 +19,14 @@ class SmallIntTest extends \Doctrine\Tests\DbalTestCase
$this->_type = Type::getType('smallint');
}
public function testDecimalConvertsToPHPValue()
public function testSmallIntConvertsToPHPValue()
{
$this->assertTrue(
is_integer($this->_type->convertToPHPValue('1', $this->_platform))
);
$this->assertType('integer', $this->_type->convertToPHPValue('1', $this->_platform));
$this->assertType('integer', $this->_type->convertToPHPValue('0', $this->_platform));
}
public function testSmallIntNullConvertsToPHPValue()
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
}
\ No newline at end of file
......@@ -28,4 +28,15 @@ class StringTest extends \Doctrine\Tests\DbalTestCase
{
$this->assertEquals(255, $this->_type->getDefaultLength($this->_platform));
}
public function testConvertToPHPValue()
{
$this->assertType("string", $this->_type->convertToPHPValue("foo", $this->_platform));
$this->assertType("string", $this->_type->convertToPHPValue("", $this->_platform));
}
public function testNullConversion()
{
$this->assertNull($this->_type->convertToPHPValue(null, $this->_platform));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment