Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / orm / tests / Doctrine / Tests / ORM / Proxy / AutoloaderTest.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\Proxy;
21
22 use Doctrine\Tests\OrmTestCase;
23 use Doctrine\ORM\Proxy\Autoloader;
24
25 /**
26  * @group DDC-1698
27  */
28 class AutoloaderTest extends OrmTestCase
29 {
30     static public function dataResolveFile()
31     {
32         return array(
33             array('/tmp', 'MyProxy', 'MyProxy\__CG__\RealClass', '/tmp' . DIRECTORY_SEPARATOR . '__CG__RealClass.php'),
34             array('/tmp', 'MyProxy\Subdir', 'MyProxy\Subdir\__CG__\RealClass', '/tmp' . DIRECTORY_SEPARATOR . '__CG__RealClass.php'),
35             array('/tmp', 'MyProxy', 'MyProxy\__CG__\Other\RealClass', '/tmp' . DIRECTORY_SEPARATOR . '__CG__OtherRealClass.php'),
36         );
37     }
38
39     /**
40      * @dataProvider dataResolveFile
41      */
42     public function testResolveFile($proxyDir, $proxyNamespace, $className, $expectedProxyFile)
43     {
44         $actualProxyFile = Autoloader::resolveFile($proxyDir, $proxyNamespace, $className);
45         $this->assertEquals($expectedProxyFile, $actualProxyFile);
46     }
47
48     public function testAutoload()
49     {
50         if (file_exists(sys_get_temp_dir() ."/AutoloaderTestClass.php")) {
51             unlink(sys_get_temp_dir() ."/AutoloaderTestClass.php");
52         }
53
54         $autoloader = Autoloader::register(sys_get_temp_dir(), 'ProxyAutoloaderTest', function($proxyDir, $proxyNamespace, $className) {
55             file_put_contents(sys_get_temp_dir() . "/AutoloaderTestClass.php", "<?php namespace ProxyAutoloaderTest; class AutoloaderTestClass {} ");
56         });
57
58         $this->assertTrue(class_exists('ProxyAutoloaderTest\AutoloaderTestClass', true));
59         unlink(sys_get_temp_dir() ."/AutoloaderTestClass.php");
60     }
61 }
62