-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathDefaultFileLocatorTest.php
99 lines (75 loc) · 3.01 KB
/
DefaultFileLocatorTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
namespace Doctrine\Tests\Common\Persistence\Mapping;
use Doctrine\Common\Persistence\Mapping\Driver\DefaultFileLocator;
use Doctrine\Common\Persistence\Mapping\MappingException;
use Doctrine\Tests\DoctrineTestCase;
use const DIRECTORY_SEPARATOR;
use function sort;
class DefaultFileLocatorTest extends DoctrineTestCase
{
public function testGetPaths()
{
$path = __DIR__ . '/_files';
$locator = new DefaultFileLocator([$path]);
self::assertSame([$path], $locator->getPaths());
$locator = new DefaultFileLocator($path);
self::assertSame([$path], $locator->getPaths());
}
public function testGetFileExtension()
{
$locator = new DefaultFileLocator([], '.yml');
self::assertSame('.yml', $locator->getFileExtension());
$locator->setFileExtension('.xml');
self::assertSame('.xml', $locator->getFileExtension());
}
public function testUniquePaths()
{
$path = __DIR__ . '/_files';
$locator = new DefaultFileLocator([$path, $path]);
self::assertSame([$path], $locator->getPaths());
}
public function testFindMappingFile()
{
$path = __DIR__ . '/_files';
$locator = new DefaultFileLocator([$path], '.yml');
self::assertSame(__DIR__ . '/_files' . DIRECTORY_SEPARATOR . 'stdClass.yml', $locator->findMappingFile('stdClass'));
}
public function testFindMappingFileNotFound()
{
$path = __DIR__ . '/_files';
$locator = new DefaultFileLocator([$path], '.yml');
$this->expectException(MappingException::class);
$this->expectExceptionMessage("No mapping file found named 'stdClass2.yml' for class 'stdClass2'");
$locator->findMappingFile('stdClass2');
}
public function testGetAllClassNames()
{
$path = __DIR__ . '/_files';
$locator = new DefaultFileLocator([$path], '.yml');
$allClasses = $locator->getAllClassNames(null);
$globalClasses = $locator->getAllClassNames('global');
$expectedAllClasses = ['global', 'stdClass', 'subDirClass'];
$expectedGlobalClasses = ['subDirClass', 'stdClass'];
sort($allClasses);
sort($globalClasses);
sort($expectedAllClasses);
sort($expectedGlobalClasses);
self::assertSame($expectedAllClasses, $allClasses);
self::assertSame($expectedGlobalClasses, $globalClasses);
}
public function testGetAllClassNamesNonMatchingFileExtension()
{
$path = __DIR__ . '/_files';
$locator = new DefaultFileLocator([$path], '.xml');
self::assertSame([], $locator->getAllClassNames('global'));
}
public function testFileExists()
{
$path = __DIR__ . '/_files';
$locator = new DefaultFileLocator([$path], '.yml');
self::assertTrue($locator->fileExists('stdClass'));
self::assertFalse($locator->fileExists('stdClass2'));
self::assertTrue($locator->fileExists('global'));
self::assertFalse($locator->fileExists('global2'));
}
}