/**
  * Stores all registered objects to the session.
  *
  * @return void
  * @author Andreas Förthner <*****@*****.**>
  */
 public function writeDataToSession()
 {
     $objectsAsArray = array();
     $this->objectSerializer->clearState();
     foreach ($this->objects as $objectName => $object) {
         $objectsAsArray = array_merge($objectsAsArray, $this->objectSerializer->serializeObjectAsPropertyArray($objectName, $object));
     }
     $this->session->putData('F3_FLOW3_Object_SessionRegistry', $objectsAsArray);
 }
    /**
     * @test
     * @author Andreas Förthner <*****@*****.**>
     */
    public function serializeObjectAsPropertyArrayForSplObjectStoragePropertyBuildsTheCorrectArrayStructureAndStoresEveryObjectInsideSeparately()
    {
        $propertyClassName1 = uniqid('DummyClass');
        $propertyClassName2 = uniqid('DummyClass');
        eval('class ' . $propertyClassName1 . ' {}');
        eval('class ' . $propertyClassName2 . ' {}');
        $propertyClass1 = new $propertyClassName1();
        $propertyClass2 = new $propertyClassName2();
        $className = uniqid('DummyClass');
        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->getMock('F3\\FLOW3\\Reflection\\ReflectionService', array(), array(), '', FALSE);
        $mockReflectionService->expects($this->at(0))->method('getClassPropertyNames')->with($className)->will($this->returnValue(array('SplObjectProperty')));
        $mockReflectionService->expects($this->at(1))->method('getClassPropertyNames')->will($this->returnValue(array()));
        $mockReflectionService->expects($this->at(2))->method('getClassPropertyNames')->will($this->returnValue(array()));
        $mockReflectionService->expects($this->at(3))->method('getClassPropertyNames')->will($this->returnValue(array()));
        $mockReflectionService->expects($this->any())->method('isPropertyTaggedWith')->with($className, 'SplObjectProperty', 'transient')->will($this->returnValue(FALSE));
        $objectSerializer = new \F3\FLOW3\Object\ObjectSerializer($this->getMock('F3\\FLOW3\\Session\\SessionInterface', array(), array(), '', FALSE));
        $objectSerializer->injectReflectionService($mockReflectionService);
        $objectHash1 = spl_object_hash($propertyClass1);
        $objectHash2 = spl_object_hash($propertyClass2);
        $expectedArray = array($className => array('className' => $className, 'properties' => array('SplObjectProperty' => array('type' => 'SplObjectStorage', 'value' => array($objectHash1, $objectHash2)))), $objectHash1 => array('className' => $propertyClassName1, 'properties' => array()), $objectHash2 => array('className' => $propertyClassName2, 'properties' => array()));
        $object = new $className($propertyClass1, $propertyClass2);
        $this->assertEquals($expectedArray, $objectSerializer->serializeObjectAsPropertyArray($className, $object));
    }