Failed Conditions
Push — master ( 695e78...1160b5 )
by Matthias
03:17 queued 44s
created

LocateFilesByGlobPatternTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace ComposerRequireCheckerTest\FileLocator;
4
5
6
use ComposerRequireChecker\FileLocator\LocateFilesByGlobPattern;
7
use org\bovigo\vfs\vfsStream;
8
use org\bovigo\vfs\vfsStreamDirectory;
9
use PHPUnit\Framework\TestCase;
10
11
class LocateFilesByGlobPatternTest extends TestCase
12
{
13
14
    /**
15
     * @var LocateFilesByGlobPattern
16
     */
17
    private $locator;
18
19
    /**
20
     * @var vfsStreamDirectory
21
     */
22
    private $root;
23
24
    public function setUp()
25
    {
26
        $this->locator = new LocateFilesByGlobPattern();
27
        $this->root = vfsStream::setup();
28
    }
29
30
    public function testSimpleGlobPattern()
31
    {
32
        vfsStream::create([
33
            'bin' => [
34
                'console' => '',
35
                'not-console' => '',
36
            ],
37
        ]);
38
39
        $files = $this->files(['bin/console'], $this->root->url());
40
        self::assertCount(1, $files);
41
        self::assertContains($this->root->getChild('bin/console')->url(), $files);
42
    }
43
44
    public function testGlobPattern()
45
    {
46
        vfsStream::create([
47
            'bin' => [
48
                'console.php' => '',
49
                'console123.php' => '',
50
                'not-console' => '',
51
            ],
52
        ]);
53
54
        $files = $this->files(['bin/console*.php'], $this->root->url());
55
        self::assertCount(2, $files);
56
        self::assertContains($this->root->getChild('bin/console.php')->url(), $files);
57
        self::assertContains($this->root->getChild('bin/console123.php')->url(), $files);
58
    }
59
60
    /**
61
     * @return string[]
62
     */
63
    private function files(array $globPatterns, $dir): array
64
    {
65
        $files = [];
66
        $filesGenerator = ($this->locator)($globPatterns, $dir);
67
        foreach ($filesGenerator as $file) {
68
            $files[] = $file;
69
        }
70
        return $files;
71
    }
72
73
}
74