AutoloaderTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 148
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 0
loc 148
rs 10
c 1
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstructCorrectInstance() 0 6 1
A testRegister() 0 6 1
A testUnregister() 0 7 1
A testLoadSuccess() 0 13 1
A testLoadSuccessExtraSlashedNamespace() 0 13 1
A testLoadSuccessExtraForwardSlashedPath() 0 13 1
A testLoadSuccessExtraBackwardSlashedPath() 0 13 1
A testLoadSuccessExtraMixedSlashedPath() 0 13 1
A testLoadUnknownClass() 0 11 1
1
<?php
2
3
namespace OpCacheGUITest\Unit\Core;
4
5
use OpCacheGUI\Core\Autoloader;
6
use PHPUnit\Framework\TestCase;
7
8
class AutoloaderTest extends TestCase
9
{
10
    /**
11
     * @covers OpCacheGUI\Core\Autoloader::__construct
12
     */
13
    public function testConstructCorrectInstance()
14
    {
15
        $autoloader = new Autoloader('Test', '/');
16
17
        $this->assertInstanceOf(Autoloader::class, $autoloader);
18
    }
19
20
    /**
21
     * @covers OpCacheGUI\Core\Autoloader::__construct
22
     * @covers OpCacheGUI\Core\Autoloader::register
23
     */
24
    public function testRegister()
25
    {
26
        $autoloader = new Autoloader('Test', '/');
27
28
        $this->assertTrue($autoloader->register());
29
    }
30
31
    /**
32
     * @covers OpCacheGUI\Core\Autoloader::__construct
33
     * @covers OpCacheGUI\Core\Autoloader::register
34
     * @covers OpCacheGUI\Core\Autoloader::unregister
35
     */
36
    public function testUnregister()
37
    {
38
        $autoloader = new Autoloader('Test', '/');
39
40
        $this->assertTrue($autoloader->register());
41
        $this->assertTrue($autoloader->unregister());
42
    }
43
44
    /**
45
     * @covers OpCacheGUI\Core\Autoloader::__construct
46
     * @covers OpCacheGUI\Core\Autoloader::register
47
     * @covers OpCacheGUI\Core\Autoloader::load
48
     */
49
    public function testLoadSuccess()
50
    {
51
        $autoloader = new Autoloader(
52
            'FakeProject',
53
            dirname(__DIR__) . '/../Mocks/Core'
54
        );
55
56
        $this->assertTrue($autoloader->register());
57
58
        $someClass = new \FakeProject\NS\SomeClass();
59
60
        $this->assertTrue($someClass->isLoaded());
61
    }
62
63
    /**
64
     * @covers OpCacheGUI\Core\Autoloader::__construct
65
     * @covers OpCacheGUI\Core\Autoloader::register
66
     * @covers OpCacheGUI\Core\Autoloader::load
67
     */
68
    public function testLoadSuccessExtraSlashedNamespace()
69
    {
70
        $autoloader = new Autoloader(
71
            '\\\\FakeProject',
72
            dirname(__DIR__) . '/../Mocks/Core'
73
        );
74
75
        $this->assertTrue($autoloader->register());
76
77
        $someClass = new \FakeProject\NS\SomeClass();
78
79
        $this->assertTrue($someClass->isLoaded());
80
    }
81
82
    /**
83
     * @covers OpCacheGUI\Core\Autoloader::__construct
84
     * @covers OpCacheGUI\Core\Autoloader::register
85
     * @covers OpCacheGUI\Core\Autoloader::load
86
     */
87
    public function testLoadSuccessExtraForwardSlashedPath()
88
    {
89
        $autoloader = new Autoloader(
90
            'FakeProject',
91
            dirname(__DIR__) . '/../Mocks/Core//'
92
        );
93
94
        $this->assertTrue($autoloader->register());
95
96
        $someClass = new \FakeProject\NS\SomeClass();
97
98
        $this->assertTrue($someClass->isLoaded());
99
    }
100
101
    /**
102
     * @covers OpCacheGUI\Core\Autoloader::__construct
103
     * @covers OpCacheGUI\Core\Autoloader::register
104
     * @covers OpCacheGUI\Core\Autoloader::load
105
     */
106
    public function testLoadSuccessExtraBackwardSlashedPath()
107
    {
108
        $autoloader = new Autoloader(
109
            'FakeProject',
110
            dirname(__DIR__) . '/../Mocks/Core\\'
111
        );
112
113
        $this->assertTrue($autoloader->register());
114
115
        $someClass = new \FakeProject\NS\SomeClass();
116
117
        $this->assertTrue($someClass->isLoaded());
118
    }
119
120
    /**
121
     * @covers OpCacheGUI\Core\Autoloader::__construct
122
     * @covers OpCacheGUI\Core\Autoloader::register
123
     * @covers OpCacheGUI\Core\Autoloader::load
124
     */
125
    public function testLoadSuccessExtraMixedSlashedPath()
126
    {
127
        $autoloader = new Autoloader(
128
            'FakeProject',
129
            dirname(__DIR__) . '/../Mocks/Core\\\\/\\//'
130
        );
131
132
        $this->assertTrue($autoloader->register());
133
134
        $someClass = new \FakeProject\NS\SomeClass();
135
136
        $this->assertTrue($someClass->isLoaded());
137
    }
138
139
    /**
140
     * @covers OpCacheGUI\Core\Autoloader::__construct
141
     * @covers OpCacheGUI\Core\Autoloader::register
142
     * @covers OpCacheGUI\Core\Autoloader::load
143
     */
144
    public function testLoadUnknownClass()
145
    {
146
        $autoloader = new Autoloader(
147
            'FakeProject',
148
            dirname(__DIR__) . '/../Mocks/Core\\\\/\\//'
149
        );
150
151
        $this->assertTrue($autoloader->register());
152
153
        $this->assertFalse($autoloader->load('IDontExistClass'));
154
    }
155
}
156