Passed
Push — feature/custom-services-v2 ( 14ad97...35de26 )
by Chema
03:35
created

UseBlockParserTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 26
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A test_get_class_from_method() 0 5 1
A setUp() 0 3 1
A phpCode() 0 3 1
A test_get_class_from_empty_doc_block() 0 5 1
A test_get_class_from_method_not_found() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GacelaTest\Unit\Framework\ClassResolver\DocBlockService;
6
7
use Gacela\Framework\ClassResolver\DocBlockService\UseBlockParser;
8
use PHPUnit\Framework\TestCase;
9
10
final class UseBlockParserTest extends TestCase
11
{
12
    private UseBlockParser $parser;
13
14
    protected function setUp(): void
15
    {
16
        $this->parser = new UseBlockParser();
17
    }
18
19
    public function test_get_class_from_empty_doc_block(): void
20
    {
21
        $actual = $this->parser->getUseStatement('TestClass', '');
22
23
        self::assertSame('', $actual);
24
    }
25
26
27
    public function test_get_class_from_method_not_found(): void
28
    {
29
        $actual = $this->parser->getUseStatement('NonExistingClass', $this->phpCode());
30
31
        self::assertSame('', $actual);
32
    }
33
34
    public function test_get_class_from_method(): void
35
    {
36
        $actual = $this->parser->getUseStatement('ExistingClass', $this->phpCode());
37
38
        self::assertSame('Ns\Test\Inner\ExistingClass', $actual);
39
    }
40
41
    private function phpCode(): string
42
    {
43
        return <<<'PHP'
44
<?php 
45
namespace ns\test;
46
47
use Ns\Test\Inner\ExistingClass;
48
use Ns\Test\OuterTwo\ExistingClass; // this will be ignored. The first match will win.
49
                                    // this is also illegal in real code. I place it here 
50
                                    // just to verify the actual logic.
51
52
final class TestClass
53
{
54
    public function foo(): void 
55
    {
56
        echo ExistingClass::class;
57
    }
58
}
59
PHP;
60
    }
61
}
62