You are here

public function ProxyMagicMethodsTest::testInheritedMagicIsset in Plug 7

File

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

Class

ProxyMagicMethodsTest
Test for behavior of proxies with inherited magic methods

Namespace

Doctrine\Tests\Common\Proxy

Code

public function testInheritedMagicIsset() {
  $proxyClassName = $this
    ->generateProxyClass(__NAMESPACE__ . '\\MagicIssetClass');
  $proxy = new $proxyClassName(function (Proxy $proxy, $method, $params) use (&$counter) {
    if (in_array($params[0], array(
      'publicField',
      'test',
      'nonExisting',
    ))) {
      $initializer = $proxy
        ->__getInitializer();
      $proxy
        ->__setInitializer(null);
      $proxy->publicField = 'modifiedPublicField';
      $counter += 1;
      $proxy
        ->__setInitializer($initializer);
      return;
    }
    throw new \InvalidArgumentException(sprintf('Should not be initialized when checking isset("%s")', $params[0]));
  });
  $this
    ->assertTrue(isset($proxy->id));
  $this
    ->assertTrue(isset($proxy->publicField));
  $this
    ->assertTrue(isset($proxy->test));
  $this
    ->assertFalse(isset($proxy->nonExisting));
  $this
    ->assertSame(3, $counter);
}