You are here

public function ProxyLogicTest::testCloningWithPersister in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 vendor/doctrine/common/tests/Doctrine/Tests/Common/Proxy/ProxyLogicTest.php \Doctrine\Tests\Common\Proxy\ProxyLogicTest::testCloningWithPersister()

File

vendor/doctrine/common/tests/Doctrine/Tests/Common/Proxy/ProxyLogicTest.php, line 320

Class

ProxyLogicTest
Test the generated proxies behavior. These tests make assumptions about the structure of LazyLoadableObject

Namespace

Doctrine\Tests\Common\Proxy

Code

public function testCloningWithPersister() {
  $this->lazyObject->publicTransientField = 'should-not-change';
  $this->proxyLoader
    ->expects($this
    ->exactly(2))
    ->method('load')
    ->with(array(
    'publicIdentifierField' => 'publicIdentifierFieldValue',
    'protectedIdentifierField' => 'protectedIdentifierFieldValue',
  ))
    ->will($this
    ->returnCallback(function () {
    $blueprint = new LazyLoadableObject();
    $blueprint->publicPersistentField = 'checked-persistent-field';
    $blueprint->publicAssociation = 'checked-association-field';
    $blueprint->publicTransientField = 'checked-transient-field';
    return $blueprint;
  }));
  $firstClone = clone $this->lazyObject;
  $this
    ->assertSame('checked-persistent-field', $firstClone->publicPersistentField, 'Persistent fields are cloned correctly');
  $this
    ->assertSame('checked-association-field', $firstClone->publicAssociation, 'Associations are cloned correctly');
  $this
    ->assertSame('should-not-change', $firstClone->publicTransientField, 'Transient fields are not overwritten');
  $secondClone = clone $this->lazyObject;
  $this
    ->assertSame('checked-persistent-field', $secondClone->publicPersistentField, 'Persistent fields are cloned correctly');
  $this
    ->assertSame('checked-association-field', $secondClone->publicAssociation, 'Associations are cloned correctly');
  $this
    ->assertSame('should-not-change', $secondClone->publicTransientField, 'Transient fields are not overwritten');

  // those should not trigger lazy loading
  $firstClone
    ->__load();
  $secondClone
    ->__load();
}