1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace RoaveTest\ApiCompare\Comparator\BackwardsCompatibility\ClassBased; |
6
|
|
|
|
7
|
|
|
use PHPUnit\Framework\TestCase; |
8
|
|
|
use Roave\ApiCompare\Change; |
9
|
|
|
use Roave\ApiCompare\Changes; |
10
|
|
|
use Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassBased\MethodChanged; |
11
|
|
|
use Roave\ApiCompare\Comparator\BackwardsCompatibility\MethodBased\MethodBased; |
12
|
|
|
use Roave\BetterReflection\BetterReflection; |
13
|
|
|
use Roave\BetterReflection\Reflection\ReflectionMethod; |
14
|
|
|
use Roave\BetterReflection\Reflector\ClassReflector; |
15
|
|
|
use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator; |
16
|
|
|
use function strtolower; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @covers \Roave\ApiCompare\Comparator\BackwardsCompatibility\ClassBased\MethodChanged |
20
|
|
|
*/ |
21
|
|
|
final class MethodChangedTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
public function testWillDetectChangesInMethods() : void |
24
|
|
|
{ |
25
|
|
|
$astLocator = (new BetterReflection())->astLocator(); |
26
|
|
|
|
27
|
|
|
$fromLocator = new StringSourceLocator( |
28
|
|
|
<<<'PHP' |
29
|
|
|
<?php |
30
|
|
|
|
31
|
|
|
class TheClass { |
32
|
|
|
public function a() {} |
33
|
|
|
protected function b() {} |
34
|
|
|
private function c() {} |
35
|
|
|
private static function d() {} |
36
|
|
|
public function G() {} |
37
|
|
|
} |
38
|
|
|
PHP |
39
|
|
|
, |
40
|
|
|
$astLocator |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
$toLocator = new StringSourceLocator( |
44
|
|
|
<<<'PHP' |
45
|
|
|
<?php |
46
|
|
|
|
47
|
|
|
class TheClass { |
48
|
|
|
protected function b() {} |
49
|
|
|
private static function d() {} |
50
|
|
|
public function e() {} |
51
|
|
|
public function f() {} |
52
|
|
|
public function g() {} |
53
|
|
|
} |
54
|
|
|
PHP |
55
|
|
|
, |
56
|
|
|
$astLocator |
57
|
|
|
); |
58
|
|
|
|
59
|
|
|
$comparator = $this->createMock(MethodBased::class); |
60
|
|
|
|
61
|
|
|
$comparator |
62
|
|
|
->expects(self::exactly(3)) |
63
|
|
|
->method('compare') |
64
|
|
|
->willReturnCallback(function (ReflectionMethod $from, ReflectionMethod $to) : Changes { |
65
|
|
|
$methodName = $from->getName(); |
66
|
|
|
|
67
|
|
|
self::assertSame(strtolower($methodName), strtolower($to->getName())); |
68
|
|
|
|
69
|
|
|
return Changes::fromArray([Change::added($methodName, true)]); |
70
|
|
|
}); |
71
|
|
|
|
72
|
|
|
self::assertEquals( |
73
|
|
|
Changes::fromArray([ |
74
|
|
|
Change::added('b', true), |
75
|
|
|
Change::added('d', true), |
76
|
|
|
Change::added('G', true), |
77
|
|
|
]), |
78
|
|
|
(new MethodChanged($comparator))->compare( |
79
|
|
|
(new ClassReflector($fromLocator))->reflect('TheClass'), |
80
|
|
|
(new ClassReflector($toLocator))->reflect('TheClass') |
81
|
|
|
) |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|