1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace RoaveTest\BackwardCompatibility\DetectChanges\BCBreak\TraitBased; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Roave\BackwardCompatibility\Change; |
9
|
|
|
use Roave\BackwardCompatibility\Changes; |
10
|
|
|
use Roave\BackwardCompatibility\DetectChanges\BCBreak\TraitBased\ExcludeInternalTrait; |
11
|
|
|
use Roave\BackwardCompatibility\DetectChanges\BCBreak\TraitBased\TraitBased; |
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\TraitBased\ExcludeInternalTrait */ |
17
|
|
|
final class ExcludeInternalTraitTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
public function testNormalTraitsAreNotExcluded() : void |
20
|
|
|
{ |
21
|
|
|
$locator = (new BetterReflection())->astLocator(); |
22
|
|
|
$reflector = new ClassReflector(new StringSourceLocator( |
23
|
|
|
<<<'PHP' |
24
|
|
|
<?php |
25
|
|
|
|
26
|
|
|
trait ANormalTrait {} |
27
|
|
|
PHP |
28
|
|
|
, |
29
|
|
|
$locator |
30
|
|
|
)); |
31
|
|
|
$reflection = $reflector->reflect('ANormalTrait'); |
32
|
|
|
|
33
|
|
|
$check = $this->createMock(TraitBased::class); |
34
|
|
|
$check->expects(self::once()) |
|
|
|
|
35
|
|
|
->method('__invoke') |
36
|
|
|
->with($reflection, $reflection) |
37
|
|
|
->willReturn(Changes::fromList(Change::removed('foo', true))); |
38
|
|
|
|
39
|
|
|
self::assertEquals( |
|
|
|
|
40
|
|
|
Changes::fromList(Change::removed('foo', true)), |
41
|
|
|
(new ExcludeInternalTrait($check)) |
42
|
|
|
->__invoke($reflection, $reflection) |
43
|
|
|
); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
public function testInternalTraitsAreExcluded() : void |
47
|
|
|
{ |
48
|
|
|
$locator = (new BetterReflection())->astLocator(); |
49
|
|
|
$reflector = new ClassReflector(new StringSourceLocator( |
50
|
|
|
<<<'PHP' |
51
|
|
|
<?php |
52
|
|
|
|
53
|
|
|
/** @internal */ |
54
|
|
|
trait AnInternalTrait {} |
55
|
|
|
PHP |
56
|
|
|
, |
57
|
|
|
$locator |
58
|
|
|
)); |
59
|
|
|
$reflection = $reflector->reflect('AnInternalTrait'); |
60
|
|
|
|
61
|
|
|
$check = $this->createMock(TraitBased::class); |
62
|
|
|
$check->expects(self::never())->method('__invoke'); |
|
|
|
|
63
|
|
|
|
64
|
|
|
self::assertEquals( |
65
|
|
|
Changes::empty(), |
66
|
|
|
(new ExcludeInternalTrait($check)) |
67
|
|
|
->__invoke($reflection, $reflection) |
68
|
|
|
); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
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.