Skip to content

Commit 3d81e35

Browse files
authored
Ungrouped tests should have default group assigned (#623)
Fixes #622
1 parent c1fdc98 commit 3d81e35

File tree

4 files changed

+79
-0
lines changed

4 files changed

+79
-0
lines changed

src/Runners/PHPUnit/SuiteLoader.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
use function ksort;
3939
use function preg_match;
4040
use function sprintf;
41+
use function strpos;
4142
use function strrpos;
4243
use function substr;
4344
use function trim;
@@ -323,7 +324,12 @@ private function getMethodTests(ParsedClass $class, ReflectionMethod $method): a
323324
{
324325
$result = [];
325326

327+
/** @var string[] $groups */
326328
$groups = Test::getGroups($class->getName(), $method->getName());
329+
if ($this->containsOnlyVirtualGroups($groups)) {
330+
$groups[] = 'default';
331+
}
332+
327333
if (! $this->testMatchGroupOptions($groups)) {
328334
return $result;
329335
}
@@ -506,4 +512,20 @@ private function warmCoverageCache(): void
506512

507513
$this->output->writeln('done [' . $timer->stop()->asString() . ']');
508514
}
515+
516+
/**
517+
* @see PHPUnit\Framework\TestCase::containsOnlyVirtualGroups
518+
*
519+
* @param string[] $groups
520+
*/
521+
private function containsOnlyVirtualGroups(array $groups): bool
522+
{
523+
foreach ($groups as $group) {
524+
if (strpos($group, '__phpunit_') !== 0) {
525+
return false;
526+
}
527+
}
528+
529+
return true;
530+
}
509531
}

test/Unit/Runners/PHPUnit/SuiteLoaderTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,14 @@ public function testTestMethodsFromErroringDataProviderReturnTheSimpleMethodToBe
378378
static::assertCount(3, $loader->getTestMethods());
379379
}
380380

381+
public function testUngroupedTestShouldHaveDefaultGroupAssigned(): void
382+
{
383+
$this->bareOptions['--path'] = $this->fixture('group_default');
384+
$this->bareOptions['--group'] = 'default';
385+
$loader = $this->loadSuite();
386+
static::assertCount(2, $loader->getTestMethods());
387+
}
388+
381389
/**
382390
* @return string[]
383391
*/
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ParaTest\Tests\fixtures\passing_tests;
6+
7+
use PHPUnit\Framework\TestCase;
8+
9+
final class GroupDefaultTest extends TestCase
10+
{
11+
public function testTruth(): void
12+
{
13+
$this->assertTrue(true);
14+
}
15+
16+
/**
17+
* @covers ParaTest\Tests\fixtures\passing_tests\GroupDefaultTest
18+
*/
19+
public function testTruthWithCovers(): void
20+
{
21+
$this->assertTrue(true);
22+
}
23+
24+
/**
25+
* @group group1
26+
*/
27+
public function testFalsehood(): void
28+
{
29+
$this->assertFalse(false);
30+
}
31+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ParaTest\Tests\fixtures\passing_tests;
6+
7+
use PHPUnit\Framework\TestCase;
8+
9+
/**
10+
* @group group1
11+
*/
12+
final class GroupNonDefaultTest extends TestCase
13+
{
14+
public function testTruth(): void
15+
{
16+
$this->assertTrue(true);
17+
}
18+
}

0 commit comments

Comments
 (0)