Failed Conditions
Pull Request — master (#1)
by Jonathan
03:48
created

DefaultFileLocatorTest::testFindMappingFile()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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