public function testSetValueOnProxyPublicProperty() { $setCheckMock = $this->getMock('stdClass', array('neverCallSet')); $setCheckMock->expects($this->never())->method('neverCallSet'); $initializer = function () use($setCheckMock) { call_user_func(array($setCheckMock, 'neverCallSet')); }; $mockProxy = new RuntimePublicReflectionPropertyTestProxyMock(); $mockProxy->__setInitializer($initializer); $reflProperty = new RuntimePublicReflectionProperty(__NAMESPACE__ . '\\RuntimePublicReflectionPropertyTestProxyMock', 'checkedProperty'); $reflProperty->setValue($mockProxy, 'newValue'); $this->assertSame('newValue', $mockProxy->checkedProperty); unset($mockProxy->checkedProperty); $reflProperty->setValue($mockProxy, 'otherNewValue'); $this->assertSame('otherNewValue', $mockProxy->checkedProperty); $setCheckMock = $this->getMock('stdClass', array('callSet')); $setCheckMock->expects($this->once())->method('callSet'); $initializer = function () use($setCheckMock) { call_user_func(array($setCheckMock, 'callSet')); }; $mockProxy->__setInitializer($initializer); $mockProxy->__setInitialized(true); unset($mockProxy->checkedProperty); $reflProperty->setValue($mockProxy, 'againNewValue'); $this->assertSame('againNewValue', $mockProxy->checkedProperty); }
/** * {@inheritDoc} */ public function getAccessibleProperty($class, $property) { $reflectionProperty = new ReflectionProperty($class, $property); if ($reflectionProperty->isPublic()) { $reflectionProperty = new RuntimePublicReflectionProperty($class, $property); } $reflectionProperty->setAccessible(true); return $reflectionProperty; }