Skip to content

Commit f64b8a3

Browse files
committed
Ignore inherited PHPUnit suite factories
1 parent 7c2b47f commit f64b8a3

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

packages/runtime-playground/src/phpunit-command-handlers.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,8 +352,11 @@ function ${functionName}(array $argv) {
352352

353353
function phpunitClassHasTestsPhp(functionName: string): string {
354354
return `function ${functionName}(ReflectionClass $class): bool {
355-
if ($class->hasMethod('suite') && $class->getMethod('suite')->isStatic()) {
356-
return true;
355+
if ($class->hasMethod('suite')) {
356+
$suite_method = $class->getMethod('suite');
357+
if ($suite_method->isStatic() && $suite_method->getDeclaringClass()->getName() === $class->getName()) {
358+
return true;
359+
}
357360
}
358361
foreach ((new PHPUnit\\Util\\Reflection())->publicMethodsInTestClass($class) as $method) {
359362
if (PHPUnit\\Util\\Test::isTestMethod($method)) {

tests/phpunit-project-autoload.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,10 +325,13 @@ function assertDiscoveredTestExecutes(source: string, stagePrefix: "pg" | "core_
325325
: `public function __construct($name) { $this->name = $name; }`
326326

327327
writeFileSync(testFile, `<?php
328-
class ConcreteHelper extends PHPUnit\\Framework\\TestCase {
328+
abstract class ProjectTestCase extends PHPUnit\\Framework\\TestCase {
329+
public static function suite($class) {}
330+
}
331+
class ConcreteHelper extends ProjectTestCase {
329332
public function helperMethod(): void {}
330333
}
331-
class DiscoveredTest extends PHPUnit\\Framework\\TestCase {
334+
class DiscoveredTest extends ProjectTestCase {
332335
public function testDiscovered(): void {}
333336
public function run(): void {
334337
file_put_contents(getenv('EXECUTION_MARKER'), 'executed');

0 commit comments

Comments
 (0)