3 namespace Doctrine\Tests\Common\Persistence\Mapping;
5 use Doctrine\Tests\DoctrineTestCase;
6 use Doctrine\Common\Persistence\Mapping\Driver\DefaultFileLocator;
8 class DefaultFileLocatorTest extends DoctrineTestCase
10 public function testGetPaths()
12 $path = __DIR__ . "/_files";
14 $locator = new DefaultFileLocator(array($path));
15 $this->assertEquals(array($path), $locator->getPaths());
17 $locator = new DefaultFileLocator($path);
18 $this->assertEquals(array($path), $locator->getPaths());
21 public function testGetFileExtension()
23 $locator = new DefaultFileLocator(array(), ".yml");
24 $this->assertEquals(".yml", $locator->getFileExtension());
25 $locator->setFileExtension(".xml");
26 $this->assertEquals(".xml", $locator->getFileExtension());
29 public function testUniquePaths()
31 $path = __DIR__ . "/_files";
33 $locator = new DefaultFileLocator(array($path, $path));
34 $this->assertEquals(array($path), $locator->getPaths());
37 public function testFindMappingFile()
39 $path = __DIR__ . "/_files";
41 $locator = new DefaultFileLocator(array($path), ".yml");
43 $this->assertEquals(__DIR__ . '/_files' . DIRECTORY_SEPARATOR . 'stdClass.yml', $locator->findMappingFile('stdClass'));
46 public function testFindMappingFileNotFound()
48 $path = __DIR__ . "/_files";
50 $locator = new DefaultFileLocator(array($path), ".yml");
52 $this->setExpectedException(
53 'Doctrine\Common\Persistence\Mapping\MappingException',
54 "No mapping file found named 'stdClass2.yml' for class 'stdClass2'"
56 $locator->findMappingFile('stdClass2');
59 public function testGetAllClassNames()
61 $path = __DIR__ . "/_files";
63 $locator = new DefaultFileLocator(array($path), ".yml");
64 $classes = $locator->getAllClassNames(null);
67 $this->assertEquals(array('global', 'stdClass'), $classes);
68 $this->assertEquals(array('stdClass'), $locator->getAllClassNames("global"));
71 public function testGetAllClassNamesNonMatchingFileExtension()
73 $path = __DIR__ . "/_files";
75 $locator = new DefaultFileLocator(array($path), ".xml");
76 $this->assertEquals(array(), $locator->getAllClassNames("global"));
79 public function testFileExists()
81 $path = __DIR__ . "/_files";
83 $locator = new DefaultFileLocator(array($path), ".yml");
85 $this->assertTrue($locator->fileExists("stdClass"));
86 $this->assertFalse($locator->fileExists("stdClass2"));
87 $this->assertTrue($locator->fileExists("global"));
88 $this->assertFalse($locator->fileExists("global2"));