3 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15 * This software consists of voluntary contributions made by many individuals
16 * and is licensed under the LGPL. For more information, see
17 * <http://www.doctrine-project.org>.
20 namespace Doctrine\Tests\ORM\Mapping\Symfony;
25 abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase
27 public function testFindMappingFile()
29 $driver = $this->getDriver(array(
30 'MyNamespace\MySubnamespace\EntityFoo' => 'foo',
31 'MyNamespace\MySubnamespace\Entity' => $this->dir,
34 touch($filename = $this->dir.'/Foo'.$this->getFileExtension());
35 $this->assertEquals($filename, $driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Entity\Foo'));
38 public function testFindMappingFileInSubnamespace()
40 $driver = $this->getDriver(array(
41 'MyNamespace\MySubnamespace\Entity' => $this->dir,
44 touch($filename = $this->dir.'/Foo.Bar'.$this->getFileExtension());
45 $this->assertEquals($filename, $driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Entity\Foo\Bar'));
48 public function testFindMappingFileNamespacedFoundFileNotFound()
50 $this->setExpectedException(
51 'Doctrine\Common\Persistence\Mapping\MappingException',
52 "No mapping file found named '".$this->dir."/Foo".$this->getFileExtension()."' for class 'MyNamespace\MySubnamespace\Entity\Foo'."
55 $driver = $this->getDriver(array(
56 'MyNamespace\MySubnamespace\Entity' => $this->dir,
59 $driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Entity\Foo');
62 public function testFindMappingNamespaceNotFound()
64 $this->setExpectedException(
65 'Doctrine\Common\Persistence\Mapping\MappingException',
66 "No mapping file found named 'Foo".$this->getFileExtension()."' for class 'MyOtherNamespace\MySubnamespace\Entity\Foo'."
69 $driver = $this->getDriver(array(
70 'MyNamespace\MySubnamespace\Entity' => $this->dir,
73 $driver->getLocator()->findMappingFile('MyOtherNamespace\MySubnamespace\Entity\Foo');
76 protected function setUp()
78 $this->dir = sys_get_temp_dir().'/abstract_driver_test';
79 @mkdir($this->dir, 0777, true);
82 protected function tearDown()
84 $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->dir), \RecursiveIteratorIterator::CHILD_FIRST);
86 foreach ($iterator as $path) {
97 abstract protected function getFileExtension();
98 abstract protected function getDriver(array $paths = array());
100 private function setField($obj, $field, $value)
102 $ref = new \ReflectionProperty($obj, $field);
103 $ref->setAccessible(true);
104 $ref->setValue($obj, $value);
107 private function invoke($obj, $method, array $args = array()) {
108 $ref = new \ReflectionMethod($obj, $method);
109 $ref->setAccessible(true);
111 return $ref->invokeArgs($obj, $args);