You are here

public function ProxyLogicTest::testCloningCallsClonerWithClonedObject in Plug 7

File

lib/doctrine/common/tests/Doctrine/Tests/Common/Proxy/ProxyLogicTest.php, line 232

Class

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

Namespace

Doctrine\Tests\Common\Proxy

Code

public function testCloningCallsClonerWithClonedObject() {
  $lazyObject = $this->lazyObject;
  $test = $this;
  $cb = $this
    ->getMock('stdClass', array(
    'cb',
  ));
  $cb
    ->expects($this
    ->once())
    ->method('cb')
    ->will($this
    ->returnCallback(function (LazyLoadableObject $proxy) use ($lazyObject, $test) {

    /* @var $proxy LazyLoadableObject|Proxy */
    $test
      ->assertNotSame($proxy, $lazyObject);
    $proxy
      ->__setInitializer(null);
    $proxy->publicAssociation = 'clonedAssociation';
  }));
  $this->lazyObject
    ->__setCloner($this
    ->getClosure(array(
    $cb,
    'cb',
  )));
  $cloned = clone $this->lazyObject;
  $this
    ->assertSame('clonedAssociation', $cloned->publicAssociation);
  $this
    ->assertNotSame($cloned, $lazyObject, 'a clone of the lazy object is retrieved');
}