Skip to content

Commit

Permalink
BAP-5280: Upgrade to latest master does not work
Browse files Browse the repository at this point in the history
  • Loading branch information
x86demon committed Sep 24, 2014
1 parent 50d1114 commit d3da6e1
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 19 deletions.
11 changes: 10 additions & 1 deletion src/Oro/DBAL/Types/ArrayType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ArrayType extends BaseType
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value && strpos($value, ';') === false) {
if ($value && !$this->isSerialized($value)) {
$value = base64_decode($value);
}

Expand All @@ -27,4 +27,13 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
$convertedValue = parent::convertToDatabaseValue($value, $platform);
return base64_encode($convertedValue);
}

/**
* @param string $string
* @return bool
*/
protected function isSerialized($string)
{
return strpos($string, ';') !== false || strpos($string, ':') !== false || strpos($string, '{') !== false;
}
}
11 changes: 10 additions & 1 deletion src/Oro/DBAL/Types/ObjectType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class ObjectType extends BaseType
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if ($value && strpos($value, ';') === false) {
if ($value && !$this->isSerialized($value)) {
$value = base64_decode($value);
}

Expand All @@ -27,4 +27,13 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform)
$convertedValue = parent::convertToDatabaseValue($value, $platform);
return base64_encode($convertedValue);
}

/**
* @param string $string
* @return bool
*/
protected function isSerialized($string)
{
return strpos($string, ';') !== false || strpos($string, ':') !== false || strpos($string, '{') !== false;
}
}
53 changes: 45 additions & 8 deletions tests/Oro/Tests/DBAL/Types/ArrayTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,55 @@

class ArrayTypeTest extends \PHPUnit_Framework_TestCase
{
public function testSerialization()
/**
* @dataProvider serializationDataProvider
* @param array $data
*/
public function testSerialization($data)
{
$array = array('a' => 'b');
$encoded = base64_encode(serialize($array));
$encoded = base64_encode(serialize($data));

$platform = TestUtil::getEntityManager()->getConnection()->getDatabasePlatform();
Type::overrideType(Type::TARRAY, 'Oro\DBAL\Types\ArrayType');
$type = Type::getType(Type::TARRAY);
$type = $this->getType();

$actualDbValue = $type->convertToDatabaseValue($array, $platform);
$actualDbValue = $type->convertToDatabaseValue($data, $platform);
$this->assertEquals($encoded, $actualDbValue);
$this->assertEquals($array, $type->convertToPHPValue($actualDbValue, $platform));
$this->assertEquals($array, $type->convertToPHPValue($encoded, $platform));
$this->assertEquals($data, $type->convertToPHPValue($actualDbValue, $platform));
$this->assertEquals($data, $type->convertToPHPValue($encoded, $platform));
}

/**
* @dataProvider serializationDataProvider
* @param array $data
*/
public function testCompatibilityMode($data)
{
$dataSerialized = serialize($data);

$platform = TestUtil::getEntityManager()->getConnection()->getDatabasePlatform();
$type = $this->getType();

$this->assertEquals($data, $type->convertToPHPValue($dataSerialized, $platform));
}

/**
* @return Type
*/
protected function getType()
{
Type::overrideType(Type::TARRAY, 'Oro\DBAL\Types\ArrayType');
return Type::getType(Type::TARRAY);
}

/**
* @return array
*/
public function serializationDataProvider()
{
return array(
array(array('a' => 'b')),
array(array()),
array(array(1, 2, 3)),
);
}
}
58 changes: 49 additions & 9 deletions tests/Oro/Tests/DBAL/Types/ObjectTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,60 @@

class ObjectTypeTest extends \PHPUnit_Framework_TestCase
{
public function testSerialization()
/**
* @dataProvider serializationDataProvider
* @param array $data
*/
public function testSerialization($data)
{
$object = new \stdClass();
$object->a = 'test1';
$encoded = base64_encode(serialize($data));

$platform = TestUtil::getEntityManager()->getConnection()->getDatabasePlatform();
$type = $this->getType();

$actualDbValue = $type->convertToDatabaseValue($data, $platform);
$this->assertEquals($encoded, $actualDbValue);
$this->assertEquals($data, $type->convertToPHPValue($actualDbValue, $platform));
$this->assertEquals($data, $type->convertToPHPValue($encoded, $platform));
}

$encoded = base64_encode(serialize($object));
/**
* @dataProvider serializationDataProvider
* @param array $data
*/
public function testCompatibilityMode($data)
{
$dataSerialized = serialize($data);

$platform = TestUtil::getEntityManager()->getConnection()->getDatabasePlatform();
$type = $this->getType();

$this->assertEquals($data, $type->convertToPHPValue($dataSerialized, $platform));
}

/**
* @return Type
*/
protected function getType()
{
Type::overrideType(Type::OBJECT, 'Oro\DBAL\Types\ObjectType');
$type = Type::getType(Type::OBJECT);
return Type::getType(Type::OBJECT);
}

$actualDbValue = $type->convertToDatabaseValue($object, $platform);
$this->assertEquals($encoded, $actualDbValue);
$this->assertEquals($object, $type->convertToPHPValue($actualDbValue, $platform));
$this->assertEquals($object, $type->convertToPHPValue($encoded, $platform));
/**
* @return array
*/
public function serializationDataProvider()
{
$object = new \stdClass();
$object->a = 'test1';

$emptyObject = new \stdClass();

return array(
array($object),
array($emptyObject)
);
}
}

0 comments on commit d3da6e1

Please sign in to comment.