Skip to content

Commit 5a7bbb1

Browse files
committed
test: Prove false-positive on protected->private in final class
A final class cannot be extended, therefore `protected` and `private` are functionally identical. `protected` methods may exist in final classes for historical reasons, but making them `private` is not a BC break.
1 parent be346a8 commit 5a7bbb1

1 file changed

Lines changed: 43 additions & 0 deletions

File tree

test/unit/DetectChanges/BCBreak/ClassBased/MethodRemovedTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Roave\BetterReflection\Reflection\ReflectionClass;
1414
use Roave\BetterReflection\Reflector\DefaultReflector;
1515
use Roave\BetterReflection\SourceLocator\Type\SingleFileSourceLocator;
16+
use Roave\BetterReflection\SourceLocator\Type\StringSourceLocator;
1617

1718
use function array_map;
1819
use function iterator_to_array;
@@ -60,6 +61,48 @@ public static function classesToBeTested(): array
6061
'[BC] REMOVED: Method RoaveTestAsset\ClassWithMethodsBeingRemoved#removedProtectedMethod() was removed',
6162
],
6263
],
64+
'final class with protected changing to private' => [
65+
(new DefaultReflector(new StringSourceLocator(
66+
<<<'PHP'
67+
<?php
68+
final class FinalClassWithProtectedMethod {
69+
protected function foo(string $bar): void {}
70+
}
71+
PHP,
72+
$locator,
73+
)))->reflectClass('FinalClassWithProtectedMethod'),
74+
(new DefaultReflector(new StringSourceLocator(
75+
<<<'PHP'
76+
<?php
77+
final class FinalClassWithProtectedMethod {
78+
private function foo(string $bar): void {}
79+
}
80+
PHP,
81+
$locator,
82+
)))->reflectClass('FinalClassWithProtectedMethod'),
83+
[],
84+
],
85+
'final class with public changing to private' => [
86+
(new DefaultReflector(new StringSourceLocator(
87+
<<<'PHP'
88+
<?php
89+
final class FinalClassWithPublicMethod {
90+
public function foo(string $bar): void {}
91+
}
92+
PHP,
93+
$locator,
94+
)))->reflectClass('FinalClassWithPublicMethod'),
95+
(new DefaultReflector(new StringSourceLocator(
96+
<<<'PHP'
97+
<?php
98+
final class FinalClassWithPublicMethod {
99+
private function foo(string $bar): void {}
100+
}
101+
PHP,
102+
$locator,
103+
)))->reflectClass('FinalClassWithPublicMethod'),
104+
['[BC] REMOVED: Method FinalClassWithPublicMethod#foo() was removed'],
105+
],
63106
];
64107
}
65108
}

0 commit comments

Comments
 (0)