From dcfebaf6930d7c5ded787d195a86c544cb8bede7 Mon Sep 17 00:00:00 2001 From: Phil Manser Date: Fri, 29 Mar 2019 16:08:13 -0400 Subject: [PATCH 1/4] proposed solution for #5457 gherkin scenarios not loaded from group file --- src/Codeception/Lib/GroupManager.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Codeception/Lib/GroupManager.php b/src/Codeception/Lib/GroupManager.php index c796033bac..c14a13ff76 100644 --- a/src/Codeception/Lib/GroupManager.php +++ b/src/Codeception/Lib/GroupManager.php @@ -118,6 +118,10 @@ public function groupsForTest(\PHPUnit\Framework\Test $test) if (strpos($filename . ':' . $test->getName(false), $testPattern) === 0) { $groups[] = $group; } + // TODO: consider mb_strtolower per https://stackoverflow.com/a/5473569 + if (strcasecmp($filename . ':' . $test->getMetadata()->getFeature(), $testPattern) === 0) { + $groups[] = $group; + } if ($test instanceof \PHPUnit\Framework\TestSuite\DataProvider) { $firstTest = $test->testAt(0); if ($firstTest != false && $firstTest instanceof TestInterface) { From 826b49b57bbb2c49daf35a63cf038eb66f913381 Mon Sep 17 00:00:00 2001 From: Phil Manser Date: Fri, 29 Mar 2019 17:22:25 -0400 Subject: [PATCH 2/4] testing for getMetaData method before calling it in GroupManager --- src/Codeception/Lib/GroupManager.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Codeception/Lib/GroupManager.php b/src/Codeception/Lib/GroupManager.php index c14a13ff76..4dfea6c1e9 100644 --- a/src/Codeception/Lib/GroupManager.php +++ b/src/Codeception/Lib/GroupManager.php @@ -119,7 +119,10 @@ public function groupsForTest(\PHPUnit\Framework\Test $test) $groups[] = $group; } // TODO: consider mb_strtolower per https://stackoverflow.com/a/5473569 - if (strcasecmp($filename . ':' . $test->getMetadata()->getFeature(), $testPattern) === 0) { + if ( + method_exists($test, 'getMetadata') + && strcasecmp($filename . ':' . $test->getMetadata()->getFeature(), $testPattern) === 0 + ) { $groups[] = $group; } if ($test instanceof \PHPUnit\Framework\TestSuite\DataProvider) { From 8e950a6e491180ed1068dd541a83518422313187 Mon Sep 17 00:00:00 2001 From: Phil Manser Date: Sat, 30 Mar 2019 19:30:53 -0400 Subject: [PATCH 3/4] reformatting if statement to appease nitpick --- src/Codeception/Lib/GroupManager.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Codeception/Lib/GroupManager.php b/src/Codeception/Lib/GroupManager.php index 4dfea6c1e9..7606c3f727 100644 --- a/src/Codeception/Lib/GroupManager.php +++ b/src/Codeception/Lib/GroupManager.php @@ -119,8 +119,7 @@ public function groupsForTest(\PHPUnit\Framework\Test $test) $groups[] = $group; } // TODO: consider mb_strtolower per https://stackoverflow.com/a/5473569 - if ( - method_exists($test, 'getMetadata') + if (method_exists($test, 'getMetadata') && strcasecmp($filename . ':' . $test->getMetadata()->getFeature(), $testPattern) === 0 ) { $groups[] = $group; From fa0eff4b01481d191bc5ac9e5c430bf424d2075e Mon Sep 17 00:00:00 2001 From: Phil Manser Date: Mon, 1 Apr 2019 22:22:54 -0400 Subject: [PATCH 4/4] adding tests for #5457 --- src/Codeception/Lib/GroupManager.php | 7 +++---- tests/data/gherkinGroup1 | 1 + tests/data/gherkinGroup2 | 1 + tests/data/refund2.feature | 10 ++++++++++ .../unit/Codeception/Lib/GroupManagerTest.php | 19 +++++++++++++++++++ 5 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 tests/data/gherkinGroup1 create mode 100644 tests/data/gherkinGroup2 create mode 100644 tests/data/refund2.feature diff --git a/src/Codeception/Lib/GroupManager.php b/src/Codeception/Lib/GroupManager.php index 7606c3f727..1eb2c5a545 100644 --- a/src/Codeception/Lib/GroupManager.php +++ b/src/Codeception/Lib/GroupManager.php @@ -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; @@ -118,10 +119,8 @@ public function groupsForTest(\PHPUnit\Framework\Test $test) if (strpos($filename . ':' . $test->getName(false), $testPattern) === 0) { $groups[] = $group; } - // TODO: consider mb_strtolower per https://stackoverflow.com/a/5473569 - if (method_exists($test, 'getMetadata') - && strcasecmp($filename . ':' . $test->getMetadata()->getFeature(), $testPattern) === 0 - ) { + if ($test instanceof Gherkin + && mb_strtolower($filename . ':' . $test->getMetadata()->getFeature()) === mb_strtolower($testPattern)) { $groups[] = $group; } if ($test instanceof \PHPUnit\Framework\TestSuite\DataProvider) { diff --git a/tests/data/gherkinGroup1 b/tests/data/gherkinGroup1 new file mode 100644 index 0000000000..e92fe6e789 --- /dev/null +++ b/tests/data/gherkinGroup1 @@ -0,0 +1 @@ +tests/data/refund.feature:Jeff returns a faulty microwave \ No newline at end of file diff --git a/tests/data/gherkinGroup2 b/tests/data/gherkinGroup2 new file mode 100644 index 0000000000..537815f703 --- /dev/null +++ b/tests/data/gherkinGroup2 @@ -0,0 +1 @@ +tests/data/refund2.feature:ジェフは不完全な電子レンジを返します \ No newline at end of file diff --git a/tests/data/refund2.feature b/tests/data/refund2.feature new file mode 100644 index 0000000000..4fe179b5a4 --- /dev/null +++ b/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 diff --git a/tests/unit/Codeception/Lib/GroupManagerTest.php b/tests/unit/Codeception/Lib/GroupManagerTest.php index 7d67a2f6e4..729b02f788 100644 --- a/tests/unit/Codeception/Lib/GroupManagerTest.php +++ b/tests/unit/Codeception/Lib/GroupManagerTest.php @@ -2,6 +2,7 @@ namespace Codeception\Lib; use Codeception\Util\Stub; +use Codeception\Test\Loader\Gherkin as GherkinLoader; class GroupManagerTest extends \Codeception\Test\Unit { @@ -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(