Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Mapping / Symfony / AbstractDriverTest.php
1 <?php
2 /*
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.
14  *
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>.
18 */
19
20 namespace Doctrine\Tests\ORM\Mapping\Symfony;
21
22 /**
23  * @group DDC-1418
24  */
25 abstract class AbstractDriverTest extends \PHPUnit_Framework_TestCase
26 {
27     public function testFindMappingFile()
28     {
29         $driver = $this->getDriver(array(
30             'MyNamespace\MySubnamespace\EntityFoo' => 'foo',
31             'MyNamespace\MySubnamespace\Entity' => $this->dir,
32         ));
33
34         touch($filename = $this->dir.'/Foo'.$this->getFileExtension());
35         $this->assertEquals($filename, $driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Entity\Foo'));
36     }
37
38     public function testFindMappingFileInSubnamespace()
39     {
40         $driver = $this->getDriver(array(
41             'MyNamespace\MySubnamespace\Entity' => $this->dir,
42         ));
43
44         touch($filename = $this->dir.'/Foo.Bar'.$this->getFileExtension());
45         $this->assertEquals($filename, $driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Entity\Foo\Bar'));
46     }
47
48     public function testFindMappingFileNamespacedFoundFileNotFound()
49     {
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'."
53         );
54
55         $driver = $this->getDriver(array(
56             'MyNamespace\MySubnamespace\Entity' => $this->dir,
57         ));
58
59         $driver->getLocator()->findMappingFile('MyNamespace\MySubnamespace\Entity\Foo');
60     }
61
62     public function testFindMappingNamespaceNotFound()
63     {
64         $this->setExpectedException(
65             'Doctrine\Common\Persistence\Mapping\MappingException',
66             "No mapping file found named 'Foo".$this->getFileExtension()."' for class 'MyOtherNamespace\MySubnamespace\Entity\Foo'."
67         );
68
69         $driver = $this->getDriver(array(
70             'MyNamespace\MySubnamespace\Entity' => $this->dir,
71         ));
72
73         $driver->getLocator()->findMappingFile('MyOtherNamespace\MySubnamespace\Entity\Foo');
74     }
75
76     protected function setUp()
77     {
78         $this->dir = sys_get_temp_dir().'/abstract_driver_test';
79         @mkdir($this->dir, 0777, true);
80     }
81
82     protected function tearDown()
83     {
84         $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($this->dir), \RecursiveIteratorIterator::CHILD_FIRST);
85
86         foreach ($iterator as $path) {
87             if ($path->isDir()) {
88                 @rmdir($path);
89             } else {
90                 @unlink($path);
91             }
92         }
93
94         @rmdir($this->dir);
95     }
96
97     abstract protected function getFileExtension();
98     abstract protected function getDriver(array $paths = array());
99
100     private function setField($obj, $field, $value)
101     {
102         $ref = new \ReflectionProperty($obj, $field);
103         $ref->setAccessible(true);
104         $ref->setValue($obj, $value);
105     }
106
107     private function invoke($obj, $method, array $args = array()) {
108         $ref = new \ReflectionMethod($obj, $method);
109         $ref->setAccessible(true);
110
111         return $ref->invokeArgs($obj, $args);
112     }
113 }