Completed
Push — master ( b60ce0...53cbf4 )
by Matthias
02:13
created

testFromFiles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
3
namespace ComposerRequireCheckerTest\FileLocator;
4
5
use ComposerRequireChecker\FileLocator\LocateComposerPackageSourceFiles;
6
use org\bovigo\vfs\vfsStream;
7
use org\bovigo\vfs\vfsStreamDirectory;
8
use PHPUnit\Framework\TestCase;
9
10
/**
11
 * @covers \ComposerRequireChecker\FileLocator\LocateComposerPackageSourceFiles
12
 */
13
class LocateComposerPackageSourceFilesTest extends TestCase
14
{
15
    /** @var LocateComposerPackageSourceFiles */
16
    private $locator;
17
    /** @var vfsStreamDirectory */
18
    private $root;
19
20
    protected function setUp()
21
    {
22
        parent::setUp();
23
24
        $this->locator = new LocateComposerPackageSourceFiles();
25
        $this->root = vfsStream::setup();
26
    }
27
28 View Code Duplication
    public function testFromClassmap()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
29
    {
30
        vfsStream::create([
31
            'composer.json' => '{"autoload": {"classmap": ["src/MyClassA.php", "MyClassB.php"]}}',
32
            'src' => [
33
                'MyClassA.php' => '<?php class MyClassA {}',
34
            ],
35
            'MyClassB.php' => '<?php class MyClassB {}',
36
        ]);
37
38
        $files = $this->files($this->root->getChild('composer.json')->url());
39
40
        $this->assertCount(2, $files);
41
        $this->assertContains($this->root->getChild('src/MyClassA.php')->url(), $files);
42
        $this->assertContains($this->root->getChild('MyClassB.php')->url(), $files);
43
    }
44
45
    public function testFromFiles()
46
    {
47
        vfsStream::create([
48
            'composer.json' => '{"autoload": {"files": ["foo.php"]}}',
49
            'foo.php' => '<?php class MyClass {}',
50
        ]);
51
52
        $files = $this->files($this->root->getChild('composer.json')->url());
53
54
        $this->assertCount(1, $files);
55
        $this->assertContains($this->root->getChild('foo.php')->url(), $files);
56
    }
57
58 View Code Duplication
    public function testFromPsr0()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
    {
60
        vfsStream::create([
61
            'composer.json' => '{"autoload": {"psr-0": ["src"]}}',
62
            'src' => [
63
                'MyNamespace' => [
64
                    'MyClass.php' => '<?php namespace MyNamespace; class MyClass {}',
65
                ],
66
            ],
67
        ]);
68
69
        $files = $this->files($this->root->getChild('composer.json')->url());
70
71
        $this->assertCount(1, $files);
72
    }
73
74 View Code Duplication
    public function testFromPsr4()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
75
    {
76
        vfsStream::create([
77
            'composer.json' => '{"autoload": {"psr-4": {"MyNamespace\\\\": "src"}}}',
78
            'src' => [
79
                'MyClass.php' => '<?php namespace MyNamespace; class MyClass {}',
80
            ],
81
        ]);
82
83
        $files = $this->files($this->root->getChild('composer.json')->url());
84
85
        $this->assertCount(1, $files);
86
    }
87
88
    public function testFromPsr0WithMultipleDirectories()
89
    {
90
        vfsStream::create([
91
            'composer.json' => '{"autoload": {"psr-0": {"MyNamespace\\\\": ["src", "lib"]}}}',
92
            'src' => ['MyNamespace' => ['MyClassA.php' => '<?php namespace MyNamespace; class MyClassA {}']],
93
            'lib' => ['MyNamespace' => ['MyClassB.php' => '<?php namespace MyNamespace; class MyClassB {}']],
94
        ]);
95
96
        $files = $this->files($this->root->getChild('composer.json')->url());
97
98
        $this->assertCount(2, $files);
99
        $this->assertContains($this->root->getChild('src/MyNamespace/MyClassA.php')->url(), $files);
100
        $this->assertContains($this->root->getChild('lib/MyNamespace/MyClassB.php')->url(), $files);
101
    }
102
103 View Code Duplication
    public function testFromPsr4WithMultipleDirectories()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
104
    {
105
        vfsStream::create([
106
            'composer.json' => '{"autoload": {"psr-4": {"MyNamespace\\\\": ["src", "lib"]}}}',
107
            'src' => ['MyClassA.php' => '<?php namespace MyNamespace; class MyClassA {}'],
108
            'lib' => ['MyClassB.php' => '<?php namespace MyNamespace; class MyClassB {}'],
109
        ]);
110
111
        $files = $this->files($this->root->getChild('composer.json')->url());
112
113
        $this->assertCount(2, $files);
114
        $this->assertContains($this->root->getChild('src/MyClassA.php')->url(), $files);
115
        $this->assertContains($this->root->getChild('lib/MyClassB.php')->url(), $files);
116
    }
117
118
    /**
119
     * @return string[]
120
     */
121
    private function files(string $composerJson): array
122
    {
123
        $files = [];
124
        $filesGenerator = ($this->locator)($composerJson);
125
        foreach ($filesGenerator as $file) {
126
            $files[] = $file;
127
        }
128
        return $files;
129
    }
130
}
131