FileLocatorTest.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace Metadata\Tests\Driver;
  3. use Metadata\Driver\FileLocator;
  4. class FileLocatorTest extends \PHPUnit_Framework_TestCase
  5. {
  6. public function testFindFileForClass()
  7. {
  8. $locator = new FileLocator(array(
  9. 'Metadata\Tests\Driver\Fixture\A' => __DIR__.'/Fixture/A',
  10. 'Metadata\Tests\Driver\Fixture\B' => __DIR__.'/Fixture/B',
  11. 'Metadata\Tests\Driver\Fixture\C' => __DIR__.'/Fixture/C',
  12. ));
  13. $ref = new \ReflectionClass('Metadata\Tests\Driver\Fixture\A\A');
  14. $this->assertEquals(realpath(__DIR__.'/Fixture/A/A.xml'), realpath($locator->findFileForClass($ref, 'xml')));
  15. $ref = new \ReflectionClass('Metadata\Tests\Driver\Fixture\B\B');
  16. $this->assertNull($locator->findFileForClass($ref, 'xml'));
  17. $ref = new \ReflectionClass('Metadata\Tests\Driver\Fixture\C\SubDir\C');
  18. $this->assertEquals(realpath(__DIR__.'/Fixture/C/SubDir.C.yml'), realpath($locator->findFileForClass($ref, 'yml')));
  19. }
  20. public function testTraits()
  21. {
  22. if (version_compare(PHP_VERSION, '5.4.0', '<')) {
  23. $this->markTestSkipped('No traits available');
  24. }
  25. $locator = new FileLocator(array(
  26. 'Metadata\Tests\Driver\Fixture\T' => __DIR__.'/Fixture/T',
  27. ));
  28. $ref = new \ReflectionClass('Metadata\Tests\Driver\Fixture\T\T');
  29. $this->assertEquals(realpath(__DIR__.'/Fixture/T/T.xml'), realpath($locator->findFileForClass($ref, 'xml')));
  30. }
  31. public function testFindFileForGlobalNamespacedClass()
  32. {
  33. $locator = new FileLocator(array(
  34. '' => __DIR__.'/Fixture/D',
  35. ));
  36. require_once __DIR__.'/Fixture/D/D.php';
  37. $ref = new \ReflectionClass('D');
  38. $this->assertEquals(realpath(__DIR__.'/Fixture/D/D.yml'), realpath($locator->findFileForClass($ref, 'yml')));
  39. }
  40. public function testFindAllFiles()
  41. {
  42. $locator = new FileLocator(array(
  43. 'Metadata\Tests\Driver\Fixture\A' => __DIR__.'/Fixture/A',
  44. 'Metadata\Tests\Driver\Fixture\B' => __DIR__.'/Fixture/B',
  45. 'Metadata\Tests\Driver\Fixture\C' => __DIR__.'/Fixture/C',
  46. 'Metadata\Tests\Driver\Fixture\D' => __DIR__.'/Fixture/D'
  47. ));
  48. $this->assertCount(1, $xmlFiles = $locator->findAllClasses('xml'));
  49. $this->assertSame('Metadata\Tests\Driver\Fixture\A\A', $xmlFiles[0]);
  50. $this->assertCount(3, $ymlFiles = $locator->findAllClasses('yml'));
  51. $this->assertSame('Metadata\Tests\Driver\Fixture\B\B', $ymlFiles[0]);
  52. $this->assertSame('Metadata\Tests\Driver\Fixture\C\SubDir\C', $ymlFiles[1]);
  53. $this->assertSame('Metadata\Tests\Driver\Fixture\D\D', $ymlFiles[2]);
  54. }
  55. }