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

LocateAllFilesByExtensionTest::locate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
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