Skip to content

Commit daf2348

Browse files
authored
Added bin/infection-config.php --timeout option (#21)
1 parent 8bc21f6 commit daf2348

File tree

6 files changed

+85
-20
lines changed

6 files changed

+85
-20
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ tests:
88
.PHONY: lint
99
lint:
1010
php vendor/bin/parallel-lint --colors \
11-
--exclude tests/Rules/DeadCode/data/bug-383.php \
11+
--exclude tests/phpt/infection-config-default.phpt \
12+
--exclude tests/phpt/infection-config.phpt \
1213
src tests
1314

1415
.PHONY: cs-install

bin/infection-config.php

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
#!/usr/bin/env php
22
<?php declare(strict_types = 1);
33

4+
// Usage: php infection-config.php [--source-directory='another/path'] [--mutator-class='Infection\Mutator\Removal\MethodCallRemoval'] [--timeout=60]
5+
46
error_reporting(E_ALL & ~E_DEPRECATED);
57
ini_set('display_errors', 'stderr');
68

7-
$opts = getopt('', ['source-directory::', 'mutator-class::']);
8-
if ($argc < 1) {
9-
echo "Usage: php ". $argv[0] ." [--source-directory='another/path'] [--mutator-class='Infection\Mutator\Removal\MethodCallRemoval]'\n";
10-
exit(1);
11-
}
9+
$opts = getopt('', ['source-directory::', 'mutator-class::', 'timeout::']);
1210
$addSourceDirectories = (array) ($opts['source-directory'] ?? []);
1311
$addMutatorClasses = (array) ($opts['mutator-class'] ?? []);
12+
$timeout = $opts['timeout'] ?? null;
13+
14+
$defaults = file_get_contents(__DIR__.'/../resources/infection.json5');
15+
if ($defaults === false) {
16+
throw new RuntimeException('Unable to read infection.json5');
17+
}
18+
$decoded = json_decode($defaults);
1419

15-
$decoded = json_decode(file_get_contents(__DIR__.'/../resources/infection.json5'));
1620
foreach($addSourceDirectories as $path) {
1721
$decoded->source->directories[] = $path;
1822
}
1923
foreach($addMutatorClasses as $mutatorclass) {
2024
$decoded->mutators->$mutatorclass = true;
2125
}
26+
if ($timeout !== null) {
27+
$decoded->timeout = (int) $timeout;
28+
}
2229

2330
echo json_encode($decoded);
2431

phpstan.neon

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
parameters:
22
level: 8
33
paths:
4+
- bin
45
- src
56
- tests
67

phpunit.xml

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
<?xml version="1.0"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
colors="true"
3+
colors="true"
44
bootstrap="./vendor/autoload.php"
5-
beStrictAboutChangesToGlobalState="true"
6-
beStrictAboutOutputDuringTests="true"
7-
failOnRisky="true"
8-
failOnWarning="true"
9-
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
10-
executionOrder="random"
5+
beStrictAboutChangesToGlobalState="true"
6+
beStrictAboutOutputDuringTests="true"
7+
failOnRisky="true"
8+
failOnWarning="true"
9+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
10+
executionOrder="random"
1111
>
12-
<testsuites>
13-
<testsuite name="Infection for PHPStan">
14-
<directory suffix="Test.php">tests</directory>
15-
</testsuite>
16-
</testsuites>
12+
<testsuites>
13+
<testsuite name="Infection for PHPStan">
14+
<directory suffix="Test.php">tests</directory>
15+
</testsuite>
1716

18-
<logging/>
17+
<testsuite name="end-to-end">
18+
<directory suffix=".phpt">tests/phpt</directory>
19+
</testsuite>
20+
</testsuites>
21+
22+
<logging/>
1923
</phpunit>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--TEST--
2+
infection-config.php renders proper json defaults
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$bin = PHP_BINARY . ' '. __DIR__.'/../../bin/infection-config.php';
6+
echo shell_exec($bin ."| jq");
7+
--EXPECT--
8+
{
9+
"$schema": "vendor/infection/infection/resources/schema.json",
10+
"timeout": 30,
11+
"source": {
12+
"directories": [
13+
"src"
14+
]
15+
},
16+
"staticAnalysisTool": "phpstan",
17+
"logs": {
18+
"text": "tmp/infection.log"
19+
},
20+
"mutators": {
21+
"@default": false,
22+
"PHPStan\\Infection\\TrinaryLogicMutator": true
23+
},
24+
"bootstrap": "build-infection/vendor/autoload.php"
25+
}

tests/phpt/infection-config.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
infection-config.php renders proper json
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$bin = PHP_BINARY . ' '. __DIR__.'/../../bin/infection-config.php';
6+
echo shell_exec($bin." --source-directory='more/files/' --timeout=180 --mutator-class='My\Class' | jq");
7+
--EXPECT--
8+
{
9+
"$schema": "vendor/infection/infection/resources/schema.json",
10+
"timeout": 180,
11+
"source": {
12+
"directories": [
13+
"src",
14+
"more/files/"
15+
]
16+
},
17+
"staticAnalysisTool": "phpstan",
18+
"logs": {
19+
"text": "tmp/infection.log"
20+
},
21+
"mutators": {
22+
"@default": false,
23+
"PHPStan\\Infection\\TrinaryLogicMutator": true,
24+
"My\\Class": true
25+
},
26+
"bootstrap": "build-infection/vendor/autoload.php"
27+
}

0 commit comments

Comments
 (0)