BetterReflection icon indicating copy to clipboard operation
BetterReflection copied to clipboard

Bring Mutation Test score back to 100%

Open Ocramius opened this issue 2 years ago • 6 comments

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

Ocramius avatar Nov 24 '23 18:11 Ocramius

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

kukulich avatar Nov 24 '23 18:11 kukulich

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

Ocramius avatar Nov 24 '23 18:11 Ocramius

we could also contribute upstream types, maybe 🤔

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

staabm avatar Mar 13 '24 11:03 staabm

Nice :)

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

Ocramius avatar Mar 13 '24 11:03 Ocramius

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

kukulich avatar Mar 13 '24 17:03 kukulich

@kukulich sure. here you are

staabm avatar Mar 13 '24 18:03 staabm