Skip to content

Commit ee742f9

Browse files
committed
Kill some mutants
1 parent 226827a commit ee742f9

File tree

4 files changed

+100
-21
lines changed

4 files changed

+100
-21
lines changed

src/Reflection/ReflectionMethod.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ public function getModifiers(): int
307307
/** @return int-mask-of<ReflectionMethodAdapter::IS_*> */
308308
private function computeModifiers(MethodNode|Node\PropertyHook $node): int
309309
{
310-
$modifiers = 0;
310+
$modifiers = $node->isFinal() ? CoreReflectionMethod::IS_FINAL : 0;
311311

312312
if ($node instanceof MethodNode) {
313313
$modifiers += $node->isStatic() ? CoreReflectionMethod::IS_STATIC : 0;
@@ -317,8 +317,6 @@ private function computeModifiers(MethodNode|Node\PropertyHook $node): int
317317
$modifiers += $node->isAbstract() ? CoreReflectionMethod::IS_ABSTRACT : 0;
318318
}
319319

320-
$modifiers += $node->isFinal() ? CoreReflectionMethod::IS_FINAL : 0;
321-
322320
return $modifiers;
323321
}
324322

test/unit/Fixture/PropertyHooks.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,45 @@ class GetAndSetPropertyHook extends GetPropertyHook
100100
}
101101
}
102102

103+
class SetPropertyHook
104+
{
105+
public string $hook {
106+
set (string $value) {
107+
$this->hook = $value;
108+
}
109+
}
110+
}
111+
112+
class SetAndGetPropertyHook extends SetPropertyHook
113+
{
114+
public string $hook {
115+
get {
116+
return 'hook';
117+
}
118+
}
119+
}
120+
121+
class BothPropertyHooks
122+
{
123+
public string $hook {
124+
get {
125+
return 'hook';
126+
}
127+
set (string $value) {
128+
$this->hook = $value;
129+
}
130+
}
131+
}
132+
133+
class ExtendedHooks extends BothPropertyHooks
134+
{
135+
public string $hook {
136+
get {
137+
return 'hook2';
138+
}
139+
}
140+
}
141+
103142
trait PropertyHookTrait
104143
{
105144
public string $hook {

test/unit/Reflection/ReflectionClassConstantTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,25 +61,34 @@ public function testDefaultVisibility(): void
6161
{
6262
$const = $this->getExampleConstant('MY_CONST_1');
6363
self::assertTrue($const->isPublic());
64+
self::assertFalse($const->isProtected());
65+
self::assertFalse($const->isPrivate());
66+
self::assertFalse($const->isFinal());
6467
}
6568

6669
public function testOnlyPublicVisibility(): void
6770
{
6871
$const = $this->getExampleConstant('MY_CONST_3');
6972
self::assertTrue($const->isPublic());
73+
self::assertFalse($const->isProtected());
74+
self::assertFalse($const->isPrivate());
7075
self::assertFalse($const->isFinal());
7176
}
7277

7378
public function testOnlyProtectedVisibility(): void
7479
{
7580
$const = $this->getExampleConstant('MY_CONST_4');
81+
self::assertFalse($const->isPublic());
7682
self::assertTrue($const->isProtected());
83+
self::assertFalse($const->isPrivate());
7784
self::assertFalse($const->isFinal());
7885
}
7986

8087
public function testPrivateVisibility(): void
8188
{
8289
$const = $this->getExampleConstant('MY_CONST_5');
90+
self::assertFalse($const->isPublic());
91+
self::assertFalse($const->isProtected());
8392
self::assertTrue($const->isPrivate());
8493
self::assertFalse($const->isFinal());
8594
}
@@ -94,7 +103,9 @@ public function testPublicFinal(): void
94103
public function testProtectedFinal(): void
95104
{
96105
$const = $this->getExampleConstant('MY_CONST_7');
106+
self::assertFalse($const->isPublic());
97107
self::assertTrue($const->isProtected());
108+
self::assertFalse($const->isPrivate());
98109
self::assertTrue($const->isFinal());
99110
}
100111

test/unit/Reflection/ReflectionPropertyTest.php

Lines changed: 49 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,11 @@ public function testIsReadOnly(): void
192192

193193
$notReadOnlyProperty = $classInfo->getProperty('publicProperty');
194194
self::assertFalse($notReadOnlyProperty->isReadOnly());
195+
self::assertTrue($notReadOnlyProperty->isPublic());
195196

196197
$readOnlyProperty = $classInfo->getProperty('readOnlyProperty');
197-
self::assertTrue($readOnlyProperty->isPublic());
198198
self::assertTrue($readOnlyProperty->isReadOnly());
199+
self::assertTrue($readOnlyProperty->isPublic());
199200
}
200201

201202
public function testIsFinal(): void
@@ -204,6 +205,7 @@ public function testIsFinal(): void
204205

205206
$notReadOnlyProperty = $classInfo->getProperty('publicProperty');
206207
self::assertFalse($notReadOnlyProperty->isFinal());
208+
self::assertTrue($notReadOnlyProperty->isPublic());
207209

208210
$finalPublicProperty = $classInfo->getProperty('finalPublicProperty');
209211
self::assertTrue($finalPublicProperty->isFinal());
@@ -215,6 +217,7 @@ public function testIsNotAbstract(): void
215217
$classInfo = $this->reflector->reflectClass(ExampleClass::class);
216218

217219
$notAbstractProperty = $classInfo->getProperty('publicProperty');
220+
self::assertTrue($notAbstractProperty->isPublic());
218221
self::assertFalse($notAbstractProperty->isAbstract());
219222
}
220223

