AbstractFileDriverTest.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace Metadata\Tests\Driver;
  3. use Metadata\ClassMetadata;
  4. /**
  5. * @author Jordan Stout <j@jrdn.org>
  6. */
  7. class AbstractFileDriverTest extends \PHPUnit_Framework_TestCase
  8. {
  9. private static $extension = 'jms_metadata.yml';
  10. /** @var \PHPUnit_Framework_MockObject_MockObject */
  11. private $locator;
  12. /** @var \PHPUnit_Framework_MockObject_MockObject */
  13. private $driver;
  14. public function setUp()
  15. {
  16. $this->locator = $this->getMock('Metadata\Driver\FileLocator', array(), array(), '', false);
  17. $this->driver = $this->getMockBuilder('Metadata\Driver\AbstractFileDriver')
  18. ->setConstructorArgs(array($this->locator))
  19. ->getMockForAbstractClass();
  20. $this->driver->expects($this->any())->method('getExtension')->will($this->returnValue(self::$extension));
  21. }
  22. public function testLoadMetadataForClass()
  23. {
  24. $class = new \ReflectionClass('\stdClass');
  25. $this->locator
  26. ->expects($this->once())
  27. ->method('findFileForClass')
  28. ->with($class, self::$extension)
  29. ->will($this->returnValue('Some\Path'));
  30. $this->driver
  31. ->expects($this->once())
  32. ->method('loadMetadataFromFile')
  33. ->with($class, 'Some\Path')
  34. ->will($this->returnValue($metadata = new ClassMetadata('\stdClass')));
  35. $this->assertSame($metadata, $this->driver->loadMetadataForClass($class));
  36. }
  37. public function testLoadMetadataForClassWillReturnNull()
  38. {
  39. $class = new \ReflectionClass('\stdClass');
  40. $this->locator
  41. ->expects($this->once())
  42. ->method('findFileForClass')
  43. ->with($class, self::$extension)
  44. ->will($this->returnValue(null));
  45. $this->assertSame(null, $this->driver->loadMetadataForClass($class));
  46. }
  47. public function testGetAllClassNames()
  48. {
  49. $class = new \ReflectionClass('\stdClass');
  50. $this->locator
  51. ->expects($this->once())
  52. ->method('findAllClasses')
  53. ->with(self::$extension)
  54. ->will($this->returnValue(array('\stdClass')));
  55. $this->assertSame(array('\stdClass'), $this->driver->getAllClassNames($class));
  56. }
  57. public function testGetAllClassNamesThrowsRuntimeException()
  58. {
  59. $this->setExpectedException('RuntimeException');
  60. $locator = $this->getMock('Metadata\Driver\FileLocatorInterface', array(), array(), '', false);
  61. $driver = $this->getMockBuilder('Metadata\Driver\AbstractFileDriver')
  62. ->setConstructorArgs(array($locator))
  63. ->getMockForAbstractClass();
  64. $class = new \ReflectionClass('\stdClass');
  65. $locator->expects($this->never())->method('findAllClasses');
  66. $driver->getAllClassNames($class);
  67. }
  68. }