You are here

public function ProxyMagicMethodsTest::testInheritedMagicSet in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/doctrine/common/tests/Doctrine/Tests/Common/Proxy/ProxyMagicMethodsTest.php \Doctrine\Tests\Common\Proxy\ProxyMagicMethodsTest::testInheritedMagicSet()

File

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