1
0
mirror of synced 2025-02-02 13:31:45 +03:00

Merge pull request #1154 from Ocramius/hotfix/PHP-5.6-serialization-fix

DDC-3120 - PHP 5.6 internal classes/Serializable serialization fix
This commit is contained in:
Steve Müller 2014-10-06 15:08:37 +02:00
commit d46fa4adeb
3 changed files with 31 additions and 1 deletions

View File

@ -4,6 +4,7 @@ php:
- 5.3
- 5.4
- 5.5
- 5.6
env:
- DB=mysql

View File

@ -866,7 +866,7 @@ class ClassMetadataInfo implements ClassMetadata
public function newInstance()
{
if ($this->_prototype === null) {
if (PHP_VERSION_ID === 50429 || PHP_VERSION_ID === 50513) {
if (PHP_VERSION_ID === 50429 || PHP_VERSION_ID === 50513 || PHP_VERSION_ID >= 50600) {
$this->_prototype = $this->reflClass->newInstanceWithoutConstructor();
} else {
$this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));

View File

@ -1101,6 +1101,31 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase
$this->assertFalse($class->isIdentifier('foo'));
}
/**
* @group DDC-3120
*/
public function testCanInstantiateInternalPhpClassSubclass()
{
$classMetadata = new ClassMetadata(__NAMESPACE__ . '\\MyArrayObjectEntity');
$classMetadata->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$this->assertInstanceOf(__NAMESPACE__ . '\\MyArrayObjectEntity', $classMetadata->newInstance());
}
/**
* @group DDC-3120
*/
public function testCanInstantiateInternalPhpClassSubclassFromUnserializedMetadata()
{
/* @var $classMetadata ClassMetadata */
$classMetadata = unserialize(serialize(new ClassMetadata(__NAMESPACE__ . '\\MyArrayObjectEntity')));
$classMetadata->wakeupReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
$this->assertInstanceOf(__NAMESPACE__ . '\\MyArrayObjectEntity', $classMetadata->newInstance());
}
}
/**
@ -1137,3 +1162,7 @@ class MyPrefixNamingStrategy extends \Doctrine\ORM\Mapping\DefaultNamingStrategy
return strtolower($this->classToTableName($className)) . '_' . $propertyName;
}
}
class MyArrayObjectEntity extends \ArrayObject
{
}