@@ -227,6 +230,7 @@ public function testIsReadOnlyInReadOnlyClass(): void
227230
$classInfo = $reflector->reflectClass('\\Roave\\BetterReflectionTest\\Fixture\\ReadOnlyClass');
228231

229232
$property = $classInfo->getProperty('property');
233+
self::assertTrue($property->isPrivate());
230234
self::assertTrue($property->isReadOnly());
231235
}
232236

@@ -264,25 +268,32 @@ public function testGetDocCommentReturnsNullWithNoComment(): void
264268
self::assertNull($property->getDocComment());
265269
}
266270

267-
/** @return list<array{0: non-empty-string, 1: int-mask-of<ReflectionPropertyAdapter::IS_*>}> */
271+
/** @return list<array{0: non-empty-string, 1: class-string, 2: non-empty-string, 3: int-mask-of<ReflectionPropertyAdapter::IS_*>}> */
268272
public static function modifierProvider(): array
269273
{
270274
return [
271-
['publicProperty', CoreReflectionProperty::IS_PUBLIC],
272-
['protectedProperty', CoreReflectionProperty::IS_PROTECTED],
273-
['privateProperty', CoreReflectionProperty::IS_PRIVATE],
274-
['publicStaticProperty', CoreReflectionProperty::IS_PUBLIC | CoreReflectionProperty::IS_STATIC],
275-
['readOnlyProperty', CoreReflectionProperty::IS_PUBLIC | ReflectionPropertyAdapter::IS_READONLY | ReflectionPropertyAdapter::IS_PROTECTED_SET_COMPATIBILITY],
276-
['finalPublicProperty', CoreReflectionProperty::IS_PUBLIC | ReflectionPropertyAdapter::IS_FINAL_COMPATIBILITY],
275+
[__DIR__ . '/../Fixture/ExampleClass.php', 'Roave\BetterReflectionTest\Fixture\ExampleClass', 'publicProperty', CoreReflectionProperty::IS_PUBLIC],
276+
[__DIR__ . '/../Fixture/ExampleClass.php', 'Roave\BetterReflectionTest\Fixture\ExampleClass', 'protectedProperty', CoreReflectionProperty::IS_PROTECTED],
277+
[__DIR__ . '/../Fixture/ExampleClass.php', 'Roave\BetterReflectionTest\Fixture\ExampleClass', 'privateProperty', CoreReflectionProperty::IS_PRIVATE],
278+
[__DIR__ . '/../Fixture/ExampleClass.php', 'Roave\BetterReflectionTest\Fixture\ExampleClass', 'publicStaticProperty', CoreReflectionProperty::IS_PUBLIC | CoreReflectionProperty::IS_STATIC],
279+
[__DIR__ . '/../Fixture/ExampleClass.php', 'Roave\BetterReflectionTest\Fixture\ExampleClass', 'readOnlyProperty', CoreReflectionProperty::IS_PUBLIC | ReflectionPropertyAdapter::IS_READONLY | ReflectionPropertyAdapter::IS_PROTECTED_SET_COMPATIBILITY],
280+
[__DIR__ . '/../Fixture/ExampleClass.php', 'Roave\BetterReflectionTest\Fixture\ExampleClass', 'finalPublicProperty', CoreReflectionProperty::IS_PUBLIC | ReflectionPropertyAdapter::IS_FINAL_COMPATIBILITY],
281+
[__DIR__ . '/../Fixture/PropertyHooks.php', 'Roave\BetterReflectionTest\Fixture\AbstractPropertyHooks', 'hook', CoreReflectionProperty::IS_PUBLIC | ReflectionPropertyAdapter::IS_ABSTRACT_COMPATIBILITY | ReflectionPropertyAdapter::IS_VIRTUAL_COMPATIBILITY],
277282
];
278283
}
279284

280-
/** @param non-empty-string $propertyName */
285+
/**
286+
* @param non-empty-string $fileName
287+
* @param class-string $className
288+
* @param non-empty-string $propertyName
289+
*/
281290
#[DataProvider('modifierProvider')]
282-
public function testGetModifiers(string $propertyName, int $expectedModifier): void
291+
public function testGetModifiers(string $fileName, string $className, string $propertyName, int $expectedModifier): void
283292
{
284-
$classInfo = $this->reflector->reflectClass(ExampleClass::class);
285-
$property = $classInfo->getProperty($propertyName);
293+
$reflector = new DefaultReflector(new SingleFileSourceLocator($fileName, $this->astLocator));
294+
$classInfo = $reflector->reflectClass($className);
295+
296+
$property = $classInfo->getProperty($propertyName);
286297

287298
self::assertSame($expectedModifier, $property->getModifiers());
288299
}
@@ -968,25 +979,29 @@ public function testIsPrivateSet(): void
968979
self::assertTrue($protectedPrivateSet->isPrivateSet());
969980
}
970981

