Skip to content

Commit 178e7a8

Browse files
committed
Fix Infection tests
Infection was "passing" only because the process was failing hard which indeeds counts as killing a mutant, but in this specific case this was not for the right reasons. I investigated and managed to apply the right patches to make it work. The e2e tests also no runs the not prefixed Infection and compares the result with the prefixed one as they should be identical.
1 parent c860f27 commit 178e7a8

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

Makefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ help:
1818

1919
clean: ## Clean all created artifacts
2020
clean:
21-
git clean --exclude=.idea/ -fdx
21+
git clean --exclude=.idea/ -ffdx
2222

2323
build: ## Build the PHAR
2424
build: bin/php-scoper src vendor vendor-bin/box/vendor scoper.inc.php box.json
@@ -154,7 +154,15 @@ e2e_020: bin/php-scoper.phar fixtures/set020-infection/vendor
154154
php -d zend.enable_gc=0 $(PHPSCOPER) add-prefix --working-dir=fixtures/set020-infection --output-dir=../../build/set020-infection --force --no-interaction --stop-on-failure
155155
composer --working-dir=build/set020-infection dump-autoload
156156

157-
php build/set020-infection/vendor/infection/infection/bin/infection
157+
# Create coverage reports to be able to run Infection without running the tests
158+
php -d zend.enable_gc=0 $(PHPUNIT) --coverage-clover=clover.xml --coverage-xml=dist/infection-coverage/coverage-xml --log-junit=dist/infection-coverage/phpunit.junit.xml
159+
160+
php fixtures/set020-infection/vendor/infection/infection/bin/infection --coverage=dist/infection-coverage > build/set020-infection/expected-output
161+
php build/set020-infection/vendor/infection/infection/bin/infection --coverage=dist/infection-coverage > build/set020-infection/output
162+
163+
rm clover.xml
164+
165+
diff build/set020-infection/expected-output build/set020-infection/output
158166

159167
tb: ## Run Blackfire profiling
160168
tb: vendor

fixtures/set020-infection/scoper.inc.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,30 @@
1717
return [
1818
'patchers' => [
1919
function (string $filePath, string $prefix, string $contents): string {
20+
//
21+
// Infection shared global constant patch
22+
// @see https://github.com/humbug/php-scoper/issues/171
23+
//
2024
if ($filePath === realpath(__DIR__.'/vendor/infection/infection/app/bootstrap.php')) {
2125
return str_replace($prefix.'\INFECTION_COMPOSER_INSTALL;', 'INFECTION_COMPOSER_INSTALL;', $contents);
2226
}
2327

2428
return $contents;
2529
},
30+
function (string $filePath, string $prefix, string $contents): string {
31+
//
32+
// Infection IncludeInterceptor patch
33+
//
34+
if ($filePath === realpath(__DIR__.'/vendor/infection/infection/src/TestFramework/Config/MutationConfigBuilder.php')) {
35+
return str_replace(
36+
'use Infection\\\\StreamWrapper\\\\IncludeInterceptor;',
37+
'use '.$prefix.'\\\\Infection\\\\StreamWrapper\\\\IncludeInterceptor;',
38+
$contents
39+
);
40+
}
41+
42+
return $contents;
43+
},
2644
function (string $filePath, string $prefix, string $contents): string {
2745
//
2846
// PHP-Parser patch

0 commit comments

Comments
 (0)