Skip to content

Commit

Permalink
Merge pull request #6302 from Codeception/fix-wildcard-group-match
Browse files Browse the repository at this point in the history
Fixed wildcard matching of group files
  • Loading branch information
Naktibalda committed Dec 22, 2021
2 parents 8ebbb00 + 36f3259 commit c873087
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/Codeception/Lib/GroupManager.php
Expand Up @@ -56,14 +56,15 @@ protected function loadGroupsByPattern()
->sortByName()
->in($path);

$i = 1;


foreach ($files as $file) {
/** @var SplFileInfo $file * */
$this->configuredGroups[str_replace('*', $i, $group)] = dirname($pattern).DIRECTORY_SEPARATOR.$file->getRelativePathname();
$i++;
$prefix = str_replace('*', '', $group);
$pathPrefix = str_replace('*', '', basename($pattern));
$groupName = $prefix . str_replace($pathPrefix, '', $file->getRelativePathname());

$this->configuredGroups[$groupName] = dirname($pattern) . DIRECTORY_SEPARATOR . $file->getRelativePathname();
}

unset($this->configuredGroups[$group]);
}
}
Expand Down
1 change: 1 addition & 0 deletions tests/data/group_manager_test/group_chunk_1_1
@@ -0,0 +1 @@
tests/data/group_manager_test/UserTest.php
1 change: 1 addition & 0 deletions tests/data/group_manager_test/group_chunk_1_2
@@ -0,0 +1 @@
tests/data/group_manager_test/PostTest.php
12 changes: 12 additions & 0 deletions tests/unit/Codeception/Lib/GroupManagerTest.php
Expand Up @@ -76,11 +76,23 @@ public function testGroupsByPattern()
$this->assertContains('group_2', $this->manager->groupsForTest($test2));
}


public function testGroupsByPatternWithMultipleDigits()
{
$this->manager = new GroupManager(['group_chunk_*' => 'tests/data/group_manager_test/group_chunk_*']);
$test1 = $this->makeTestCase('tests/data/group_manager_test/UserTest.php');
$test2 = $this->makeTestCase('tests/data/group_manager_test/PostTest.php');

$this->assertContains('group_chunk_1_1', $this->manager->groupsForTest($test1));
$this->assertContains('group_chunk_1_2', $this->manager->groupsForTest($test2));
}

public function testGroupsByDifferentPattern()
{
$this->manager = new GroupManager(['g_*' => 'tests/data/group_manager_test/group_*']);
$test1 = $this->makeTestCase('tests/data/group_manager_test/UserTest.php');
$test2 = $this->makeTestCase('tests/data/group_manager_test/PostTest.php');

$this->assertContains('g_1', $this->manager->groupsForTest($test1));
$this->assertContains('g_2', $this->manager->groupsForTest($test2));
}
Expand Down

0 comments on commit c873087

Please sign in to comment.