971-
/** @return list<array{0: non-empty-string, 1: bool}> */
982+
/** @return list<array{0: non-empty-string, 1: bool, 2: int-mask-of<ReflectionPropertyAdapter::IS_*>}> */
972983
public static function asymmetricVisibilityImplicitFinalProvider(): array
973984
{
974985
return [
975-
['publicPrivateSetIsFinal', true],
976-
['protectedPrivateSetIsFinal', true],
977-
['privatePrivateSetIsNotFinal', false],
986+
['publicPrivateSetIsFinal', true, ReflectionPropertyAdapter::IS_PUBLIC | ReflectionPropertyAdapter::IS_PRIVATE_SET_COMPATIBILITY | ReflectionPropertyAdapter::IS_FINAL_COMPATIBILITY],
987+
['protectedPrivateSetIsFinal', true, ReflectionPropertyAdapter::IS_PROTECTED | ReflectionPropertyAdapter::IS_PRIVATE_SET_COMPATIBILITY | ReflectionPropertyAdapter::IS_FINAL_COMPATIBILITY],
988+
['privatePrivateSetIsNotFinal', false, ReflectionPropertyAdapter::IS_PRIVATE],
978989
];
979990
}
980991

981-
/** @param non-empty-string $propertyName */
992+
/**
993+
* @param non-empty-string $propertyName
994+
* @param int-mask-of<ReflectionPropertyAdapter::IS_*> $modifiers
995+
*/
982996
#[DataProvider('asymmetricVisibilityImplicitFinalProvider')]
983-
public function testAsymmetricVisibilityImplicitFinal(string $propertyName, bool $isFinal): void
997+
public function testAsymmetricVisibilityImplicitFinal(string $propertyName, bool $isFinal, int $modifiers): void
984998
{
985999
$reflector = new DefaultReflector(new SingleFileSourceLocator(__DIR__ . '/../Fixture/AsymmetricVisibilityImplicitFinal.php', $this->astLocator));
9861000
$classInfo = $reflector->reflectClass('Roave\BetterReflectionTest\Fixture\AsymmetricVisibilityImplicitFinal');
9871001
$property = $classInfo->getProperty($propertyName);
9881002

9891003
self::assertSame($isFinal, $property->isFinal());
1004+
self::assertSame($modifiers, $property->getModifiers());
9901005
}
9911006

9921007
/** @return list<array{0: non-empty-string, 1: bool}> */
@@ -1019,6 +1034,7 @@ public function testIsAbstract(): void
10191034

10201035
$hookProperty = $classInfo->getProperty('hook');
10211036
self::assertTrue($hookProperty->isAbstract());
1037+
self::assertTrue($hookProperty->isPublic());
10221038
}
10231039

10241040
public function testIsAbstractInInterface(): void
@@ -1028,6 +1044,7 @@ public function testIsAbstractInInterface(): void
10281044

10291045
$abstractProperty = $classInfo->getProperty('abstractPropertyFromInterface');
10301046
self::assertTrue($abstractProperty->isAbstract());
1047+
self::assertTrue($abstractProperty->isPublic());
10311048
}
10321049

10331050
public function testNoHooks(): void
@@ -1206,6 +1223,20 @@ public function testExtendingHooks(): void
12061223
self::assertSame('Roave\BetterReflectionTest\Fixture\GetAndSetPropertyHook', $getAndSetHookProperty->getHook(ReflectionPropertyHookType::Set)->getDeclaringClass()->getName());
12071224
}
12081225

1226+
public function testExtendingHooks2(): void
1227+
{
1228+
$reflector = new DefaultReflector(new SingleFileSourceLocator(__DIR__ . '/../Fixture/PropertyHooks.php', $this->astLocator));
1229+
1230+
$classInfo = $reflector->reflectClass('Roave\BetterReflectionTest\Fixture\ExtendedHooks');
1231+
1232+
$getAndSetHookProperty = $classInfo->getProperty('hook');
1233+
self::assertCount(2, $getAndSetHookProperty->getHooks());
1234+
self::assertTrue($getAndSetHookProperty->hasHook(ReflectionPropertyHookType::Get));
1235+
self::assertTrue($getAndSetHookProperty->hasHook(ReflectionPropertyHookType::Set));
1236+
self::assertSame('Roave\BetterReflectionTest\Fixture\ExtendedHooks', $getAndSetHookProperty->getHook(ReflectionPropertyHookType::Get)->getDeclaringClass()->getName());
1237+
self::assertSame('Roave\BetterReflectionTest\Fixture\BothPropertyHooks', $getAndSetHookProperty->getHook(ReflectionPropertyHookType::Set)->getDeclaringClass()->getName());
1238+
}
1239+
12091240
public function testUseHookFromTrait(): void
12101241
{
12111242
$reflector = new DefaultReflector(new SingleFileSourceLocator(__DIR__ . '/../Fixture/PropertyHooks.php', $this->astLocator));

0 commit comments

Comments
 (0)