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

UseBlockParserTest::phpCode()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 17
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 9.7
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