public function reconstituteObjectCallsTheCorrectReconstitutePropertyTypeFunctionsAndSetsTheValuesInTheObject()
{
$emptyClassName = 'emptyClass' . md5(uniqid(mt_rand(), true));
eval('class ' . $emptyClassName . ' {}');
$className = 'someClass' . md5(uniqid(mt_rand(), true));
eval('class ' . $className . ' {
private $simpleProperty;
private $arrayProperty;
private $arrayObjectProperty;
private $objectProperty;
private $splObjectStorageProperty;
private $collectionProperty;
private $persistenceObjectProperty;
public function getSimpleProperty() { return $this->simpleProperty; }
public function getArrayProperty() { return $this->arrayProperty; }
public function getArrayObjectProperty() { return $this->arrayObjectProperty; }
public function getObjectProperty() { return $this->objectProperty; }
public function getSplObjectStorageProperty() { return $this->splObjectStorageProperty; }
public function getCollectionProperty() { return $this->collectionProperty; }
public function getPersistenceObjectProperty() { return $this->persistenceObjectProperty; }
}');
$objectData = [ObjectSerializer::CLASSNAME => $className, ObjectSerializer::PROPERTIES => ['simpleProperty' => [ObjectSerializer::TYPE => 'simple', ObjectSerializer::VALUE => 'simplePropertyValue'], 'arrayProperty' => [ObjectSerializer::TYPE => 'array', ObjectSerializer::VALUE => 'arrayPropertyValue'], 'arrayObjectProperty' => [ObjectSerializer::TYPE => 'ArrayObject', ObjectSerializer::VALUE => 'arrayObjectPropertyValue'], 'objectProperty' => [ObjectSerializer::TYPE => 'object', ObjectSerializer::VALUE => 'emptyClass'], 'splObjectStorageProperty' => [ObjectSerializer::TYPE => 'SplObjectStorage', ObjectSerializer::VALUE => ['splObjectStoragePropertyValue']], 'collectionProperty' => [ObjectSerializer::TYPE => 'Collection', ObjectSerializer::CLASSNAME => 'Doctrine\\Common\\Collections\\ArrayCollection', ObjectSerializer::VALUE => ['collectionPropertyValue']], 'persistenceObjectProperty' => [ObjectSerializer::TYPE => 'persistenceObject', ObjectSerializer::VALUE => 'persistenceObjectClassName:persistenceObjectUUID']]];
$mockObjectManager = $this->getMockBuilder(ObjectManager::class)->disableOriginalConstructor()->getMock();
$mockObjectManager->expects($this->any())->method('getClassNameByObjectName')->will($this->returnArgument(0));
$objectSerializer = $this->getAccessibleMock(ObjectSerializer::class, ['reconstituteArray', 'reconstituteSplObjectStorage', 'reconstituteCollection', 'reconstitutePersistenceObject'], [], '', false);
$objectSerializer->injectObjectManager($mockObjectManager);
$objectSerializer->expects($this->at(0))->method('reconstituteArray')->with('arrayPropertyValue')->will($this->returnValue('arrayPropertyValue'));
$objectSerializer->expects($this->at(1))->method('reconstituteArray')->with('arrayObjectPropertyValue')->will($this->returnValue(['arrayObjectPropertyValue']));
$objectSerializer->expects($this->once())->method('reconstituteSplObjectStorage')->with(['splObjectStoragePropertyValue'])->will($this->returnValue('splObjectStoragePropertyValue'));
$objectSerializer->expects($this->once())->method('reconstituteCollection')->with('Doctrine\\Common\\Collections\\ArrayCollection', ['collectionPropertyValue'])->will($this->returnValue('collectionPropertyValue'));
$objectSerializer->expects($this->once())->method('reconstitutePersistenceObject')->with('persistenceObjectClassName', 'persistenceObjectUUID')->will($this->returnValue('persistenceObjectPropertyValue'));
$objectsAsArray = ['emptyClass' => [ObjectSerializer::CLASSNAME => $emptyClassName, ObjectSerializer::PROPERTIES => []]];
$objectSerializer->_set('objectsAsArray', $objectsAsArray);
$object = $objectSerializer->_call('reconstituteObject', 'dummyobjecthash', $objectData);
$this->assertEquals('simplePropertyValue', $object->getSimpleProperty(), 'Simple property was not set as expected.');
$this->assertEquals('arrayPropertyValue', $object->getArrayProperty(), 'Array property was not set as expected.');
$this->assertEquals(new \ArrayObject(['arrayObjectPropertyValue']), $object->getArrayObjectProperty(), 'ArrayObject property was not set as expected.');
$this->assertEquals(new $emptyClassName(), $object->getObjectProperty(), 'Object property was not set as expected.');
$this->assertEquals('splObjectStoragePropertyValue', $object->getSplObjectStorageProperty(), 'SplObjectStorage property was not set as expected.');
$this->assertEquals('collectionPropertyValue', $object->getCollectionProperty(), 'Collection property was not set as expected.');
$this->assertEquals('persistenceObjectPropertyValue', $object->getPersistenceObjectProperty(), 'Persistence object property was not set as expected.');
}