Skip to content

Commit 763f82e

Browse files
authored
fix: Throw invalid version exception (#59)
We current have the following adapters: - Codeception - PhpSpec - PHPUnit - PHPStan Of all of them, only Codeception has this behaviour of swallowing the exception to display `unknown` instead of throwing `InvalidVersion`. I am not certain it is correct, but I prefer it to be wrong and find that out and fix it everywhere than having one adpater behaving differently.
1 parent 5f8411e commit 763f82e

File tree

2 files changed

+7
-17
lines changed

2 files changed

+7
-17
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
!/.tools/.gitkeep
2+
!/tests/e2e/*/var/.gitkeep
23
.phpunit.result.cache
34
/.composer/
45
/.idea
@@ -9,6 +10,5 @@
910
/tests/**/_generated/
1011
/tests/**/_output/
1112
/tests/e2e/*/var/
12-
!/tests/e2e/*/var/.gitkeep
1313
/var/
1414
/vendor/

src/CodeceptionAdapter.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
use function explode;
4444
use function implode;
4545
use Infection\AbstractTestFramework\Coverage\TestLocation;
46-
use Infection\AbstractTestFramework\InvalidVersion;
4746
use Infection\AbstractTestFramework\MemoryUsageAware;
4847
use Infection\AbstractTestFramework\TestFrameworkAdapter;
4948
use Infection\StreamWrapper\IncludeInterceptor;
@@ -235,15 +234,7 @@ public function getVersion(): string
235234
$process = new Process($testFrameworkVersionExecutable);
236235
$process->mustRun();
237236

238-
try {
239-
$version = $this->versionParser->parse($process->getOutput());
240-
} catch (InvalidVersion) {
241-
$version = 'unknown';
242-
}
243-
244-
$this->cachedVersion = $version;
245-
246-
return $this->cachedVersion;
237+
return $this->cachedVersion ??= $this->versionParser->parse($process->getOutput());
247238
}
248239

249240
public function getInitialTestsFailRecommendations(string $commandLine): string
@@ -265,12 +256,11 @@ private static function getDisableCoveragePhpOptions(
265256

266257
private static function isDisableCoveragePhpOptionSupported(string $version): bool
267258
{
268-
return $version !== 'unknown'
269-
&& version_compare(
270-
$version,
271-
self::MIN_VERSION_DISABLE_COVERAGE_PHP,
272-
'>=',
273-
);
259+
return version_compare(
260+
$version,
261+
self::MIN_VERSION_DISABLE_COVERAGE_PHP,
262+
'>=',
263+
);
274264
}
275265

276266
private function getInterceptorFileContent(string $interceptorPath, string $originalFilePath, string $mutatedFilePath): string

0 commit comments

Comments
 (0)