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

LocateASTFromFilesTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace ComposerRequireCheckerTest\ASTLocator;
4
5
use ArrayObject;
6
use ComposerRequireChecker\ASTLocator\LocateASTFromFiles;
7
use org\bovigo\vfs\vfsStream;
8
use org\bovigo\vfs\vfsStreamDirectory;
9
use PhpParser\Lexer;
10
use PhpParser\Parser\Php7;
11
use PHPUnit\Framework\TestCase;
12
13
/**
14
 * @covers \ComposerRequireChecker\ASTLocator\LocateASTFromFiles
15
 */
16
class LocateASTFromFilesTest extends TestCase
17
{
18
    /** @var LocateASTFromFiles */
19
    private $locator;
20
    /** @var vfsStreamDirectory */
21
    private $root;
22
23
    protected function setUp()
24
    {
25
        parent::setUp();
26
27
        $this->locator = new LocateASTFromFiles(new Php7(new Lexer()));
28
        $this->root = vfsStream::setup();
29
    }
30
31
    public function testLocate()
32
    {
33
        $files = [
34
            $this->createFile('MyClassA', '<?php class MyClassA {}'),
35
            $this->createFile('MyClassB', '<?php class MyClassB {}'),
36
        ];
37
38
        $roots = $this->locate($files);
39
40
        $this->assertCount(2, $roots);
41
    }
42
43
    private function createFile(string $path, string $content = null): string
44
    {
45
        return vfsStream::newFile($path)->at($this->root)->setContent($content)->url();
46
    }
47
48
    /**
49
     * @param string[] $files
50
     */
51
    private function locate(array $files): array
52
    {
53
        return iterator_to_array(($this->locator)(new ArrayObject($files)));
54
    }
55
}
56