Completed
Branch feature/add-scrutinizer (27b569)
by Matthias
02:05
created

LocateAllFilesByExtensionTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 47
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testLocateFromNoDirectories() 0 6 1
A testLocateFromASingleDirectory() 0 15 3
A locate() 0 4 1
1
<?php
2
3
namespace ComposerRequireCheckerTest\FileLocator;
4
5
use ArrayObject;
6
use ComposerRequireChecker\FileLocator\LocateAllFilesByExtension;
7
use org\bovigo\vfs\vfsStream;
8
use org\bovigo\vfs\vfsStreamDirectory;
9
use PHPUnit\Framework\TestCase;
10
11
/**
12
 * @covers \ComposerRequireChecker\FileLocator\LocateAllFilesByExtension
13
 */
14
class LocateAllFilesByExtensionTest extends TestCase
15
{
16
    /** @var LocateAllFilesByExtension */
17
    private $locator;
18
    /** @var vfsStreamDirectory */
19
    private $root;
20
21
    protected function setUp()
22
    {
23
        parent::setUp();
24
25
        $this->locator = new LocateAllFilesByExtension();
26
        $this->root = vfsStream::setup();
27
    }
28
29
    public function testLocateFromNoDirectories()
30
    {
31
        $files = $this->locate([], '.php');
32
33
        $this->assertCount(0, $files);
34
    }
35
36
    public function testLocateFromASingleDirectory()
37
    {
38
        $dir = vfsStream::newDirectory('MyNamespaceA')->at($this->root);
39
        $files = [];
40
        for ($i = 0; $i < 3; $i++) {
41
            $files[] = vfsStream::newFile("MyClass$i.php")->at($dir);
42
        }
43
44
        $foundFiles = $this->locate([$dir->url()], '.php');
45
46
        $this->assertCount(count($files), $foundFiles);
47
        foreach ($files as $file) {
48
            $this->assertContains($file->url(), str_replace('\\', '/', $foundFiles));
49
        }
50
    }
51
52
    /**
53
     * @param string[] $directories
54
     * @return string[]
55
     */
56
    private function locate(array $directories, string $fileExtension): array
57
    {
58
        return iterator_to_array(($this->locator)(new ArrayObject($directories), $fileExtension));
59
    }
60
}
61