Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add $schema to infection.json5.dist, exclude files that breaks PHPUnit execution with Infection #5792

Merged
merged 1 commit into from
Apr 3, 2024

Conversation

maks-rafalko
Copy link
Contributor

See #5788 (comment) for the detailed explanation about what is going on and why it's needed.

@sebastianbergmann sebastianbergmann added the type/tests Tests! Yes, PHPUnit, too, needs tests. label Apr 3, 2024
Copy link

codecov bot commented Apr 3, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.17%. Comparing base (b18d5f2) to head (72e01df).

Additional details and impacted files
@@            Coverage Diff            @@
##               main    #5792   +/-   ##
=========================================
  Coverage     90.17%   90.17%           
  Complexity     6582     6582           
=========================================
  Files           693      693           
  Lines         19940    19940           
=========================================
  Hits          17980    17980           
  Misses         1960     1960           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sebastianbergmann sebastianbergmann merged commit 279f21c into sebastianbergmann:main Apr 3, 2024
26 checks passed
@staabm
Copy link
Contributor

staabm commented Apr 3, 2024

Thank you 🙏

@sebastianbergmann
Copy link
Owner

I am thankful for your work, @maks-rafalko and @staabm, but I am still seeing issues such as this basically everywhere I look:

The Finished class has a public method named test.

Infection's PublicVisibility mutator replaces public and protected and Infection then claims that this mutation survived, as can be seen in this screenshot:

318847058-26e1ad47-7f1b-4d26-9fda-17c344d12f0e

However, when I perform this mutation manually ...

diff --git a/src/Event/Events/Test/Lifecycle/Finished.php b/src/Event/Events/Test/Lifecycle/Finished.php
index 72032cf71..ae75d35c1 100644
--- a/src/Event/Events/Test/Lifecycle/Finished.php
+++ b/src/Event/Events/Test/Lifecycle/Finished.php
@@ -37,7 +37,7 @@ public function telemetryInfo(): Telemetry\Info
         return $this->telemetryInfo;
     }
 
-    public function test(): Code\Test
+    protected function test(): Code\Test
     {
         return $this->test;
     }

... and try to run PHPUnit's test suite then I get this error:

$ ./phpunit --testsuite unit
PHPUnit 11.1-gb18d5f2fe3 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.3.4
Configuration: /usr/local/src/phpunit/phpunit.xml

.

An error occurred inside PHPUnit.

Message:  Call to protected method PHPUnit\Event\Test\Finished::test() from scope PHPUnit\Runner\ResultCache\ResultCacheHandler
Location: /usr/local/src/phpunit/src/Runner/ResultCache/ResultCacheHandler.php:119

#0 /usr/local/src/phpunit/src/Runner/ResultCache/Subscriber/TestFinishedSubscriber.php(27): PHPUnit\Runner\ResultCache\ResultCacheHandler->testFinished()
#1 /usr/local/src/phpunit/src/Event/Dispatcher/DirectDispatcher.php(102): PHPUnit\Runner\ResultCache\TestFinishedSubscriber->notify()
#2 /usr/local/src/phpunit/src/Event/Dispatcher/DeferringDispatcher.php(45): PHPUnit\Event\DirectDispatcher->dispatch()
#3 /usr/local/src/phpunit/src/Event/Emitter/DispatchingEmitter.php(962): PHPUnit\Event\DeferringDispatcher->dispatch()
#4 /usr/local/src/phpunit/src/Framework/TestRunner.php(235): PHPUnit\Event\DispatchingEmitter->testFinished()
#5 /usr/local/src/phpunit/src/Framework/TestCase.php(337): PHPUnit\Framework\TestRunner->run()
#6 /usr/local/src/phpunit/src/Framework/TestSuite.php(369): PHPUnit\Framework\TestCase->run()
#7 /usr/local/src/phpunit/src/Framework/TestSuite.php(369): PHPUnit\Framework\TestSuite->run()
#8 /usr/local/src/phpunit/src/Framework/TestSuite.php(369): PHPUnit\Framework\TestSuite->run()
#9 /usr/local/src/phpunit/src/TextUI/TestRunner.php(62): PHPUnit\Framework\TestSuite->run()
#10 /usr/local/src/phpunit/src/TextUI/Application.php(200): PHPUnit\TextUI\TestRunner->run()
#11 /usr/local/src/phpunit/phpunit(104): PHPUnit\TextUI\Application->run()
#12 {main}

The mutation causes an error in PHPUnit's test runner that is not specific to a single test.

Sure, we can exclude mutators and/or source files. But I doubt that this will lead to a useful report. I fear that we must accept the fact that mutating the test (framework|runner) while running its test is an edge case that neither of us should worry about: Infection should not be adapted to cater to the mutation testing of PHPUnit, nor should PHPUnit be adapted so that mutation testing can be performed on it.

Maybe I am just too pessimistic here, but, as always, I love to be proven wrong.

In the near future (days/weeks, not months), I will add Infection to the dependencies of PHPUnit (see #5788 (comment)). This should be more straightforward.

@staabm
Copy link
Contributor

staabm commented Apr 3, 2024

Lets let this sink for a while and look into what solutions we can find :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/tests Tests! Yes, PHPUnit, too, needs tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants