Skip to content

Commit 7df0925

Browse files
committed
fix new issues founded by static analyzing tools, update baselines, increase MSI as much as possible
1 parent 7d3a122 commit 7df0925

File tree

9 files changed

+51
-43
lines changed

9 files changed

+51
-43
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ COMPOSER=$(PHP) $(shell which composer)
3333

3434
# Infection
3535
INFECTION=vendor/bin/infection
36-
MIN_MSI=52.678571428571
37-
MIN_COVERED_MSI=96
36+
MIN_MSI=52.212389380531
37+
MIN_COVERED_MSI=95
3838
INFECTION_ARGS=--min-msi=$(MIN_MSI) --min-covered-msi=$(MIN_COVERED_MSI) --threads=$(JOBS) --log-verbosity=default --show-mutations
3939

4040
all: test

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@
4949
"phpstan/phpstan-webmozart-assert": "^0.12.8",
5050
"phpunit/phpunit": "^8.5",
5151
"thecodingmachine/safe": "^1.3",
52-
"vimeo/psalm": "^4.3"
52+
"vimeo/psalm": "^4.4"
5353
}
5454
}

composer.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

psalm-baseline.xml

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<files psalm-version="3.8.5@e6ec5fa22a7b9e61670a24d07b3119aff80dcd89">
2+
<files psalm-version="4.4.1@9fd7a7d885b3a216cff8dec9d8c21a132f275224">
33
<file src="src/CommandLineBuilder.php">
44
<ForbiddenCode occurrences="1">
5-
<code>`command -v php`</code>
5+
<code>shell_exec('command -v php')</code>
66
</ForbiddenCode>
77
</file>
88
<file src="src/Config/AbstractYamlConfiguration.php">
99
<MixedArgument occurrences="1">
1010
<code>$extensionName</code>
1111
</MixedArgument>
12-
<MixedAssignment occurrences="1">
12+
<MixedAssignment occurrences="2">
13+
<code>$extensionName</code>
1314
<code>$options</code>
1415
</MixedAssignment>
1516
</file>
@@ -41,7 +42,13 @@
4142
<MixedArrayAccess occurrences="1">
4243
<code>$parsedYaml['extensions'][$extensionName]</code>
4344
</MixedArrayAccess>
44-
<MixedAssignment occurrences="2">
45+
<MixedArrayAssignment occurrences="2">
46+
<code>$options['format']</code>
47+
<code>$options['output']</code>
48+
</MixedArrayAssignment>
49+
<MixedAssignment occurrences="4">
50+
<code>$extensionName</code>
51+
<code>$extensionName</code>
4552
<code>$options</code>
4653
<code>$options</code>
4754
</MixedAssignment>
@@ -53,9 +60,10 @@
5360
<MixedArgument occurrences="1">
5461
<code>$extensionName</code>
5562
</MixedArgument>
56-
<MixedAssignment occurrences="2">
57-
<code>$options</code>
63+
<MixedAssignment occurrences="3">
64+
<code>$extensionName</code>
5865
<code>$filteredExtensions[$extensionName]</code>
66+
<code>$options</code>
5967
</MixedAssignment>
6068
</file>
6169
<file src="src/PhpSpecAdapterFactory.php">

psalm.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
<MissingReturnType errorLevel="error" />
3636
<MissingPropertyType errorLevel="error" />
3737
<InvalidDocblock errorLevel="error" />
38-
<MisplacedRequiredParam errorLevel="error" />
3938

4039
<PropertyNotSetInConstructor errorLevel="error" />
4140
<MissingConstructor errorLevel="error" />

src/PhpSpecAdapter.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ final class PhpSpecAdapter implements TestFrameworkAdapter
5858
private $mutationConfigBuilder;
5959
private $versionParser;
6060
private $commandLineBuilder;
61-
/**
62-
* @var string|null
63-
*/
64-
private $cachedVersion;
61+
private ?string $cachedVersion = null;
6562

