You are here

ManagerRegistryTest.php in Plug 7

File

lib/doctrine/common/tests/Doctrine/Tests/Common/Persistence/ManagerRegistryTest.php
View source
<?php

namespace Doctrine\Tests\Common\Persistence;

use PHPUnit_Framework_MockObject_Generator;
use Doctrine\Common\Persistence\AbstractManagerRegistry;
use Doctrine\Tests\Common\Persistence\Mapping\TestClassMetadataFactory;
use Doctrine\Tests\DoctrineTestCase;

/**
 * @groups DCOM-270
 * @uses Doctrine\Tests\Common\Persistence\TestObject
 */
class ManagerRegistryTest extends DoctrineTestCase {

  /**
   * @var TestManagerRegistry
   */
  private $mr;

  /**
   * {@inheritdoc}
   */
  public function setUp() {
    $this->mr = new TestManagerRegistry('ORM', array(
      'default_connection',
    ), array(
      'default_manager',
    ), 'default', 'default', 'Doctrine\\Common\\Persistence\\ObjectManagerAware');
  }
  public function testGetManagerForClass() {
    $this->mr
      ->getManagerForClass('Doctrine\\Tests\\Common\\Persistence\\TestObject');
  }
  public function testGetManagerForInvalidClass() {
    $this
      ->setExpectedException('ReflectionException', 'Class Doctrine\\Tests\\Common\\Persistence\\TestObjectInexistent does not exist');
    $this->mr
      ->getManagerForClass('prefix:TestObjectInexistent');
  }
  public function testGetManagerForAliasedClass() {
    $this->mr
      ->getManagerForClass('prefix:TestObject');
  }
  public function testGetManagerForInvalidAliasedClass() {
    $this
      ->setExpectedException('ReflectionException', 'Class Doctrine\\Tests\\Common\\Persistence\\TestObject:Foo does not exist');
    $this->mr
      ->getManagerForClass('prefix:TestObject:Foo');
  }

}
class TestManager {
  public function getMetadataFactory() {
    $driver = PHPUnit_Framework_MockObject_Generator::getMock('Doctrine\\Common\\Persistence\\Mapping\\Driver\\MappingDriver');
    $metadata = PHPUnit_Framework_MockObject_Generator::getMock('Doctrine\\Common\\Persistence\\Mapping\\ClassMetadata');
    return new TestClassMetadataFactory($driver, $metadata);
  }

}
class TestManagerRegistry extends AbstractManagerRegistry {
  protected function getService($name) {
    return new TestManager();
  }

  /**
   * {@inheritdoc}
   */
  protected function resetService($name) {
  }
  public function getAliasNamespace($alias) {
    return __NAMESPACE__;
  }

}