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.18k stars 131 forks source link

Added test-case for deprecated phpstorm stub with patch-version #1406

Closed staabm closed 6 months ago

staabm commented 6 months ago

tests the ternary in https://github.com/Roave/BetterReflection/blob/ab47d0b335a33ac211d5ad8758a48ed6be8622ca/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php#L677 which wasn't covered before

Ocramius commented 6 months ago

which wasn't covered before

Was it an escaped / uncovered mutation?

staabm commented 6 months ago

Was it an escaped / uncovered mutation?

I don't know. I am not a mutation testing expert.

but I realized that this is a path which wasn't test-covered before while working on the PHPStan integration

Ocramius commented 6 months ago

I don't know. I am not a mutation testing expert.

I was more wondering if mainline caught it - should be visible in the MT framework output :D

Ocramius commented 6 months ago

(wrong button - thanks Github for not dong TAB+ENTER correctly)

kukulich commented 6 months ago

https://github.com/Roave/BetterReflection/commit/28ef29b9e81c77a3157a33af64486e5c1545fa3c

So I think there may be some escaped mutants now...

Ocramius commented 6 months ago

FWIW, in mainline:


6) /home/runner/work/BetterReflection/BetterReflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php:676    [M] IncrementInteger

--- Original
+++ New
@@ @@
         }
         if (preg_match('#@deprecated\\s+(\\d+)\\.(\\d+)(?:\\.(\\d+)?)$#m', $docComment->getText(), $matches) === 1) {
             $major = $matches[1];
-            $minor = $matches[2];
+            $minor = $matches[3];
             $patch = $matches[3] ?? 0;
             $versionId = sprintf('%d%02d%02d', $major, $minor, $patch);
             if ($this->phpVersion >= $versionId) {

7) /home/runner/work/BetterReflection/BetterReflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php:677    [M] DecrementInteger

--- Original
+++ New
@@ @@
         if (preg_match('#@deprecated\\s+(\\d+)\\.(\\d+)(?:\\.(\\d+)?)$#m', $docComment->getText(), $matches) === 1) {
             $major = $matches[1];
             $minor = $matches[2];
-            $patch = $matches[3] ?? 0;
+            $patch = $matches[2] ?? 0;
             $versionId = sprintf('%d%02d%02d', $major, $minor, $patch);
             if ($this->phpVersion >= $versionId) {
                 return true;

8) /home/runner/work/BetterReflection/BetterReflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php:677    [M] IncrementInteger

--- Original
+++ New
@@ @@
         if (preg_match('#@deprecated\\s+(\\d+)\\.(\\d+)(?:\\.(\\d+)?)$#m', $docComment->getText(), $matches) === 1) {
             $major = $matches[1];
             $minor = $matches[2];
-            $patch = $matches[3] ?? 0;
+            $patch = $matches[4] ?? 0;
             $versionId = sprintf('%d%02d%02d', $major, $minor, $patch);
             if ($this->phpVersion >= $versionId) {
                 return true;

9) /home/runner/work/BetterReflection/BetterReflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php:677    [M] DecrementInteger

--- Original
+++ New
@@ @@
         if (preg_match('#@deprecated\\s+(\\d+)\\.(\\d+)(?:\\.(\\d+)?)$#m', $docComment->getText(), $matches) === 1) {
             $major = $matches[1];
             $minor = $matches[2];
-            $patch = $matches[3] ?? 0;
+            $patch = $matches[3] ?? -1;
             $versionId = sprintf('%d%02d%02d', $major, $minor, $patch);
             if ($this->phpVersion >= $versionId) {
                 return true;

10) /home/runner/work/BetterReflection/BetterReflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php:677    [M] IncrementInteger

--- Original
+++ New
@@ @@
         if (preg_match('#@deprecated\\s+(\\d+)\\.(\\d+)(?:\\.(\\d+)?)$#m', $docComment->getText(), $matches) === 1) {
             $major = $matches[1];
             $minor = $matches[2];
-            $patch = $matches[3] ?? 0;
+            $patch = $matches[3] ?? 1;
             $versionId = sprintf('%d%02d%02d', $major, $minor, $patch);
             if ($this->phpVersion >= $versionId) {
                 return true;

11) /home/runner/work/BetterReflection/BetterReflection/src/SourceLocator/SourceStubber/PhpStormStubsSourceStubber.php:677    [M] Coalesce

--- Original
+++ New
@@ @@
         if (preg_match('#@deprecated\\s+(\\d+)\\.(\\d+)(?:\\.(\\d+)?)$#m', $docComment->getText(), $matches) === 1) {
             $major = $matches[1];
             $minor = $matches[2];
-            $patch = $matches[3] ?? 0;
+            $patch = 0 ?? $matches[3];
             $versionId = sprintf('%d%02d%02d', $major, $minor, $patch);
             if ($this->phpVersion >= $versionId) {
                 return true;

That should be OK with this patch now :)

This is mostly to show @staabm how to read this: I think MT is something that will be great for your testing toolbox, since you are so detail-oriented :muscle:

Ocramius commented 6 months ago

I don't see mutation changes here: I think your test scenario did not hit the edge case you were going for, as the mutations stayed the same :D

staabm commented 6 months ago

thanks for the explanation.

lets see whether we can kill some mainline mutants with https://github.com/nikic/PHP-Parser/pull/985 :-)

staabm commented 6 months ago

FWIW, in mainline:

looking at the latest build of the latest 6.28.x-commit, I don't see the mutants you referenced in your comment

https://github.com/Roave/BetterReflection/actions/runs/8259610533/job/22593799759

staabm commented 6 months ago

superseded by https://github.com/Roave/BetterReflection/pull/1408