Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / common / tests / Doctrine / Tests / Common / Persistence / Mapping / FileDriverTest.php
1 <?php
2
3 namespace Doctrine\Tests\Common\Persistence\Mapping;
4
5 use Doctrine\Tests\DoctrineTestCase;
6 use Doctrine\Common\Persistence\Mapping\Driver\FileDriver;
7 use Doctrine\Common\Persistence\Mapping\ClassMetadata;
8
9 class FileDriverTest extends DoctrineTestCase
10 {
11     public function testGlobalBasename()
12     {
13         $driver = new TestFileDriver(array());
14
15         $this->assertNull($driver->getGlobalBasename());
16
17         $driver->setGlobalBasename("global");
18         $this->assertEquals("global", $driver->getGlobalBasename());
19     }
20
21     public function testGetElementFromGlobalFile()
22     {
23         $driver = new TestFileDriver($this->newLocator());
24         $driver->setGlobalBasename("global");
25
26         $element = $driver->getElement('stdGlobal');
27
28         $this->assertEquals('stdGlobal', $element);
29     }
30
31     public function testGetElementFromFile()
32     {
33         $locator = $this->newLocator();
34         $locator->expects($this->once())
35                 ->method('findMappingFile')
36                 ->with($this->equalTo('stdClass'))
37                 ->will($this->returnValue(__DIR__ . '/_files/stdClass.yml'));
38
39         $driver = new TestFileDriver($locator);
40
41         $this->assertEquals('stdClass', $driver->getElement('stdClass'));
42     }
43
44     public function testGetAllClassNamesGlobalBasename()
45     {
46         $driver = new TestFileDriver($this->newLocator());
47         $driver->setGlobalBasename("global");
48
49         $classNames = $driver->getAllClassNames();
50
51         $this->assertEquals(array('stdGlobal', 'stdGlobal2'), $classNames);
52     }
53
54     public function testGetAllClassNamesFromMappingFile()
55     {
56         $locator = $this->newLocator();
57         $locator->expects($this->any())
58                 ->method('getAllClassNames')
59                 ->with($this->equalTo(null))
60                 ->will($this->returnValue(array('stdClass')));
61         $driver = new TestFileDriver($locator);
62
63         $classNames = $driver->getAllClassNames();
64
65         $this->assertEquals(array('stdClass'), $classNames);
66     }
67
68     public function testGetAllClassNamesBothSources()
69     {
70         $locator = $this->newLocator();
71         $locator->expects($this->any())
72                 ->method('getAllClassNames')
73                 ->with($this->equalTo('global'))
74                 ->will($this->returnValue(array('stdClass')));
75         $driver = new TestFileDriver($locator);
76         $driver->setGlobalBasename("global");
77
78         $classNames = $driver->getAllClassNames();
79
80         $this->assertEquals(array('stdGlobal', 'stdGlobal2', 'stdClass'), $classNames);
81     }
82
83     public function testIsNotTransient()
84     {
85         $locator = $this->newLocator();
86         $locator->expects($this->once())
87                 ->method('fileExists')
88                 ->with($this->equalTo('stdClass'))
89                 ->will($this->returnValue( true ));
90
91         $driver = new TestFileDriver($locator);
92         $driver->setGlobalBasename("global");
93
94         $this->assertFalse($driver->isTransient('stdClass'));
95         $this->assertFalse($driver->isTransient('stdGlobal'));
96         $this->assertFalse($driver->isTransient('stdGlobal2'));
97     }
98
99     public function testIsTransient()
100     {
101         $locator = $this->newLocator();
102         $locator->expects($this->once())
103                 ->method('fileExists')
104                 ->with($this->equalTo('stdClass2'))
105                 ->will($this->returnValue( false ));
106
107         $driver = new TestFileDriver($locator);
108
109         $this->assertTrue($driver->isTransient('stdClass2'));
110     }
111
112     public function testNonLocatorFallback()
113     {
114         $driver = new TestFileDriver(__DIR__ . '/_files', '.yml');
115         $this->assertTrue($driver->isTransient('stdClass2'));
116         $this->assertFalse($driver->isTransient('stdClass'));
117     }
118
119     private function newLocator()
120     {
121         $locator = $this->getMock('Doctrine\Common\Persistence\Mapping\Driver\FileLocator');
122         $locator->expects($this->any())->method('getFileExtension')->will($this->returnValue('.yml'));
123         $locator->expects($this->any())->method('getPaths')->will($this->returnValue(array(__DIR__ . "/_files")));
124         return $locator;
125     }
126 }
127
128 class TestFileDriver extends FileDriver
129 {
130     protected function loadMappingFile($file)
131     {
132         if (strpos($file, "global.yml") !== false) {
133             return array('stdGlobal' => 'stdGlobal', 'stdGlobal2' => 'stdGlobal2');
134         }
135         return array('stdClass' => 'stdClass');
136     }
137
138     public function loadMetadataForClass($className, ClassMetadata $metadata)
139     {
140
141     }
142 }