Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed solution for #5457 gherkin scenarios not loaded from group file #5458

Merged
merged 4 commits into from Apr 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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