1<?php
2
3namespace OAuthTest\Unit\Commen\Core;
4
5use OAuth\Common\AutoLoader;
6
7class AutoLoaderTest extends \PHPUnit_Framework_TestCase
8{
9    /**
10     * @covers OAuth\Common\AutoLoader::__construct
11     * @covers OAuth\Common\AutoLoader::register
12     */
13    public function testRegister()
14    {
15        $autoloader = new AutoLoader('Test', '/');
16
17        $this->assertTrue($autoloader->register());
18    }
19
20    /**
21     * @covers OAuth\Common\AutoLoader::__construct
22     * @covers OAuth\Common\AutoLoader::register
23     * @covers OAuth\Common\AutoLoader::unregister
24     */
25    public function testUnregister()
26    {
27        $autoloader = new AutoLoader('Test', '/');
28
29        $this->assertTrue($autoloader->register());
30        $this->assertTrue($autoloader->unregister());
31    }
32
33    /**
34     * @covers OAuth\Common\AutoLoader::__construct
35     * @covers OAuth\Common\AutoLoader::register
36     * @covers OAuth\Common\AutoLoader::load
37     */
38    public function testLoadSuccess()
39    {
40        $autoloader = new AutoLoader('FakeProject', dirname(__DIR__) . '/../Mocks/Common');
41
42        $this->assertTrue($autoloader->register());
43
44        $someClass = new \FakeProject\NS\SomeClass();
45
46        $this->assertTrue($someClass->isLoaded());
47    }
48
49    /**
50     * @covers OAuth\Common\AutoLoader::__construct
51     * @covers OAuth\Common\AutoLoader::register
52     * @covers OAuth\Common\AutoLoader::load
53     */
54    public function testLoadSuccessExtraSlashedNamespace()
55    {
56        $autoloader = new AutoLoader('\\\\FakeProject', dirname(__DIR__) . '/../Mocks/Common');
57
58        $this->assertTrue($autoloader->register());
59
60        $someClass = new \FakeProject\NS\SomeClass();
61
62        $this->assertTrue($someClass->isLoaded());
63    }
64
65    /**
66     * @covers OAuth\Common\AutoLoader::__construct
67     * @covers OAuth\Common\AutoLoader::register
68     * @covers OAuth\Common\AutoLoader::load
69     */
70    public function testLoadSuccessExtraForwardSlashedPath()
71    {
72        $autoloader = new AutoLoader('FakeProject', dirname(__DIR__) . '/../Mocks/Common//');
73
74        $this->assertTrue($autoloader->register());
75
76        $someClass = new \FakeProject\NS\SomeClass();
77
78        $this->assertTrue($someClass->isLoaded());
79    }
80
81    /**
82     * @covers OAuth\Common\AutoLoader::__construct
83     * @covers OAuth\Common\AutoLoader::register
84     * @covers OAuth\Common\AutoLoader::load
85     */
86    public function testLoadSuccessExtraBackwardSlashedPath()
87    {
88        $autoloader = new AutoLoader('FakeProject', dirname(__DIR__) . '/../Mocks/Common\\');
89
90        $this->assertTrue($autoloader->register());
91
92        $someClass = new \FakeProject\NS\SomeClass();
93
94        $this->assertTrue($someClass->isLoaded());
95    }
96
97    /**
98     * @covers OAuth\Common\AutoLoader::__construct
99     * @covers OAuth\Common\AutoLoader::register
100     * @covers OAuth\Common\AutoLoader::load
101     */
102    public function testLoadSuccessExtraMixedSlashedPath()
103    {
104        $autoloader = new AutoLoader('FakeProject', dirname(__DIR__) . '/../Mocks/Common\\\\/\\//');
105
106        $this->assertTrue($autoloader->register());
107
108        $someClass = new \FakeProject\NS\SomeClass();
109
110        $this->assertTrue($someClass->isLoaded());
111    }
112
113    /**
114     * @covers OAuth\Common\AutoLoader::__construct
115     * @covers OAuth\Common\AutoLoader::register
116     * @covers OAuth\Common\AutoLoader::load
117     */
118    public function testLoadUnknownClass()
119    {
120        $autoloader = new AutoLoader('FakeProject', dirname(__DIR__) . '/../Mocks/Common\\\\/\\//');
121
122        $this->assertTrue($autoloader->register());
123
124        $this->assertFalse($autoloader->load('IDontExistClass'));
125    }
126}
127