OSDN Git Service

refactor functions
[php-libraries/Autoloader.git] / test / RegisterNamespacePath.php
1 <?php
2
3 namespace frostbane\autoloader\test;
4
5 use frostbane\autoloader\Psr0;
6 use PHPUnit_Framework_TestCase;
7
8 class RegisterNamespacePath
9     extends PHPUnit_Framework_TestCase
10 {
11     /* ***************************************************************** */
12     /*                                                                   */
13     /* ***************************************************************** */
14
15     /**
16      * @var Psr0
17      */
18     private $loader;
19
20     /**
21      * @var \ReflectionMethod
22      */
23     private $findClassFile;
24
25     /* ***************************************************************** */
26     /*                                                                   */
27     /* ***************************************************************** */
28
29     public static function
30     setUpBeforeClass()
31     {
32         $loader = Psr0::instance();
33
34         $rexl = new \ReflectionProperty($loader, "__registered");
35
36         $rexl->setAccessible(true);
37         $rexl->setValue($loader, true);
38     }
39
40     public function
41     setUp()
42     {
43         $this->loader = Psr0::instance();
44
45         $this->findClassFile = new \ReflectionMethod($this->loader, "__findClassFile");
46
47         $this->findClassFile->setAccessible(true);
48
49     }
50
51     /* ***************************************************************** */
52     /*                                                                   */
53     /* ***************************************************************** */
54
55     public function
56     testRegisterInvalidNamespace()
57     {
58         $this->setExpectedException("InvalidArgumentException");
59         $this->loader->registerNamespacePath(__DIR__ . "/fixture/classes");
60     }
61
62     public function
63     testRegisterInvalidNamespacePath()
64     {
65         $this->setExpectedException("InvalidArgumentException");
66         $this->loader->registerNamespacePath(array("\\DataNoPrefix", __DIR__ . "/fixture/classes/DataNoPrefix"),
67                                              "some path");
68     }
69
70     public function
71     testRegisterString()
72     {
73         $this->loader->registerNamespacePath("\\DataNoPrefix", __DIR__ . "/fixture/classes/DataNoPrefix");
74
75         $minidatafile = $this->findClassFile->invoke($this->loader, "DataNoPrefix\\MiniData");
76
77         $this->assertNotNull($minidatafile);
78     }
79
80     public function
81     testRegisterArray()
82     {
83         $this->loader->registerNamespacePath(array("\\DataNoPrefix" => __DIR__ . "/fixture/classes/DataNoPrefix",
84                                                    "\\UtilNoPrefix" => __DIR__ . "/fixture/utility/UtilNoPrefix"));
85
86         $minidatafile = $this->findClassFile->invoke($this->loader, "DataNoPrefix\\MiniData");
87         $miniutilfle  = $this->findClassFile->invoke($this->loader, "UtilNoPrefix\\MiniUtil");
88
89         $this->assertNotNull($minidatafile);
90         $this->assertNotNull($miniutilfle);
91     }
92
93     public function
94     testRegisterArray_NoClasses()
95     {
96         $path = __DIR__ . "/fixture/classes/SomePath/thatDoesNotExist";
97
98         $this->assertFalse(file_exists($path));
99
100         $this->loader->registerNamespacePath(array("\\DataNoPrefix" => $path));
101
102         $minidatafile = $this->findClassFile->invoke($this->loader, "DataNoPrefix\\MiniData");
103         $miniutilfle  = $this->findClassFile->invoke($this->loader, "UtilNoPrefix\\MiniUtil");
104
105         $this->assertNull($minidatafile);
106         $this->assertNull($miniutilfle);
107     }
108
109     /* ***************************************************************** */
110     /*                                                                   */
111     /* ***************************************************************** */
112
113     public function
114     tearDown()
115     {
116         $this->loader->clearPaths();
117     }
118
119     public static function
120     tearDownAfterClass()
121     {
122     }
123 }