Completed
Push — develop ( 9af8d2...9dbd4b )
by Jaap
17s
created

testAutoloadAtDefaultLocation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 8
rs 10
c 0
b 0
f 0
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
    public function testAutoloadComposerInstalled()
95
    {
96
        $root = vfsStream::setup('root', null, $this->composerInstalledStructure);
97
        vfsStream::newFile('composer.json')->at($root->getChild('dummy'));
98
        $baseDir = vfsStream::url('root/dummy/vendor/phpDocumentor/phpDocumentor/src/phpDocumentor');
99
        $this->assertSame(
100
            'vfs://root/dummy/vendor/phpDocumentor/phpDocumentor/src/phpDocumentor/../../../../../vendor'
101
            , AutoloaderLocator::findVendorPath($baseDir)
102
        );
103
    }
104
105
    public function testAutoloadComposerInstalledCustomVendor()
106
    {
107
        $root = vfsStream::setup('root', null, $this->customVendorDir);
108
        vfsStream::newFile('composer.json')->withContent($this->customVendorDirComposer)->at($root->getChild('dummy'));
109
        $baseDir = vfsStream::url('root/dummy/custom-vendor/phpDocumentor/phpDocumentor/src/phpDocumentor');
110
        $this->assertSame(
111
            'vfs://root/dummy/custom-vendor/phpDocumentor/phpDocumentor/src/phpDocumentor/../../../../../custom-vendor'
112
            , AutoloaderLocator::findVendorPath($baseDir)
113
        );
114
    }
115
}
116