Roave / BetterReflection

:crystal_ball: Better Reflection is a reflection API that aims to improve and provide more features than PHP's built-in reflection API.
MIT License
1.19k stars 131 forks source link

Bring Mutation Test score back to 100% #1382

Open Ocramius opened 11 months ago

Ocramius commented 11 months ago

Seen in #1381 and #1380 ( https://github.com/Roave/BetterReflection/actions/runs/6983487200/job/19004937424?pr=1381#step:5:11665 )

Error: ] The minimum required MSI percentage should be 100%, but actual is      
         99.73%. Improve your tests!        
Escaped mutants:
================

1) /home/runner/work/BetterReflection/BetterReflection/src/Reflection/ReflectionFunctionAbstract.php:112    [M] GreaterThan

--- Original
+++ New
@@ @@
         $startLine = null;
         if ($node->hasAttribute('startLine')) {
             $startLine = $node->getStartLine();
-            assert($startLine > 0);
+            assert($startLine >= 0);
         }
         $endLine = null;
         if ($node->hasAttribute('endLine')) {

2) /home/runner/work/BetterReflection/BetterReflection/src/Reflection/ReflectionFunctionAbstract.php:118    [M] GreaterThan

--- Original
+++ New
@@ @@
         $endLine = null;
         if ($node->hasAttribute('endLine')) {
             $endLine = $node->getEndLine();
-            assert($endLine > 0);
+            assert($endLine >= 0);
         }
         $this->startLine = $startLine;
         $this->endLine = $endLine;

3) /home/runner/work/BetterReflection/BetterReflection/src/Reflection/ReflectionFunctionAbstract.php:507    [M] InstanceOf_

--- Original
+++ New
@@ @@
         if ($returnType === null) {
             return null;
         }
-        assert($returnType instanceof Node\Identifier || $returnType instanceof Node\Name || $returnType instanceof Node\NullableType || $returnType instanceof Node\UnionType || $returnType instanceof Node\IntersectionType);
+        assert(true || $returnType instanceof Node\Name || $returnType instanceof Node\NullableType || $returnType instanceof Node\UnionType || $returnType instanceof Node\IntersectionType);
         return ReflectionType::createFromNode($this->reflector, $this, $returnType);
     }
     /** @return list<ReflectionAttribute> */

4) /home/runner/work/BetterReflection/BetterReflection/src/Reflection/ReflectionFunctionAbstract.php:507    [M] InstanceOf_

--- Original
+++ New
@@ @@
         if ($returnType === null) {
             return null;
         }
-        assert($returnType instanceof Node\Identifier || $returnType instanceof Node\Name || $returnType instanceof Node\NullableType || $returnType instanceof Node\UnionType || $returnType instanceof Node\IntersectionType);
+        assert($returnType instanceof Node\Identifier || true || $returnType instanceof Node\NullableType || $returnType instanceof Node\UnionType || $returnType instanceof Node\IntersectionType);
         return ReflectionType::createFromNode($this->reflector, $this, $returnType);
     }
     /** @return list<ReflectionAttribute> */

5) /home/runner/work/BetterReflection/BetterReflection/src/Reflection/ReflectionFunctionAbstract.php:507    [M] InstanceOf_

--- Original
-        assert($returnType instanceof Node\Identifier || $returnType instanceof Node\Name || $returnType instanceof Node\NullableType || $returnType instanceof Node\UnionType || $returnType instanceof Node\IntersectionType);
+        assert($returnType instanceof Node\Identifier || $returnType instanceof Node\Name || $returnType instanceof Node\NullableType || $returnType instanceof Node\UnionType || false);
         return ReflectionType::createFromNode($this->reflector, $this, $returnType);
     }
     /** @return list<ReflectionAttribute> */

9) /home/runner/work/BetterReflection/BetterReflection/src/Reflection/ReflectionFunctionAbstract.php:507    [M] LogicalOrAllSubExprNegation

--- Original
+++ New
@@ @@
         if ($returnType === null) {
             return null;
         }
-        assert($returnType instanceof Node\Identifier || $returnType instanceof Node\Name || $returnType instanceof Node\NullableType || $returnType instanceof Node\UnionType || $returnType instanceof Node\IntersectionType);
+        assert(!$returnType instanceof Node\Identifier || !$returnType instanceof Node\Name || !$returnType instanceof Node\NullableType || !$returnType instanceof Node\UnionType || !$returnType instanceof Node\IntersectionType);
         return ReflectionType::createFromNode($this->reflector, $this, $returnType);
     }
     /** @return list<ReflectionAttribute> */

