-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPreloaderTest.php
173 lines (165 loc) · 5.28 KB
/
PreloaderTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
<?php
/*
* This file is part of Aplus Framework Autoload Library.
*
* (c) Natan Felles <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Tests\Autoload;
use Framework\Autoload\Autoloader;
use Framework\Autoload\Preloader;
use PHPUnit\Framework\TestCase;
final class PreloaderTest extends TestCase
{
public function testEmptyListFiles() : void
{
$preloader = new Preloader(packagesDir: __DIR__);
self::assertEmpty($preloader->getAutoloader()->getClasses());
self::assertEmpty($preloader->listPackagesFiles());
self::assertEmpty($preloader->listFiles());
self::assertEmpty($preloader->getAutoloader()->getClasses());
}
public function testListFiles() : void
{
$autoloader = new Autoloader();
$autoloader->setNamespace(
'Foo\Bar\Baz',
__DIR__ . '/support'
)->setClass(\OneInterface::class, __DIR__ . '/support/OneInterface.php');
$preloader = new Preloader($autoloader, __DIR__ . '/../vendor/aplus');
$packageFiles = $preloader->listPackagesFiles();
$files = $preloader->listFiles();
self::assertContains(
\realpath(__DIR__ . '/../vendor/aplus/debug/src/Debugger.php'),
$packageFiles
);
self::assertContains(
\realpath(__DIR__ . '/../vendor/aplus/debug/src/Debugger.php'),
$files
);
self::assertNotContains(
\realpath(__DIR__ . '/../vendor/aplus/coding-standard/src/Config.php'),
$files
);
self::assertNotContains(
__DIR__ . '/support/OneClass.php',
$files
);
self::assertContains(
__DIR__ . '/support/OneEnum.php',
$files
);
self::assertContains(
__DIR__ . '/support/OneInterface.php',
$files
);
$classes = $preloader->getAutoloader()->getClasses();
self::assertArrayHasKey(
\Framework\Debug\Debugger::class,
$classes
);
self::assertArrayNotHasKey(
\Framework\CodingStandard\Config::class,
$classes
);
self::assertArrayHasKey(
\Foo\Bar\Baz\OneEnum::class,
$classes
);
self::assertArrayHasKey(
\Foo\Bar\Baz\OneTrait::class,
$classes
);
self::assertArrayNotHasKey(
\OneClass::class,
$classes
);
self::assertArrayHasKey(
\OneInterface::class,
$classes
);
self::assertContains(
$classes[\Framework\Debug\Debugger::class],
$packageFiles
);
self::assertContains(
$classes[\Framework\Debug\Debugger::class],
$files
);
}
public function testPackagesDir() : void
{
$dir = __DIR__ . '/../vendor/aplus';
$preloader = new Preloader(packagesDir: null);
$preloader->setPackagesDir($dir);
self::assertSame(
\realpath($dir) . \DIRECTORY_SEPARATOR,
$preloader->getPackagesDir()
);
self::assertEmpty($preloader->listFiles());
self::assertNotEmpty($preloader->withPackages()->listFiles());
$classes = $preloader->getAutoloader()->getClasses();
self::assertContains(
$classes[\Framework\Debug\Debugger::class],
$preloader->listFiles()
);
self::assertArrayNotHasKey(
\Framework\CodingStandard\Config::class,
$classes
);
$preloader->withDevPackages()->listFiles();
$classes = $preloader->getAutoloader()->getClasses();
self::assertArrayHasKey(
\Framework\CodingStandard\Config::class,
$classes
);
self::assertContains(
$classes[\Framework\CodingStandard\Config::class],
$preloader->withDevPackages()->listFiles()
);
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage('Invalid packages dir: /foo/bar');
$preloader->setPackagesDir('/foo/bar');
}
public function testLoad() : void
{
$preloader = new Preloader(packagesDir: __DIR__ . '/support');
self::assertEmpty($preloader->load());
$preloader->getAutoloader()->setClass(\OneClass::class, __DIR__ . '/support/OneClass.php');
self::assertContains(
__DIR__ . '/support/OneClass.php',
$preloader->load()
);
}
public function testAllDeclarations() : void
{
self::assertContains(
__CLASS__,
Preloader::getAllDeclarations()
);
self::assertContains(
Preloader::class,
Preloader::getAllDeclarations()
);
}
public function testDeclarations() : void
{
self::assertNotContains(
__CLASS__,
Preloader::getDeclarations()
);
self::assertContains(
Preloader::class,
Preloader::getAllDeclarations()
);
}
public function testIncludedFiles() : void
{
self::assertContains(
__FILE__,
Preloader::getIncludedFiles()
);
}
}