forked from doctrine/DoctrineMongoDBBundle
/
AbstractDriverTest.php
74 lines (54 loc) · 2.24 KB
/
AbstractDriverTest.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
<?php
declare(strict_types=1);
namespace Doctrine\Bundle\MongoDBBundle\Tests\Mapping\Driver;
use Doctrine\Persistence\Mapping\Driver\FileDriver;
use Doctrine\Persistence\Mapping\MappingException;
use PHPUnit\Framework\TestCase;
use ReflectionProperty;
abstract class AbstractDriverTest extends TestCase
{
public function testFindMappingFile()
{
$driver = $this->getDriver([
'foo' => 'MyNamespace\MyBundle\DocumentFoo',
$this->getFixtureDir() => 'MyNamespace\MyBundle\Document',
]);
$locator = $this->getDriverLocator($driver);
$this->assertEquals(
$this->getFixtureDir() . '/Foo' . $this->getFileExtension(),
$locator->findMappingFile('MyNamespace\MyBundle\Document\Foo')
);
}
public function testFindMappingFileInSubnamespace()
{
$driver = $this->getDriver([$this->getFixtureDir() => 'MyNamespace\MyBundle\Document']);
$locator = $this->getDriverLocator($driver);
$this->assertEquals(
$this->getFixtureDir() . '/Foo.Bar' . $this->getFileExtension(),
$locator->findMappingFile('MyNamespace\MyBundle\Document\Foo\Bar')
);
}
public function testFindMappingFileNamespacedFoundFileNotFound()
{
$driver = $this->getDriver([$this->getFixtureDir() => 'MyNamespace\MyBundle\Document']);
$this->expectException(MappingException::class);
$locator = $this->getDriverLocator($driver);
$locator->findMappingFile('MyNamespace\MyBundle\Document\Missing');
}
public function testFindMappingNamespaceNotFound()
{
$driver = $this->getDriver([$this->getFixtureDir() => 'MyNamespace\MyBundle\Document']);
$locator = $this->getDriverLocator($driver);
$this->expectException(MappingException::class);
$locator->findMappingFile('MyOtherNamespace\MyBundle\Document\Foo');
}
abstract protected function getFileExtension();
abstract protected function getFixtureDir();
abstract protected function getDriver(array $paths = []);
private function getDriverLocator(FileDriver $driver)
{
$ref = new ReflectionProperty($driver, 'locator');
$ref->setAccessible(true);
return $ref->getValue($driver);
}
}