Not Covered mutants:
====================
Warning: Escaped Mutant for Mutator "GreaterThan":

--- Original
+++ New
@@ @@
         $startLine = null;
         if ($node->hasAttribute('startLine')) {
             $startLine = $node->getStartLine();
-            assert($startLine > 0);
+            assert($startLine >= 0);
         }
         $endLine = null;
         if ($node->hasAttribute('endLine')) {

Warning: Escaped Mutant for Mutator "GreaterThan":

--- Original
+++ New
@@ @@
         $endLine = null;
         if ($node->hasAttribute('endLine')) {
             $endLine = $node->getEndLine();

Warning: Escaped Mutant for Mutator "InstanceOf_":

--- Original
+++ New
@@ @@
         if ($returnType === null) {
             return null;
         }
-        assert($returnType instanceof Node\Identifier || $returnType instanceof Node\Name || $returnType instanceof Node\NullableType || $returnType instanceof Node\UnionType || $returnType instanceof Node\IntersectionType);
+        assert($returnType instanceof Node\Identifier || $returnType instanceof Node\Name || $returnType instanceof Node\NullableType || true || $returnType instanceof Node\IntersectionType);
         return ReflectionType::createFromNode($this->reflector, $this, $returnType);
     }
     /** @return list<ReflectionAttribute> */

Warning: Escaped Mutant for Mutator "InstanceOf_":

--- Original
+++ New
@@ @@
         if ($returnType === null) {
             return null;
         }
-        assert($returnType instanceof Node\Identifier || $returnType instanceof Node\Name || $returnType instanceof Node\NullableType || $returnType instanceof Node\UnionType || $returnType instanceof Node\IntersectionType);
+        assert($returnType instanceof Node\Identifier || $returnType instanceof Node\Name || $returnType instanceof Node\NullableType || $returnType instanceof Node\UnionType || true);
         return ReflectionType::createFromNode($this->reflector, $this, $returnType);
     }
     /** @return list<ReflectionAttribute> */

Warning: Escaped Mutant for Mutator "InstanceOf_":

--- Original
+++ New
@@ @@
         if ($returnType === null) {
             return null;
         }
-        assert($returnType instanceof Node\Identifier || $returnType instanceof Node\Name || $returnType instanceof Node\NullableType || $returnType instanceof Node\UnionType || $returnType instanceof Node\IntersectionType);
+        assert($returnType instanceof Node\Identifier || $returnType instanceof Node\Name || $returnType instanceof Node\NullableType || $returnType instanceof Node\UnionType || false);
         return ReflectionType::createFromNode($this->reflector, $this, $returnType);
     }
     /** @return list<ReflectionAttribute> */

Warning: Escaped Mutant for Mutator "LogicalOrAllSubExprNegation":

--- Original
+++ New
@@ @@
         if ($returnType === null) {
             return null;
         }
-        assert($returnType instanceof Node\Identifier || $returnType instanceof Node\Name || $returnType instanceof Node\NullableType || $returnType instanceof Node\UnionType || $returnType instanceof Node\IntersectionType);
+        assert(!$returnType instanceof Node\Identifier || !$returnType instanceof Node\Name || !$returnType instanceof Node\NullableType || !$returnType instanceof Node\UnionType || !$returnType instanceof Node\IntersectionType);
         return ReflectionType::createFromNode($this->reflector, $this, $returnType);
     }
     /** @return list<ReflectionAttribute> */

Warning:  Dashboard report has not been sent: The current process is a pull request build
kukulich commented 11 months ago

I don't have better solution than: https://github.com/Roave/BetterReflection/pull/1377#issuecomment-1819624130 :(

Ocramius commented 11 months ago

@kukulich we could also contribute upstream types, maybe :thinking:

staabm commented 8 months ago

we could also contribute upstream types, maybe 🤔

I think this is what I did with https://github.com/nikic/PHP-Parser/pull/985

Ocramius commented 8 months ago

Nice :)

BTW, moving to PHP-Parser v5 already improved things a lot :)

kukulich commented 8 months ago

@staabm Is it possible to prepare PR with your PHPParser so we can see the difference? I'm just curious if it will work :)

staabm commented 8 months ago

@kukulich sure. here you are