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