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
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.