Skip to content

Commit 4966d4b

Browse files
committed
Kill some mutants
1 parent 58b8301 commit 4966d4b

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

@@ -265,25 +269,32 @@ public function testGetDocCommentReturnsNullWithNoComment(): void
265269
self::assertNull($property->getDocComment());
266270
}
267271

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

281-
/** @param non-empty-string $propertyName */
286+
/**
287+
* @param non-empty-string $fileName
288+
* @param class-string $className
289+
* @param non-empty-string $propertyName
290+
*/
282291
#[DataProvider('modifierProvider')]
283-
public function testGetModifiers(string $propertyName, int $expectedModifier): void
292+
public function testGetModifiers(string $fileName, string $className, string $propertyName, int $expectedModifier): void
284293
{
285-
$classInfo = $this->reflector->reflectClass(ExampleClass::class);
286-
$property = $classInfo->getProperty($propertyName);
294+
$reflector = new DefaultReflector(new SingleFileSourceLocator($fileName, $this->astLocator));
295+
$classInfo = $reflector->reflectClass($className);
296+
297+
$property = $classInfo->getProperty($propertyName);
287298

288299
self::assertSame($expectedModifier, $property->getModifiers());
289300
}
@@ -972,25 +983,29 @@ public function testIsPrivateSet(): void
972983
self::assertTrue($protectedPrivateSet->isPrivateSet());
973984
}
974985

975-
/** @return list<array{0: non-empty-string, 1: bool}> */
986+
/** @return list<array{0: non-empty-string, 1: bool, 2: int-mask-of<ReflectionPropertyAdapter::IS_*>}> */
976987
public static function asymmetricVisibilityImplicitFinalProvider(): array
977988
{
978989
return [
979-
['publicPrivateSetIsFinal', true],
980-
['protectedPrivateSetIsFinal', true],
981-
['privatePrivateSetIsNotFinal', false],
990+
['publicPrivateSetIsFinal', true, ReflectionPropertyAdapter::IS_PUBLIC | ReflectionPropertyAdapter::IS_PRIVATE_SET_COMPATIBILITY | ReflectionPropertyAdapter::IS_FINAL_COMPATIBILITY],
991+
['protectedPrivateSetIsFinal', true, ReflectionPropertyAdapter::IS_PROTECTED | ReflectionPropertyAdapter::IS_PRIVATE_SET_COMPATIBILITY | ReflectionPropertyAdapter::IS_FINAL_COMPATIBILITY],
992+
['privatePrivateSetIsNotFinal', false, ReflectionPropertyAdapter::IS_PRIVATE],
982993
];
983994
}
984995

985-
/** @param non-empty-string $propertyName */
996+
/**
997+
* @param non-empty-string $propertyName
998+
* @param int-mask-of<ReflectionPropertyAdapter::IS_*> $modifiers
999+
*/
9861000
#[DataProvider('asymmetricVisibilityImplicitFinalProvider')]
987-
public function testAsymmetricVisibilityImplicitFinal(string $propertyName, bool $isFinal): void
1001+
public function testAsymmetricVisibilityImplicitFinal(string $propertyName, bool $isFinal, int $modifiers): void
9881002
{
9891003
$reflector = new DefaultReflector(new SingleFileSourceLocator(__DIR__ . '/../Fixture/AsymmetricVisibilityImplicitFinal.php', $this->astLocator));
9901004
$classInfo = $reflector->reflectClass('Roave\BetterReflectionTest\Fixture\AsymmetricVisibilityImplicitFinal');
9911005
$property = $classInfo->getProperty($propertyName);
9921006

9931007
self::assertSame($isFinal, $property->isFinal());
1008+
self::assertSame($modifiers, $property->getModifiers());
9941009
}
9951010

9961011
/** @return list<array{0: non-empty-string, 1: bool}> */
@@ -1023,6 +1038,7 @@ public function testIsAbstract(): void
10231038

10241039
$hookProperty = $classInfo->getProperty('hook');
10251040
self::assertTrue($hookProperty->isAbstract());
1041+
self::assertTrue($hookProperty->isPublic());
10261042
}
10271043

10281044
public function testIsAbstractInInterface(): void
@@ -1032,6 +1048,7 @@ public function testIsAbstractInInterface(): void
10321048

10331049
$abstractProperty = $classInfo->getProperty('abstractPropertyFromInterface');
10341050
self::assertTrue($abstractProperty->isAbstract());
1051+
self::assertTrue($abstractProperty->isPublic());
10351052
}
10361053

10371054
public function testNoHooks(): void
@@ -1212,6 +1229,20 @@ public function testExtendingHooks(): void
12121229
self::assertSame('Roave\BetterReflectionTest\Fixture\GetAndSetPropertyHook', $getAndSetHookProperty->getHook(ReflectionPropertyHookType::Set)->getDeclaringClass()->getName());
12131230
}
12141231

1232+
public function testExtendingHooks2(): void
1233+
{
1234+
$reflector = new DefaultReflector(new SingleFileSourceLocator(__DIR__ . '/../Fixture/PropertyHooks.php', $this->astLocator));
1235+
1236+
$classInfo = $reflector->reflectClass('Roave\BetterReflectionTest\Fixture\ExtendedHooks');
1237+
1238+
$getAndSetHookProperty = $classInfo->getProperty('hook');
1239+
self::assertCount(2, $getAndSetHookProperty->getHooks());
1240+
self::assertTrue($getAndSetHookProperty->hasHook(ReflectionPropertyHookType::Get));
1241+
self::assertTrue($getAndSetHookProperty->hasHook(ReflectionPropertyHookType::Set));
1242+
self::assertSame('Roave\BetterReflectionTest\Fixture\ExtendedHooks', $getAndSetHookProperty->getHook(ReflectionPropertyHookType::Get)->getDeclaringClass()->getName());
1243+
self::assertSame('Roave\BetterReflectionTest\Fixture\BothPropertyHooks', $getAndSetHookProperty->getHook(ReflectionPropertyHookType::Set)->getDeclaringClass()->getName());
1244+
}
1245+
12151246
public function testUseHookFromTrait(): void
12161247
{
12171248
$reflector = new DefaultReflector(new SingleFileSourceLocator(__DIR__ . '/../Fixture/PropertyHooks.php', $this->astLocator));

0 commit comments

Comments
 (0)