/
AutoloadTest.php
112 lines (95 loc) · 2.62 KB
/
AutoloadTest.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
<?php
/**
* Testing XH_autoload().
*
* @category Testing
* @package XH
* @author The CMSimple_XH developers <devs@cmsimple-xh.org>
* @copyright 2017 The CMSimple_XH developers <http://cmsimple-xh.org/?The_Team>
* @license http://www.gnu.org/licenses/gpl-3.0.en.html GNU GPLv3
* @link http://cmsimple-xh.org/
*/
namespace XH;
use org\bovigo\vfs\vfsStream;
use org\bovigo\vfs\vfsStreamDirectory;
/**
* A test case for XH_autoload().
*
* @category Testing
* @package XH
* @author The CMSimple_XH developers <devs@cmsimple-xh.org>
* @license http://www.gnu.org/licenses/gpl-3.0.en.html GNU GPLv3
* @link http://cmsimple-xh.org/
* @since 1.7
*/
class AutoloadTest extends TestCase
{
const CLASS_XH_FOO = <<<'EOT'
<?php
namespace XH;
class Foo {}
EOT;
const CLASS_XH_FOO_BAR = <<<'EOT'
<?php
namespace XH\Foo;
class Bar {}
EOT;
const CLASS_FOO_PLUGIN = <<<'EOT'
<?php
namespace Foo;
class Plugin {}
EOT;
const CLASS_FOO = <<<'EOT'
<?php
class Foo{}
EOT;
/**
* @var vfsStreamDirectory
*/
protected $root;
protected function setUp()
{
global $pth;
$this->root = vfsStream::setup('root/');
mkdir(vfsStream::url('root/cmsimple/classes/foo'), 0777, true);
file_put_contents(vfsStream::url('root/cmsimple/classes/Foo.php'), self::CLASS_XH_FOO);
file_put_contents(vfsStream::url('root/cmsimple/classes/foo/Bar.php'), self::CLASS_XH_FOO_BAR);
mkdir(vfsStream::url('root/plugins/foo/classes'), 0777, true);
file_put_contents(vfsStream::url('root/plugins/foo/classes/Plugin.php'), self::CLASS_FOO_PLUGIN);
$pth = array(
'folder' => array(
'classes' => vfsStream::url('root/cmsimple/classes/'),
'plugins' => vfsStream::url('root/plugins/')
)
);
spl_autoload_register('XH_autoload');
}
protected function tearDown()
{
spl_autoload_unregister('XH_autoload');
}
public function testCoreClass()
{
$this->assertInstanceOf(Foo::class, new Foo);
}
public function testCoreClassInSubnamespace()
{
$this->assertInstanceOf(Foo\Bar::class, new Foo\Bar);
}
public function testPluginClass()
{
$this->assertInstanceOf(\Foo\Plugin::class, new \Foo\Plugin);
}
public function testClassAlias()
{
$this->assertTrue(class_exists('XH_Foo'));
}
public function testNonExistentClass()
{
$this->assertFalse(class_exists(Bar::class));
}
public function testNonNamespacedClassIsNotLoaded()
{
$this->assertFalse(class_exists('\Foo'));
}
}