Skip to content

Commit abbae3e

Browse files
authored
refactor: Inject the test framework name from the factory instead of the adapter (#51)
See the rationale in infection/phpspec-adapter#89.
1 parent 763f82e commit abbae3e

File tree

5 files changed

+17
-7
lines changed

5 files changed

+17
-7
lines changed

src/CodeceptionAdapter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ final class CodeceptionAdapter implements MemoryUsageAware, TestFrameworkAdapter
7979
private ?string $cachedVersion = null;
8080

8181
public function __construct(
82+
private readonly string $name,
8283
private string $testFrameworkExecutable,
8384
private CommandLineBuilder $commandLineBuilder,
8485
private VersionParser $versionParser,
@@ -137,7 +138,7 @@ public function getMemoryUsed(string $output): float
137138

138139
public function getName(): string
139140
{
140-
return self::NAME;
141+
return $this->name;
141142
}
142143

143144
public function getInitialTestRunCommandLine(string $extraOptions, array $phpExtraArgs, bool $skipCoverage): array

src/CodeceptionAdapterFactory.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@
4646

4747
final class CodeceptionAdapterFactory implements TestFrameworkAdapterFactory
4848
{
49+
private const NAME = 'Codeception';
50+
4951
private const COVERAGE_DIR = 'coverage-xml';
5052

5153
/**
@@ -62,9 +64,10 @@ public static function create(
6264
bool $skipCoverage,
6365
): TestFrameworkAdapter {
6466
return new CodeceptionAdapter(
67+
self::NAME,
6568
$testFrameworkExecutable,
6669
new CommandLineBuilder(),
67-
new VersionParser(),
70+
new VersionParser(self::NAME),
6871
new JUnitTestCaseSorter(),
6972
new Filesystem(),
7073
Path::makeRelative($jUnitFilePath, $tmpDir),
@@ -80,7 +83,7 @@ public static function create(
8083

8184
public static function getAdapterName(): string
8285
{
83-
return CodeceptionAdapter::NAME;
86+
return 'codeception';
8487
}
8588

8689
public static function getExecutableName(): string

src/VersionParser.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ class VersionParser
4646
{
4747
private const VERSION_REGEX = '/(?<version>[0-9]+\.[0-9]+\.?[0-9]*)(?<prerelease>-[0-9a-zA-Z.]+)?(?<build>\+[0-9a-zA-Z.]+)?/';
4848

49+
public function __construct(
50+
private readonly string $name,
51+
) {
52+
}
53+
4954
/**
5055
* @throws InvalidVersion
5156
*/
@@ -56,7 +61,7 @@ public function parse(string $content): string
5661

5762
if (!$matched) {
5863
throw self::createInvalidVersion(
59-
CodeceptionAdapter::NAME,
64+
$this->name,
6065
$content,
6166
);
6267
}

tests/phpunit/Adapter/CodeceptionAdapterTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -434,9 +434,10 @@ public static function phpCoverageOptionProvider(): iterable
434434
private function createAdapter(?array $config = null, ?string $version = 'unknown'): CodeceptionAdapter
435435
{
436436
$adapter = new CodeceptionAdapter(
437+
'codeception',
437438
'/path/to/codeception',
438439
new CommandLineBuilder(),
439-
new VersionParser(),
440+
new VersionParser('Codeception'),
440441
new JUnitTestCaseSorter(),
441442
new Filesystem(),
442443
'path/to/junit',

tests/phpunit/Adapter/VersionParserTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ final class VersionParserTest extends TestCase
4545

4646
protected function setUp(): void
4747
{
48-
$this->versionParser = new VersionParser();
48+
$this->versionParser = new VersionParser('TestCodeception');
4949
}
5050

5151
/**
@@ -62,7 +62,7 @@ public function test_it_throws_exception_when_content_has_no_version_substring()
6262
{
6363
$this->expectExceptionObject(
6464
new InvalidVersion(
65-
'Could not recognise the test framework version for codeception for the value "abc".',
65+
'Could not recognise the test framework version for TestCodeception for the value "abc".',
6666
),
6767
);
6868

0 commit comments

Comments
 (0)