ExcludeInternalPropertyTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 33
c 1
b 0
f 0
dl 0
loc 60
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testNormalPropertiesAreNotExcluded() 0 28 1
A testInternalPropertiesAreExcluded() 0 27 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\PropertyBased;
6
7
use PHPUnit\Framework\TestCase;
8
use Roave\BackwardCompatibility\Change;
9
use Roave\BackwardCompatibility\Changes;
10
use Roave\BackwardCompatibility\DetectChanges\BCBreak\PropertyBased\ExcludeInternalProperty;
11
use Roave\BackwardCompatibility\DetectChanges\BCBreak\PropertyBased\PropertyBased;
12
use Roave\BetterReflection\BetterReflection;
13
use Roave\BetterReflection\Reflector\ClassReflector;
14
use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator;
15
16
/** @covers \Roave\BackwardCompatibility\DetectChanges\BCBreak\PropertyBased\ExcludeInternalProperty */
17
final class ExcludeInternalPropertyTest extends TestCase
18
{
19
    public function testNormalPropertiesAreNotExcluded() : void
20
    {
21
        $property = (new ClassReflector(new StringSourceLocator(
22
            <<<'PHP'
23
<?php
24
25
class A {
26
    public $property;
27
}
28
PHP
29
            ,
30
            (new BetterReflection())->astLocator()
31
        )))
32
            ->reflect('A')
33
            ->getProperty('property');
34
35
        self::assertNotNull($property);
36
37
        $check = $this->createMock(PropertyBased::class);
38
        $check->expects(self::once())
39
              ->method('__invoke')
40
              ->with($property, $property)
41
              ->willReturn(Changes::fromList(Change::removed('foo', true)));
42
43
        self::assertEquals(
44
            Changes::fromList(Change::removed('foo', true)),
45
            (new ExcludeInternalProperty($check))
46
                ->__invoke($property, $property)
47
        );
48
    }
49
50
    public function testInternalPropertiesAreExcluded() : void
51
    {
52
        $property = (new ClassReflector(new StringSourceLocator(
53
            <<<'PHP'
54
<?php
55
56
class A {
57
    /** @internal */
58
    public $property;
59
}
60
PHP
61
            ,
62
            (new BetterReflection())->astLocator()
63
        )))
64
            ->reflect('A')
65
            ->getProperty('property');
66
67
        self::assertNotNull($property);
68
69
        $check = $this->createMock(PropertyBased::class);
70
        $check->expects(self::never())
71
              ->method('__invoke');
72
73
        self::assertEquals(
74
            Changes::empty(),
75
            (new ExcludeInternalProperty($check))
76
                ->__invoke($property, $property)
77
        );
78
    }
79
}
80