You are here

public function ProxyLogicTest::testInitializedProxyUnserialization in Plug 7

File

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

Class

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

Namespace

Doctrine\Tests\Common\Proxy

Code

public function testInitializedProxyUnserialization() {

  // persister will retrieve the lazy object itself, so that we don't have to re-define all field values
  $this->proxyLoader
    ->expects($this
    ->once())
    ->method('load')
    ->will($this
    ->returnValue($this->lazyObject));
  $this->lazyObject
    ->__setInitializer($this
    ->getSuggestedInitializerImplementation());
  $this->lazyObject
    ->__load();
  $serialized = serialize($this->lazyObject);
  $reflClass = $this->lazyLoadableObjectMetadata
    ->getReflectionClass();

  /* @var $unserialized LazyLoadableObject|Proxy */
  $unserialized = unserialize($serialized);
  $this
    ->assertTrue($unserialized
    ->__isInitialized(), 'serialization didn\'t cause intialization');

  // Checking transient fields
  $this
    ->assertSame('publicTransientFieldValue', $unserialized->publicTransientField, 'transient fields are kept');
  $protectedTransientField = $reflClass
    ->getProperty('protectedTransientField');
  $protectedTransientField
    ->setAccessible(true);
  $this
    ->assertSame('protectedTransientFieldValue', $protectedTransientField
    ->getValue($unserialized), 'transient fields are kept');

  // Checking persistent fields
  $this
    ->assertSame('publicPersistentFieldValue', $unserialized->publicPersistentField, 'persistent fields are kept');
  $protectedPersistentField = $reflClass
    ->getProperty('protectedPersistentField');
  $protectedPersistentField
    ->setAccessible(true);
  $this
    ->assertSame('protectedPersistentFieldValue', $protectedPersistentField
    ->getValue($unserialized), 'persistent fields are kept');

  // Checking identifiers
  $this
    ->assertSame('publicIdentifierFieldValue', $unserialized->publicIdentifierField, 'identifiers are kept');
  $protectedIdentifierField = $reflClass
    ->getProperty('protectedIdentifierField');
  $protectedIdentifierField
    ->setAccessible(true);
  $this
    ->assertSame('protectedIdentifierFieldValue', $protectedIdentifierField
    ->getValue($unserialized), 'identifiers are kept');

  // Checking associations
  $this
    ->assertSame('publicAssociationValue', $unserialized->publicAssociation, 'associations are kept');
  $protectedAssociationField = $reflClass
    ->getProperty('protectedAssociation');
  $protectedAssociationField
    ->setAccessible(true);
  $this
    ->assertSame('protectedAssociationValue', $protectedAssociationField
    ->getValue($unserialized), 'associations are kept');
}