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

ReflectionUseStatementsTest::testMain()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 31
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 23
nc 1
nop 0
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
}