AutoloaderLocatorTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Coupling/Cohesion

Components 3
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 97
rs 10
c 0
b 0
f 0
wmc 3
lcom 3
cbo 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testAutoloadAtDefaultLocation() 0 9 1
A testAutoloadComposerInstalled() 0 10 1
A testAutoloadComposerInstalledCustomVendor() 0 12 1
1
<?php
2
/**
3
 * This file is part of phpDocumentor.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @author    Mike van Riel <[email protected]>
9
 * @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com)
10
 * @license   http://www.opensource.org/licenses/mit-license.php MIT
11
 * @link      http://phpdoc.org
12
 *
13
 *
14
 */
15
16
namespace phpDocumentor;
17
18
use Composer\Autoload\ClassLoader;
19
use org\bovigo\vfs\vfsStream;
20
use PHPUnit\Framework\TestCase;
21
22
class AutoloaderLocatorTest extends TestCase
23
{
24
    /**
25
     * Directory structure when phpdocumentor is installed using composer.
26
     *
27
     * @var array
28
     */
29
    private $composerInstalledStructure = array(
30
        'dummy' => array(
31
            'vendor' => array(
32
                'phpDocumentor' => array(
33
                    'phpDocumentor' => array(
34
                        'src' => array(
35
                            'phpDocumentor' => array(),
36
                        ),
37
                    ),
38
                ),
39
            ),
40
        ),
41
    );
42
43
    /**
44
     * Directory structure when phpdocumentor is installed using composer.
45
     *
46
     * @var array
47
     */
48
    private $customVendorDir = array(
49
        'dummy' => array(
50
            'custom-vendor' => array(
51
                'phpDocumentor' => array(
52
                    'phpDocumentor' => array(
53
                        'src' => array(
54
                            'phpDocumentor' => array(),
55
                        ),
56
                    ),
57
                ),
58
            ),
59
        ),
60
    );
61
62
    private $customVendorDirComposer = '{
63
    "config": {
64
        "vendor-dir": "custom-vendor"
65
    }
66
    }';
67
68
69
    /**
70
     * Directory structure when phpdocumentor is installed from git.
71
     *
72
     * @var array
73
     */
74
    private $standaloneStructure = array(
75
        'dummy' => array(
76
            'vendor' => array(),
77
            'src' => array(
78
                'phpDocumentor' => array(),
79
            ),
80
            'test' => array(),
81
        ),
82
    );
83
84
85
    public function testAutoloadAtDefaultLocation()
86
    {
87
        vfsStream::setup('root', null, $this->standaloneStructure);
88
        $baseDir = vfsStream::url('root/dummy/src/phpDocumentor');
89
        self::assertSame(
90
            'vfs://root/dummy/src/phpDocumentor/../../vendor',
91
            AutoloaderLocator::findVendorPath($baseDir)
92
        );
93
    }
94
95
    public function testAutoloadComposerInstalled()
96
    {
97
        $root = vfsStream::setup('root', null, $this->composerInstalledStructure);
98
        vfsStream::newFile('composer.json')->at($root->getChild('dummy'));
99
        $baseDir = vfsStream::url('root/dummy/vendor/phpDocumentor/phpDocumentor/src/phpDocumentor');
100
        $this->assertSame(
101
            'vfs://root/dummy/vendor/phpDocumentor/phpDocumentor/src/phpDocumentor/../../../../../vendor',
102
            AutoloaderLocator::findVendorPath($baseDir)
103
        );
104
    }
105
106
    public function testAutoloadComposerInstalledCustomVendor()
107
    {
108
        $root = vfsStream::setup('root', null, $this->customVendorDir);
109
        vfsStream::newFile('composer.json')
110
            ->withContent($this->customVendorDirComposer)
111
            ->at($root->getChild('dummy'));
112
        $baseDir = vfsStream::url('root/dummy/custom-vendor/phpDocumentor/phpDocumentor/src/phpDocumentor');
113
        $this->assertSame(
114
            'vfs://root/dummy/custom-vendor/phpDocumentor/phpDocumentor/src/phpDocumentor/../../../../../custom-vendor',
115
            AutoloaderLocator::findVendorPath($baseDir)
116
        );
117
    }
118
}
119