DriverChainTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace Metadata\Tests\Driver;
  3. use Metadata\ClassMetadata;
  4. use Metadata\Driver\DriverChain;
  5. class DriverChainTest extends \PHPUnit_Framework_TestCase
  6. {
  7. public function testLoadMetadataForClass()
  8. {
  9. $driver = $this->getMock('Metadata\\Driver\\DriverInterface');
  10. $driver
  11. ->expects($this->once())
  12. ->method('loadMetadataForClass')
  13. ->will($this->returnValue($metadata = new ClassMetadata('\stdClass')))
  14. ;
  15. $chain = new DriverChain(array($driver));
  16. $this->assertSame($metadata, $chain->loadMetadataForClass(new \ReflectionClass('\stdClass')));
  17. }
  18. public function testGetAllClassNames()
  19. {
  20. $driver1 = $this->getMock('Metadata\\Driver\\AdvancedDriverInterface');
  21. $driver1
  22. ->expects($this->once())
  23. ->method('getAllClassNames')
  24. ->will($this->returnValue(array('Foo')));
  25. $driver2 = $this->getMock('Metadata\\Driver\\AdvancedDriverInterface');
  26. $driver2
  27. ->expects($this->once())
  28. ->method('getAllClassNames')
  29. ->will($this->returnValue(array('Bar')));
  30. $chain = new DriverChain(array($driver1, $driver2));
  31. $this->assertSame(array('Foo', 'Bar'), $chain->getAllClassNames());
  32. }
  33. public function testLoadMetadataForClassReturnsNullWhenNoMetadataIsFound()
  34. {
  35. $driver = new DriverChain(array());
  36. $this->assertNull($driver->loadMetadataForClass(new \ReflectionClass('\stdClass')));
  37. $driver = $this->getMock('Metadata\\Driver\\DriverInterface');
  38. $driver
  39. ->expects($this->once())
  40. ->method('loadMetadataForClass')
  41. ->will($this->returnValue(null))
  42. ;
  43. $driverChain = new DriverChain(array($driver));
  44. $this->assertNull($driver->loadMetadataForClass(new \ReflectionClass('\stdClass')));
  45. }
  46. public function testGetAllClassNamesThrowsException()
  47. {
  48. $this->setExpectedException('RuntimeException');
  49. $driver = $this->getMock('Metadata\\Driver\\DriverInterface');
  50. $driver->expects($this->never())->method('getAllClassNames');
  51. $chain = new DriverChain(array($driver));
  52. $chain->getAllClassNames();
  53. }
  54. }