|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* ***************************************************************************** |
|
4
|
|
|
* Contributions to this work were made on behalf of the GÉANT project, a |
|
5
|
|
|
* project that has received funding from the European Union’s Framework |
|
6
|
|
|
* Programme 7 under Grant Agreements No. 238875 (GN3) and No. 605243 (GN3plus), |
|
7
|
|
|
* Horizon 2020 research and innovation programme under Grant Agreements No. |
|
8
|
|
|
* 691567 (GN4-1) and No. 731122 (GN4-2). |
|
9
|
|
|
* On behalf of the aforementioned projects, GEANT Association is the sole owner |
|
10
|
|
|
* of the copyright in all material which was developed by a member of the GÉANT |
|
11
|
|
|
* project. GÉANT Vereniging (Association) is registered with the Chamber of |
|
12
|
|
|
* Commerce in Amsterdam with registration number 40535155 and operates in the |
|
13
|
|
|
* UK as a branch of GÉANT Vereniging. |
|
14
|
|
|
* |
|
15
|
|
|
* Registered office: Hoekenrode 3, 1102BR Amsterdam, The Netherlands. |
|
16
|
|
|
* UK branch address: City House, 126-130 Hills Road, Cambridge CB2 1PQ, UK |
|
17
|
|
|
* |
|
18
|
|
|
* License: see the web/copyright.inc.php file in the file structure or |
|
19
|
|
|
* <base_url>/copyright.php after deploying the software |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
use core\autoloader\Psr4Autoloader; |
|
23
|
|
|
|
|
24
|
|
|
class MockPsr4Autoloader extends Psr4Autoloader |
|
25
|
|
|
{ |
|
26
|
|
|
protected $files = array(); |
|
27
|
|
|
|
|
28
|
|
|
public function setFiles(array $files) |
|
29
|
|
|
{ |
|
30
|
|
|
$this->files = $files; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
protected function requireFile($file) |
|
34
|
|
|
{ |
|
35
|
|
|
return in_array($file, $this->files); |
|
36
|
|
|
} |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
class Psr4AutoloaderTest extends \PHPUnit\Framework\TestCase |
|
40
|
|
|
{ |
|
41
|
|
|
protected $loader; |
|
42
|
|
|
|
|
43
|
|
|
protected function setUp() |
|
44
|
|
|
{ |
|
45
|
|
|
$this->loader = new MockPsr4Autoloader; |
|
46
|
|
|
|
|
47
|
|
|
$this->loader->setFiles(array( |
|
48
|
|
|
'/vendor/foo.bar/src/ClassName.php', |
|
49
|
|
|
'/vendor/foo.bar/src/DoomClassName.php', |
|
50
|
|
|
'/vendor/foo.bar/tests/ClassNameTest.php', |
|
51
|
|
|
'/vendor/foo.bardoom/src/ClassName.php', |
|
52
|
|
|
'/vendor/foo.bar.baz.dib/src/ClassName.php', |
|
53
|
|
|
'/vendor/foo.bar.baz.dib.zim.gir/src/ClassName.php', |
|
54
|
|
|
)); |
|
55
|
|
|
|
|
56
|
|
|
$this->loader->addNamespace( |
|
57
|
|
|
'Foo\Bar', |
|
58
|
|
|
'/vendor/foo.bar/src' |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
$this->loader->addNamespace( |
|
62
|
|
|
'Foo\Bar', |
|
63
|
|
|
'/vendor/foo.bar/tests' |
|
64
|
|
|
); |
|
65
|
|
|
|
|
66
|
|
|
$this->loader->addNamespace( |
|
67
|
|
|
'Foo\BarDoom', |
|
68
|
|
|
'/vendor/foo.bardoom/src' |
|
69
|
|
|
); |
|
70
|
|
|
|
|
71
|
|
|
$this->loader->addNamespace( |
|
72
|
|
|
'Foo\Bar\Baz\Dib', |
|
73
|
|
|
'/vendor/foo.bar.baz.dib/src' |
|
74
|
|
|
); |
|
75
|
|
|
|
|
76
|
|
|
$this->loader->addNamespace( |
|
77
|
|
|
'Foo\Bar\Baz\Dib\Zim\Gir', |
|
78
|
|
|
'/vendor/foo.bar.baz.dib.zim.gir/src' |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function testExistingFile() |
|
83
|
|
|
{ |
|
84
|
|
|
$actual = $this->loader->loadClass('Foo\Bar\ClassName'); |
|
85
|
|
|
$expect = '/vendor/foo.bar/src/ClassName.php'; |
|
86
|
|
|
$this->assertSame($expect, $actual); |
|
87
|
|
|
|
|
88
|
|
|
$actual = $this->loader->loadClass('Foo\Bar\ClassNameTest'); |
|
89
|
|
|
$expect = '/vendor/foo.bar/tests/ClassNameTest.php'; |
|
90
|
|
|
$this->assertSame($expect, $actual); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
public function testMissingFile() |
|
94
|
|
|
{ |
|
95
|
|
|
$actual = $this->loader->loadClass('No_Vendor\No_Package\NoClass'); |
|
96
|
|
|
$this->assertFalse($actual); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
public function testDeepFile() |
|
100
|
|
|
{ |
|
101
|
|
|
$actual = $this->loader->loadClass('Foo\Bar\Baz\Dib\Zim\Gir\ClassName'); |
|
102
|
|
|
$expect = '/vendor/foo.bar.baz.dib.zim.gir/src/ClassName.php'; |
|
103
|
|
|
$this->assertSame($expect, $actual); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function testConfusion() |
|
107
|
|
|
{ |
|
108
|
|
|
$actual = $this->loader->loadClass('Foo\Bar\DoomClassName'); |
|
109
|
|
|
$expect = '/vendor/foo.bar/src/DoomClassName.php'; |
|
110
|
|
|
$this->assertSame($expect, $actual); |
|
111
|
|
|
|
|
112
|
|
|
$actual = $this->loader->loadClass('Foo\BarDoom\ClassName'); |
|
113
|
|
|
$expect = '/vendor/foo.bardoom/src/ClassName.php'; |
|
114
|
|
|
$this->assertSame($expect, $actual); |
|
115
|
|
|
} |
|
116
|
|
|
} |