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