You are here

public function ProxyMagicMethodsTest::testInheritedMagicSet in Plug 7

File

lib/doctrine/common/tests/Doctrine/Tests/Common/Proxy/ProxyMagicMethodsTest.php, line 119

Class

ProxyMagicMethodsTest
Test for behavior of proxies with inherited magic methods

Namespace

Doctrine\Tests\Common\Proxy

Code

public function testInheritedMagicSet() {
  $proxyClassName = $this
    ->generateProxyClass(__NAMESPACE__ . '\\MagicSetClass');
  $proxy = new $proxyClassName(function (Proxy $proxy, $method, $params) use (&$counter) {
    if (!in_array($params[0], array(
      'publicField',
      'test',
      'notDefined',
    ))) {
      throw new \InvalidArgumentException('Unexpected access to field "' . $params[0] . '"');
    }
    $counter += 1;
  });
  $this
    ->assertSame('id', $proxy->id);
  $proxy->publicField = 'publicFieldValue';
  $this
    ->assertSame('publicFieldValue', $proxy->publicField);
  $proxy->test = 'testValue';
  $this
    ->assertSame('testValue', $proxy->testAttribute);
  $proxy->notDefined = 'not defined';
  $this
    ->assertSame('not defined', $proxy->testAttribute);
  $this
    ->assertSame(3, $counter);
}