Skip to content

Commit c6935cd

Browse files
Detect PHPUnit suite from CLI arguments
1 parent 50a6863 commit c6935cd

1 file changed

Lines changed: 50 additions & 1 deletion

File tree

tests/TestSuiteSubscriber.php

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,55 @@ public function notify(Started $event): void
2323

2424
public static function getCurrentSuite(): string
2525
{
26-
return self::$currentSuite;
26+
if (self::$currentSuite !== '') {
27+
return self::$currentSuite;
28+
}
29+
30+
return self::inferCurrentSuiteFromArguments();
31+
}
32+
33+
private static function inferCurrentSuiteFromArguments(): string
34+
{
35+
$arguments = $_SERVER['argv'] ?? $GLOBALS['argv'] ?? [];
36+
37+
foreach ($arguments as $index => $argument) {
38+
if (! is_string($argument)) {
39+
continue;
40+
}
41+
42+
if (str_starts_with($argument, '--testsuite=')) {
43+
$suite = substr($argument, strlen('--testsuite='));
44+
45+
if (in_array($suite, ['unit', 'feature'], true)) {
46+
return $suite;
47+
}
48+
}
49+
50+
if ($argument === '--testsuite') {
51+
$suite = $arguments[$index + 1] ?? null;
52+
53+
if (is_string($suite) && in_array($suite, ['unit', 'feature'], true)) {
54+
return $suite;
55+
}
56+
}
57+
}
58+
59+
foreach ($arguments as $argument) {
60+
if (! is_string($argument)) {
61+
continue;
62+
}
63+
64+
$normalized = str_replace('\\', '/', $argument);
65+
66+
if (str_contains($normalized, 'tests/Feature/')) {
67+
return 'feature';
68+
}
69+
70+
if (str_contains($normalized, 'tests/Unit/')) {
71+
return 'unit';
72+
}
73+
}
74+
75+
return '';
2776
}
2877
}

0 commit comments

Comments
 (0)