Neos\Flow\Tests\Unit\ObjectManagement\ObjectSerializerTest::serializeObjectAsPropertyArraySkipsPropertiesThatAreAnnotatedToBeTransient PHP Method

serializeObjectAsPropertyArraySkipsPropertiesThatAreAnnotatedToBeTransient() public method

    public function serializeObjectAsPropertyArraySkipsPropertiesThatAreAnnotatedToBeTransient()
    {
        $className = 'DummyClass' . md5(uniqid(mt_rand(), true));
        eval('class ' . $className . ' {
			private $privateProperty = \'privateProperty\';
			protected $protectedProperty = \'protectedProperty\';
			public $publicProperty = \'publicProperty\';
		}');
        $mockReflectionService = $this->getMockBuilder(ReflectionService::class)->disableOriginalConstructor()->getMock();
        $mockReflectionService->expects($this->any())->method('getClassPropertyNames')->with($className)->will($this->returnValue(['privateProperty', 'protectedProperty', 'publicProperty']));
        $mockReflectionService->expects($this->at(1))->method('isPropertyTaggedWith')->with($className, 'privateProperty', 'transient')->will($this->returnValue(false));
        $mockReflectionService->expects($this->at(2))->method('isPropertyTaggedWith')->with($className, 'protectedProperty', 'transient')->will($this->returnValue(true));
        $mockReflectionService->expects($this->at(3))->method('isPropertyTaggedWith')->with($className, 'publicProperty', 'transient')->will($this->returnValue(false));
        /** @var ObjectSerializer $objectSerializer */
        $objectSerializer = $this->getAccessibleMock(ObjectSerializer::class, ['dummy'], [], '', false);
        $objectSerializer->injectReflectionService($mockReflectionService);
        $someObject = new $className();
        $expectedPropertyArray = [spl_object_hash($someObject) => [ObjectSerializer::CLASSNAME => $className, ObjectSerializer::PROPERTIES => ['privateProperty' => [ObjectSerializer::TYPE => 'simple', ObjectSerializer::VALUE => 'privateProperty'], 'publicProperty' => [ObjectSerializer::TYPE => 'simple', ObjectSerializer::VALUE => 'publicProperty']]]];
        $this->assertEquals($expectedPropertyArray, $objectSerializer->serializeObjectAsPropertyArray($someObject), 'The object was not stored correctly as property array.');
    }
ObjectSerializerTest