|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Doctrine MongoDBBundle |
| 5 | + * |
| 6 | + * The code was originally distributed inside the Symfony framework. |
| 7 | + * |
| 8 | + * (c) Fabien Potencier <[email protected]> |
| 9 | + * (c) Doctrine Project |
| 10 | + * |
| 11 | + * For the full copyright and license information, please view the LICENSE |
| 12 | + * file that was distributed with this source code. |
| 13 | + */ |
| 14 | + |
| 15 | +namespace Doctrine\Bundle\MongoDBBundle\Tests\Mapping\Driver; |
| 16 | + |
| 17 | +use Doctrine\Common\Persistence\Mapping\Driver\FileDriver; |
| 18 | + |
| 19 | +abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase |
| 20 | +{ |
| 21 | + public function testFindMappingFile() |
| 22 | + { |
| 23 | + $driver = $this->getDriver(array( |
| 24 | + 'foo' => 'MyNamespace\MyBundle\DocumentFoo', |
| 25 | + $this->getFixtureDir() => 'MyNamespace\MyBundle\Document', |
| 26 | + )); |
| 27 | + |
| 28 | + $locator = $this->getDriverLocator($driver); |
| 29 | + |
| 30 | + $this->assertEquals( |
| 31 | + $this->getFixtureDir() . '/Foo' . $this->getFileExtension(), |
| 32 | + $locator->findMappingFile('MyNamespace\MyBundle\Document\Foo') |
| 33 | + ); |
| 34 | + } |
| 35 | + |
| 36 | + public function testFindMappingFileInSubnamespace() |
| 37 | + { |
| 38 | + $driver = $this->getDriver(array( |
| 39 | + $this->getFixtureDir() => 'MyNamespace\MyBundle\Document', |
| 40 | + )); |
| 41 | + |
| 42 | + $locator = $this->getDriverLocator($driver); |
| 43 | + |
| 44 | + $this->assertEquals( |
| 45 | + $this->getFixtureDir() . '/Foo.Bar' . $this->getFileExtension(), |
| 46 | + $locator->findMappingFile('MyNamespace\MyBundle\Document\Foo\Bar') |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * @expectedException Doctrine\Common\Persistence\Mapping\MappingException |
| 52 | + */ |
| 53 | + public function testFindMappingFileNamespacedFoundFileNotFound() |
| 54 | + { |
| 55 | + $driver = $this->getDriver(array( |
| 56 | + $this->getFixtureDir() => 'MyNamespace\MyBundle\Document', |
| 57 | + )); |
| 58 | + |
| 59 | + $locator = $this->getDriverLocator($driver); |
| 60 | + $locator->findMappingFile('MyNamespace\MyBundle\Document\Missing'); |
| 61 | + } |
| 62 | + |
| 63 | + /** |
| 64 | + * @expectedException Doctrine\Common\Persistence\Mapping\MappingException |
| 65 | + */ |
| 66 | + public function testFindMappingNamespaceNotFound() |
| 67 | + { |
| 68 | + $driver = $this->getDriver(array( |
| 69 | + $this->getFixtureDir() => 'MyNamespace\MyBundle\Document', |
| 70 | + )); |
| 71 | + |
| 72 | + $locator = $this->getDriverLocator($driver); |
| 73 | + $locator->findMappingFile('MyOtherNamespace\MyBundle\Document\Foo'); |
| 74 | + } |
| 75 | + |
| 76 | + abstract protected function getFileExtension(); |
| 77 | + abstract protected function getFixtureDir(); |
| 78 | + abstract protected function getDriver(array $paths = array()); |
| 79 | + |
| 80 | + private function getDriverLocator(FileDriver $driver) |
| 81 | + { |
| 82 | + $ref = new \ReflectionProperty($driver, 'locator'); |
| 83 | + $ref->setAccessible(true); |
| 84 | + |
| 85 | + return $ref->getValue($driver); |
| 86 | + } |
| 87 | +} |
0 commit comments