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