public function serializeObjectAsPropertyArrayForSplObjectStoragePropertyBuildsTheCorrectArrayStructureAndStoresEveryObjectInsideSeparately()
{
$propertyClassName1 = 'DummyClass' . md5(uniqid(mt_rand(), true));
$propertyClassName2 = 'DummyClass' . md5(uniqid(mt_rand(), true));
eval('class ' . $propertyClassName1 . ' {}');
eval('class ' . $propertyClassName2 . ' {}');
$propertyClass1 = new $propertyClassName1();
$propertyClass2 = new $propertyClassName2();
$className = 'DummyClass' . md5(uniqid(mt_rand(), true));
eval('class ' . $className . ' {
private $SplObjectProperty;
public function __construct($object1, $object2) {
$this->SplObjectProperty = new \\SplObjectStorage();
$this->SplObjectProperty->attach($object1);
$this->SplObjectProperty->attach($object2);
}
public function getSplObjectProperty() {
return $this->SplObjectProperty;
}
}');
$mockReflectionService = $this->getMockBuilder(ReflectionService::class)->disableOriginalConstructor()->getMock();
$mockReflectionService->expects($this->at(0))->method('getClassPropertyNames')->with($className)->will($this->returnValue(['SplObjectProperty']));
$mockReflectionService->expects($this->at(1))->method('getClassPropertyNames')->will($this->returnValue([]));
$mockReflectionService->expects($this->at(2))->method('getClassPropertyNames')->will($this->returnValue([]));
$mockReflectionService->expects($this->at(3))->method('getClassPropertyNames')->will($this->returnValue([]));
$mockReflectionService->expects($this->any())->method('isPropertyTaggedWith')->with($className, 'SplObjectProperty', 'transient')->will($this->returnValue(false));
$objectSerializer = new ObjectSerializer($this->getMockBuilder(SessionInterface::class)->disableOriginalConstructor()->getMock());
$objectSerializer->injectReflectionService($mockReflectionService);
$objectHash1 = spl_object_hash($propertyClass1);
$objectHash2 = spl_object_hash($propertyClass2);
$object = new $className($propertyClass1, $propertyClass2);
$expectedArray = [spl_object_hash($object) => [ObjectSerializer::CLASSNAME => $className, ObjectSerializer::PROPERTIES => ['SplObjectProperty' => [ObjectSerializer::TYPE => 'SplObjectStorage', ObjectSerializer::VALUE => [$objectHash1, $objectHash2]]]], $objectHash1 => [ObjectSerializer::CLASSNAME => $propertyClassName1, ObjectSerializer::PROPERTIES => []], $objectHash2 => [ObjectSerializer::CLASSNAME => $propertyClassName2, ObjectSerializer::PROPERTIES => []]];
$this->assertEquals($expectedArray, $objectSerializer->serializeObjectAsPropertyArray($object));
}