Completed
Push — master ( 25f365...554d02 )
by Alexey
02:46
created

ReflectionUseStatementsTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B testMain() 0 31 1
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Reflection\Tests;
6
7
use \PHPUnit\Framework\TestCase;
8
9
use \Reflection\ReflectionUseStatements;
10
use \Reflection\UseStatements;
11
use \Reflection\UseStatement;
12
13
use \Reflection\Tests\Dummy\Tree;
14
15
/**
16
 * Class ClassUseStatementsTest
17
 * @package Reflection\Tests
18
 */
19
class ReflectionUseStatementsTest extends TestCase {
20
21
    public function testMain() {
22
        $reflection = new ReflectionUseStatements(Tree::class);
23
24
        $this->assertEquals(
25
            $reflection->getUseStatements(),
26
            (new UseStatements())
27
                ->add(new UseStatement('\JsonSerializable'))
28
                ->add(new UseStatement('\Reflection\Tests\Dummy\Branch', 'BranchClass'))
29
                ->add(new UseStatement('\Reflection\Tests\Dummy\Leaf'))
30
        );
31
32
        $this->assertFalse($reflection->isNotUserDefined());
33
34
        $this->assertTrue($reflection->hasUseStatement('\JsonSerializable'));
35
        $this->assertTrue($reflection->hasUseStatement('JsonSerializable'));
36
        $this->assertTrue($reflection->hasUseStatement('\Reflection\Tests\Dummy\Branch'));
37
        $this->assertTrue($reflection->hasUseStatement('BranchClass'));
38
        $this->assertTrue($reflection->hasUseStatement('\Reflection\Tests\Dummy\Leaf'));
39
        $this->assertTrue($reflection->hasUseStatement('Leaf'));
40
        $this->assertFalse($reflection->hasUseStatement('LeafClass'));
41
42
        $this->assertNull($reflection->getUseStatements()->getClass('LeafClass'));
43
        $this->assertEquals(
44
            $reflection->getUseStatements()->getClass('BranchClass'),
45
            new UseStatement('\Reflection\Tests\Dummy\Branch', 'BranchClass')
46
        );
47
48
        $this->expectException('RuntimeException');
49
        $this->expectExceptionMessage('Can get use statements from user defined classes only.');
50
        (new ReflectionUseStatements('\JsonSerializable'))->getUseStatements();
51
    }
52
53
}