forked from ClassPreloader/ClassPreloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClassLoaderTest.php
More file actions
137 lines (106 loc) · 3.62 KB
/
Copy pathClassLoaderTest.php
File metadata and controls
137 lines (106 loc) · 3.62 KB
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
<?php
/*
* This file is part of Class Preloader.
*
* (c) Graham Campbell <graham@alt-three.com>
* (c) Michael Dowling <mtdowling@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use ClassPreloader\ClassLoader;
use ClassPreloader\Config;
class ClassLoaderTest extends PHPUnit_Framework_TestCase
{
public function testGetSingleInclude()
{
$config = ClassLoader::getIncludes(function (ClassLoader $loader) {
$loader->register();
new Bar();
});
$expected = [
__DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'Bar.php',
];
$this->assertInstanceOf(Config::class, $config);
$this->assertSame($expected, $config->getFilenames());
}
/**
* @depends testGetSingleInclude
*/
public function testGetManyIncludes()
{
$config = ClassLoader::getIncludes(function (ClassLoader $loader) {
$loader->register();
new Foo();
});
$expected = [
__DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'Bar.php',
__DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'Foo.php',
];
$this->assertInstanceOf(Config::class, $config);
$this->assertSame($expected, $config->getFilenames());
}
public function testGetIncludesFailed()
{
$config = ClassLoader::getIncludes(function (ClassLoader $loader) {
// forget to call register
new Foo();
});
$this->assertEmpty($config->getFilenames());
}
public function testLoadOneClass()
{
$loader = new ClassLoader();
$loader->register();
$loader->loadClass('Bar');
$expected = [
__DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'Bar.php',
];
$this->assertSame($expected, $loader->getFilenames());
}
/**
* @depends testLoadOneClass
*/
public function testLoadManyClasses()
{
$loader = new ClassLoader();
$loader->register();
$loader->loadClass('Foo');
$expected = [
__DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'Bar.php',
__DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'Foo.php',
];
$this->assertSame($expected, $loader->getFilenames());
// now we've loaded phpunit classes, and we haven't unregistered yet
$files = $loader->getFilenames();
$this->assertContains($expected[0], $files);
$this->assertContains($expected[1], $files);
$this->assertNotSame($expected, $loader->getFilenames());
}
public function testLoadManyClassesWithoutLoader()
{
$loader = new ClassLoader();
$loader->loadClass('Foo');
$expected = [
__DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'Foo.php',
];
$this->assertSame($expected, $loader->getFilenames());
}
/**
* @depends testLoadManyClasses
* @depends testLoadManyClassesWithoutLoader
*/
public function testUnregister()
{
$loader = new ClassLoader();
$loader->register();
$loader->loadClass('Foo');
$loader->unregister();
$this->assertTrue(true); // force load in phpunit classes
$expected = [
__DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'Bar.php',
__DIR__.DIRECTORY_SEPARATOR.'stubs'.DIRECTORY_SEPARATOR.'Foo.php',
];
$this->assertSame($expected, $loader->getFilenames()); // phpunit classes not present
}
}