You are here

class RuntimePublicReflectionPropertyTest in Plug 7

Hierarchy

Expanded class hierarchy of RuntimePublicReflectionPropertyTest

File

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

Namespace

Doctrine\Tests\Common\Reflection
View source
class RuntimePublicReflectionPropertyTest extends PHPUnit_Framework_TestCase {
  public function testGetValueOnProxyPublicProperty() {
    $getCheckMock = $this
      ->getMock('stdClass', array(
      'callGet',
    ));
    $getCheckMock
      ->expects($this
      ->never())
      ->method('callGet');
    $initializer = function () use ($getCheckMock) {
      call_user_func($getCheckMock);
    };
    $mockProxy = new RuntimePublicReflectionPropertyTestProxyMock();
    $mockProxy
      ->__setInitializer($initializer);
    $reflProperty = new RuntimePublicReflectionProperty(__NAMESPACE__ . '\\RuntimePublicReflectionPropertyTestProxyMock', 'checkedProperty');
    $this
      ->assertSame('testValue', $reflProperty
      ->getValue($mockProxy));
    unset($mockProxy->checkedProperty);
    $this
      ->assertNull($reflProperty
      ->getValue($mockProxy));
  }
  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);
  }

}

Members