class ClassMetadataFactoryTest

Hierarchy

Expanded class hierarchy of ClassMetadataFactoryTest

File

drupal/core/vendor/doctrine/common/tests/Doctrine/Tests/Common/Persistence/Mapping/ClassMetadataFactoryTest.php, line 12

Namespace

Doctrine\Tests\Common\Persistence\Mapping
View source
class ClassMetadataFactoryTest extends DoctrineTestCase {

  /**
   * @var TestClassMetadataFactory
   */
  private $cmf;
  public function setUp() {
    $driver = $this
      ->getMock('Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriver');
    $metadata = $this
      ->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
    $this->cmf = new TestClassMetadataFactory($driver, $metadata);
  }
  public function testGetCacheDriver() {
    $this
      ->assertNull($this->cmf
      ->getCacheDriver());
    $cache = new ArrayCache();
    $this->cmf
      ->setCacheDriver($cache);
    $this
      ->assertSame($cache, $this->cmf
      ->getCacheDriver());
  }
  public function testGetMetadataFor() {
    $metadata = $this->cmf
      ->getMetadataFor('stdClass');
    $this
      ->assertInstanceOf('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata', $metadata);
    $this
      ->assertTrue($this->cmf
      ->hasMetadataFor('stdClass'));
  }
  public function testGetParentMetadata() {
    $metadata = $this->cmf
      ->getMetadataFor(__NAMESPACE__ . '\\ChildEntity');
    $this
      ->assertInstanceOf('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata', $metadata);
    $this
      ->assertTrue($this->cmf
      ->hasMetadataFor(__NAMESPACE__ . '\\ChildEntity'));
    $this
      ->assertTrue($this->cmf
      ->hasMetadataFor(__NAMESPACE__ . '\\RootEntity'));
  }
  public function testGetCachedMetadata() {
    $metadata = $this
      ->getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
    $cache = new ArrayCache();
    $cache
      ->save(__NAMESPACE__ . '\\ChildEntity$CLASSMETADATA', $metadata);
    $this->cmf
      ->setCacheDriver($cache);
    $loadedMetadata = $this->cmf
      ->getMetadataFor(__NAMESPACE__ . '\\ChildEntity');
    $this
      ->assertSame($loadedMetadata, $metadata);
  }
  public function testCacheGetMetadataFor() {
    $cache = new ArrayCache();
    $this->cmf
      ->setCacheDriver($cache);
    $loadedMetadata = $this->cmf
      ->getMetadataFor(__NAMESPACE__ . '\\ChildEntity');
    $this
      ->assertSame($loadedMetadata, $cache
      ->fetch(__NAMESPACE__ . '\\ChildEntity$CLASSMETADATA'));
  }
  public function testGetAliasedMetadata() {
    $loadedMetadata = $this->cmf
      ->getMetadataFor('prefix:ChildEntity');
    $this
      ->assertTrue($this->cmf
      ->hasMetadataFor(__NAMESPACE__ . '\\ChildEntity'));
    $this
      ->assertTrue($this->cmf
      ->hasMetadataFor('prefix:ChildEntity'));
  }

}

Members