Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ tests:
.PHONY: lint
lint:
php vendor/bin/parallel-lint --colors \
--exclude tests/Rules/DeadCode/data/bug-383.php \
--exclude tests/phpt/infection-config-default.phpt \
--exclude tests/phpt/infection-config.phpt \
src tests

.PHONY: cs-install
Expand Down
19 changes: 13 additions & 6 deletions bin/infection-config.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
#!/usr/bin/env php
<?php declare(strict_types = 1);

// Usage: php infection-config.php [--source-directory='another/path'] [--mutator-class='Infection\Mutator\Removal\MethodCallRemoval'] [--timeout=60]

error_reporting(E_ALL & ~E_DEPRECATED);
ini_set('display_errors', 'stderr');

$opts = getopt('', ['source-directory::', 'mutator-class::']);
if ($argc < 1) {
echo "Usage: php ". $argv[0] ." [--source-directory='another/path'] [--mutator-class='Infection\Mutator\Removal\MethodCallRemoval]'\n";
exit(1);
}
$opts = getopt('', ['source-directory::', 'mutator-class::', 'timeout::']);
$addSourceDirectories = (array) ($opts['source-directory'] ?? []);
$addMutatorClasses = (array) ($opts['mutator-class'] ?? []);
$timeout = $opts['timeout'] ?? null;

$defaults = file_get_contents(__DIR__.'/../resources/infection.json5');
if ($defaults === false) {
throw new RuntimeException('Unable to read infection.json5');
}
$decoded = json_decode($defaults);

$decoded = json_decode(file_get_contents(__DIR__.'/../resources/infection.json5'));
foreach($addSourceDirectories as $path) {
$decoded->source->directories[] = $path;
}
foreach($addMutatorClasses as $mutatorclass) {
$decoded->mutators->$mutatorclass = true;
}
if ($timeout !== null) {
$decoded->timeout = (int) $timeout;
}

echo json_encode($decoded);

Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
parameters:
level: 8
paths:
- bin
- src
- tests

Expand Down
30 changes: 17 additions & 13 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
colors="true"
bootstrap="./vendor/autoload.php"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
executionOrder="random"
beStrictAboutChangesToGlobalState="true"
beStrictAboutOutputDuringTests="true"
failOnRisky="true"
failOnWarning="true"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
executionOrder="random"
>
<testsuites>
<testsuite name="Infection for PHPStan">
<directory suffix="Test.php">tests</directory>
</testsuite>
</testsuites>
<testsuites>
<testsuite name="Infection for PHPStan">
<directory suffix="Test.php">tests</directory>
</testsuite>

<logging/>
<testsuite name="end-to-end">
<directory suffix=".phpt">tests/phpt</directory>
</testsuite>
</testsuites>

<logging/>
</phpunit>
25 changes: 25 additions & 0 deletions tests/phpt/infection-config-default.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
--TEST--
infection-config.php renders proper json defaults
--FILE--
<?php declare(strict_types=1);
$bin = PHP_BINARY . ' '. __DIR__.'/../../bin/infection-config.php';
echo shell_exec($bin ."| jq");
--EXPECT--
{
"$schema": "vendor/infection/infection/resources/schema.json",
"timeout": 30,
"source": {
"directories": [
"src"
]
},
"staticAnalysisTool": "phpstan",
"logs": {
"text": "tmp/infection.log"
},
"mutators": {
"@default": false,
"PHPStan\\Infection\\TrinaryLogicMutator": true
},
"bootstrap": "build-infection/vendor/autoload.php"
}
27 changes: 27 additions & 0 deletions tests/phpt/infection-config.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
--TEST--
infection-config.php renders proper json
--FILE--
<?php declare(strict_types=1);
$bin = PHP_BINARY . ' '. __DIR__.'/../../bin/infection-config.php';
echo shell_exec($bin." --source-directory='more/files/' --timeout=180 --mutator-class='My\Class' | jq");
--EXPECT--
{
"$schema": "vendor/infection/infection/resources/schema.json",
"timeout": 180,
"source": {
"directories": [
"src",
"more/files/"
]
},
"staticAnalysisTool": "phpstan",
"logs": {
"text": "tmp/infection.log"
},
"mutators": {
"@default": false,
"PHPStan\\Infection\\TrinaryLogicMutator": true,
"My\\Class": true
},
"bootstrap": "build-infection/vendor/autoload.php"
}
Loading