DriverChainTest.php 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace Doctrine\Tests\ORM\Mapping;
  3. use Doctrine\ORM\Mapping\Driver\Driver;
  4. use Doctrine\ORM\Mapping\Driver\DriverChain;
  5. require_once __DIR__ . '/../../TestInit.php';
  6. class DriverChainTest extends \Doctrine\Tests\OrmTestCase
  7. {
  8. public function testDelegateToMatchingNamespaceDriver()
  9. {
  10. $className = 'Doctrine\Tests\ORM\Mapping\DriverChainEntity';
  11. $classMetadata = new \Doctrine\ORM\Mapping\ClassMetadata($className);
  12. $chain = new DriverChain();
  13. $driver1 = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver');
  14. $driver1->expects($this->never())
  15. ->method('loadMetadataForClass');
  16. $driver1->expectS($this->never())
  17. ->method('isTransient');
  18. $driver2 = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver');
  19. $driver2->expects($this->at(0))
  20. ->method('loadMetadataForClass')
  21. ->with($this->equalTo($className), $this->equalTo($classMetadata));
  22. $driver2->expects($this->at(1))
  23. ->method('isTransient')
  24. ->with($this->equalTo($className))
  25. ->will($this->returnValue( true ));
  26. $chain->addDriver($driver1, 'Doctrine\Tests\Models\Company');
  27. $chain->addDriver($driver2, 'Doctrine\Tests\ORM\Mapping');
  28. $chain->loadMetadataForClass($className, $classMetadata);
  29. $this->assertTrue( $chain->isTransient($className) );
  30. }
  31. public function testLoadMetadata_NoDelegatorFound_ThrowsMappingException()
  32. {
  33. $className = 'Doctrine\Tests\ORM\Mapping\DriverChainEntity';
  34. $classMetadata = new \Doctrine\ORM\Mapping\ClassMetadata($className);
  35. $chain = new DriverChain();
  36. $this->setExpectedException('Doctrine\ORM\Mapping\MappingException');
  37. $chain->loadMetadataForClass($className, $classMetadata);
  38. }
  39. public function testGatherAllClassNames()
  40. {
  41. $className = 'Doctrine\Tests\ORM\Mapping\DriverChainEntity';
  42. $classMetadata = new \Doctrine\ORM\Mapping\ClassMetadata($className);
  43. $chain = new DriverChain();
  44. $driver1 = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver');
  45. $driver1->expects($this->once())
  46. ->method('getAllClassNames')
  47. ->will($this->returnValue(array('Doctrine\Tests\Models\Company\Foo')));
  48. $driver2 = $this->getMock('Doctrine\ORM\Mapping\Driver\Driver');
  49. $driver2->expects($this->once())
  50. ->method('getAllClassNames')
  51. ->will($this->returnValue(array('Doctrine\Tests\ORM\Mapping\Bar', 'Doctrine\Tests\ORM\Mapping\Baz', 'FooBarBaz')));
  52. $chain->addDriver($driver1, 'Doctrine\Tests\Models\Company');
  53. $chain->addDriver($driver2, 'Doctrine\Tests\ORM\Mapping');
  54. $this->assertEquals(array(
  55. 'Doctrine\Tests\Models\Company\Foo',
  56. 'Doctrine\Tests\ORM\Mapping\Bar',
  57. 'Doctrine\Tests\ORM\Mapping\Baz'
  58. ), $chain->getAllClassNames());
  59. }
  60. /**
  61. * @group DDC-706
  62. */
  63. public function testIsTransient()
  64. {
  65. $chain = new DriverChain();
  66. $chain->addDriver($this->createAnnotationDriver(), 'Doctrine\Tests\Models\CMS');
  67. $this->assertTrue($chain->isTransient('stdClass'), "stdClass isTransient");
  68. $this->assertFalse($chain->isTransient('Doctrine\Tests\Models\CMS\CmsUser'), "CmsUser is not Transient");
  69. }
  70. }
  71. class DriverChainEntity
  72. {
  73. }