Skip to content

Commit

Permalink
Proposed solution for #5457 gherkin scenarios not loaded from group f…
Browse files Browse the repository at this point in the history
…ile (#5458)

* proposed solution for #5457 gherkin scenarios not loaded from group file

* testing for getMetaData method before calling it in GroupManager

* reformatting if statement to appease nitpick

* adding tests for #5457
  • Loading branch information
mozillalives authored and DavertMik committed Apr 5, 2019
1 parent 547a64c commit 119bac0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Codeception/Lib/GroupManager.php
Expand Up @@ -5,6 +5,7 @@
use Codeception\Test\Interfaces\Reported;
use Codeception\Test\Descriptor;
use Codeception\TestInterface;
use Codeception\Test\Gherkin;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;

Expand Down Expand Up @@ -118,6 +119,10 @@ public function groupsForTest(\PHPUnit\Framework\Test $test)
if (strpos($filename . ':' . $test->getName(false), $testPattern) === 0) {
$groups[] = $group;
}
if ($test instanceof Gherkin
&& mb_strtolower($filename . ':' . $test->getMetadata()->getFeature()) === mb_strtolower($testPattern)) {
$groups[] = $group;
}
if ($test instanceof \PHPUnit\Framework\TestSuite\DataProvider) {
$firstTest = $test->testAt(0);
if ($firstTest != false && $firstTest instanceof TestInterface) {
Expand Down
1 change: 1 addition & 0 deletions tests/data/gherkinGroup1
@@ -0,0 +1 @@
tests/data/refund.feature:Jeff returns a faulty microwave
1 change: 1 addition & 0 deletions tests/data/gherkinGroup2
@@ -0,0 +1 @@
tests/data/refund2.feature:ジェフは不完全な電子レンジを返します
10 changes: 10 additions & 0 deletions tests/data/refund2.feature
@@ -0,0 +1,10 @@
@important
Feature: Refund item
In order to get satisfaction
As a customer
I need to be able to get refunds

Scenario: ジェフは不完全な電子レンジを返します
Given Jeff has bought a microwave for "$100"
When he returns the microwave
Then Jeff should be refunded $100
19 changes: 19 additions & 0 deletions tests/unit/Codeception/Lib/GroupManagerTest.php
Expand Up @@ -2,6 +2,7 @@
namespace Codeception\Lib;

use Codeception\Util\Stub;
use Codeception\Test\Loader\Gherkin as GherkinLoader;

class GroupManagerTest extends \Codeception\Test\Unit
{
Expand Down Expand Up @@ -75,6 +76,24 @@ public function testGroupsFileHandlesWhitespace()
$this->assertEmpty($this->manager->groupsForTest($badTest));
}

public function testLoadSpecificScenarioFromFile()
{
$this->manager = new GroupManager(['gherkinGroup1' => 'tests/data/gherkinGroup1']);
$loader = new GherkinLoader();
$loader->loadTests(codecept_absolute_path('tests/data/refund.feature'));
$test = $loader->getTests()[0];
$this->assertContains('gherkinGroup1', $this->manager->groupsForTest($test));
}

public function testLoadSpecificScenarioWithMultibyteStringFromFile()
{
$this->manager = new GroupManager(['gherkinGroup2' => 'tests/data/gherkinGroup2']);
$loader = new GherkinLoader();
$loader->loadTests(codecept_absolute_path('tests/data/refund2.feature'));
$test = $loader->getTests()[0];
$this->assertContains('gherkinGroup2', $this->manager->groupsForTest($test));
}

protected function makeTestCase($file, $name = '')
{
return Stub::make(
Expand Down

0 comments on commit 119bac0

Please sign in to comment.