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

LocateASTFromFilesTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 40
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testLocate() 0 11 1
A createFile() 0 4 1
A locate() 0 4 1
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