You are here

public function RuntimePublicReflectionPropertyTest::testSetValueOnProxyPublicProperty in Plug 7

File

lib/doctrine/common/tests/Doctrine/Tests/Common/Reflection/RuntimePublicReflectionPropertyTest.php, line 32

Class

RuntimePublicReflectionPropertyTest

Namespace

Doctrine\Tests\Common\Reflection

Code

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);
}