6663
public function __construct(
6764
string $testFrameworkExecutable,
@@ -127,21 +124,21 @@ public function getInitialTestRunCommandLine(
127124
/**
128125
* Returns array of arguments to pass them into the Mutant Symfony Process
129126
*
130-
* @param TestLocation[] $tests
127+
* @param TestLocation[] $coverageTests
131128
*
132129
* @return string[]
133130
*/
134131
public function getMutantCommandLine(
135-
array $tests,
136-
string $mutantFilePath,
132+
array $coverageTests,
133+
string $mutatedFilePath,
137134
string $mutationHash,
138135
string $mutationOriginalFilePath,
139136
string $extraOptions
140137
): array {
141138
return $this->getCommandLine(
142139
$this->buildMutationConfigFile(
143-
$tests,
144-
$mutantFilePath,
140+
$coverageTests,
141+
$mutatedFilePath,
145142
$mutationHash,
146143
$mutationOriginalFilePath
147144
),
@@ -165,16 +162,14 @@ public function getVersion(): string
165162
$process = new Process($testFrameworkVersionExecutable);
166163
$process->mustRun();
167164

168-
$version = 'unknown';
169-
170165
try {
171166
$version = $this->versionParser->parse($process->getOutput());
172167
} catch (InvalidArgumentException $e) {
173168
$version = 'unknown';
174-
} finally {
175-
$this->cachedVersion = $version;
176169
}
177170

171+
$this->cachedVersion = $version;
172+
178173
return $this->cachedVersion;
179174
}
180175

tests/phpunit/Config/Builder/InitialConfigBuilderTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public function test_it_builds_path_to_initial_config_file(): void
4949

5050
$builder = new InitialConfigBuilder($this->tmp, $originalYamlConfigPath, false);
5151

52-
self::assertSame($this->tmp . '/phpspecConfiguration.initial.infection.yml', $builder->build('2.0'));
52+
$actualPath = $builder->build('2.0');
53+
54+
self::assertFileExists($actualPath);
55+
self::assertSame($this->tmp . '/phpspecConfiguration.initial.infection.yml', $actualPath);
5356
}
5457
}

tests/phpunit/Config/Builder/MutationConfigBuilderTest.php

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,15 @@ public function test_it_builds_path_to_mutation_config_file(): void
5555

5656
$builder = new MutationConfigBuilder($this->tmp, $originalYamlConfigPath, $projectDir);
5757

58-
self::assertSame(
59-
$this->tmp . '/phpspecConfiguration.a1b2c3.infection.yml',
60-
$builder->build(
61-
[],
62-
self::MUTATED_FILE_PATH,
63-
self::MUTATION_HASH,
64-
self::ORIGINAL_FILE_PATH
65-
)
58+
$actualPath = $builder->build(
59+
[],
60+
self::MUTATED_FILE_PATH,
61+
self::MUTATION_HASH,
62+
self::ORIGINAL_FILE_PATH
6663
);
64+
65+
self::assertFileExists($actualPath);
66+
self::assertSame($this->tmp . '/phpspecConfiguration.a1b2c3.infection.yml', $actualPath);
6767
}
6868

6969
public function test_it_adds_original_bootstrap_file_to_custom_autoload(): void
@@ -82,10 +82,11 @@ public function test_it_adds_original_bootstrap_file_to_custom_autoload(): void
8282
self::ORIGINAL_FILE_PATH
8383
)
8484
);
85-
self::assertStringContainsString(
86-
"require_once '/project/dir/bootstrap.php';",
87-
file_get_contents($this->tmp . '/interceptor.phpspec.autoload.a1b2c3.infection.php')
88-
);
85+
86+
$actualContent = file_get_contents($this->tmp . '/interceptor.phpspec.autoload.a1b2c3.infection.php');
87+
88+
self::assertStringContainsString("require_once '/project/dir/bootstrap.php';", $actualContent);
89+
self::assertStringNotContainsString('\Phar::loadPhar("%s", "%s");', $actualContent);
8990
}
9091

9192
public function test_interceptor_is_included(): void

tests/phpunit/Config/MutationYamlConfigurationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ final class MutationYamlConfigurationTest extends TestCase
6666
'SomeOtherExtension' => ['option' => 123],
6767
],
6868
'bootstrap' => '/path/to/adc',
69+
'verbose' => true,
6970
];
7071

7172
public function test_it_removes_code_coverage_extension(): void
@@ -80,6 +81,7 @@ public function test_it_removes_code_coverage_extension(): void
8081
'FirstExtension' => [],
8182
'SomeOtherExtension' => ['option' => 123],
8283
],
84+
'verbose' => true,
8385
];
8486

8587
self::assertSame($expectedConfig, $parsedYaml);

0 commit comments

Comments
 (0)