-
-
Notifications
You must be signed in to change notification settings - Fork 95
Compatibility layer for cucumber/gherkin
#253
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
Open
ciaranmcnulty
wants to merge
11
commits into
Behat:master
Choose a base branch
from
ciaranmcnulty:cucumber-gherkin
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5eff5fd
Alternative Loader that uses the cucumber/gherkin parser
ciaranmcnulty 45b6bea
Configure CI to run cucumber tests
ciaranmcnulty 2c3211b
Test cucumber compatibility layer against behat etalons (+ fixes)
ciaranmcnulty 8d4736d
Method so behat can detect whether the new parser is available
ciaranmcnulty fda7a22
Add support for Rules
ciaranmcnulty 07573f4
conflict with incompatible version
ciaranmcnulty 69a9e8b
Add caching
ciaranmcnulty 77fb8ef
Make cache dependency private
ciaranmcnulty 237fb42
Remove test data
ciaranmcnulty 498c802
Try adding prefer-lowest jobs
ciaranmcnulty 3ac5fb1
Bump the required versions of PHPUnit and Yaml
ciaranmcnulty File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <?php declare(strict_types=1); | ||
|
|
||
| namespace Behat\Gherkin\Cucumber; | ||
|
|
||
| use Cucumber\Messages\Location; | ||
|
|
||
| final class MultilineStringFormatter | ||
| { | ||
| public static function format(string $string, Location $keywordLocation = null): string | ||
| { | ||
| if (!$keywordLocation) { | ||
| $keywordLocation = new Location(0,1); | ||
| } | ||
|
|
||
| $maxIndent = ($keywordLocation->column-1 ?: 0) + 2; | ||
|
|
||
| return preg_replace( | ||
| ["/^[^\n\S]{0,$maxIndent}/um", '/[^\n\S]+$/um'], | ||
| ['', ''], | ||
| $string | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| Feature: | ||
|
|
||
| this is a description with some important points | ||
|
|
||
| this is another paragraph in the same description | ||
|
|
||
| Scenario: | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <?php | ||
|
|
||
| namespace Tests\Behat\Gherkin\Acceptance; | ||
|
|
||
| use Behat\Gherkin\Loader\YamlFileLoader; | ||
| use Behat\Gherkin\Node\FeatureNode; | ||
|
|
||
| trait CompatibilityTestTrait | ||
| { | ||
| private $yaml; | ||
|
|
||
| abstract protected function parseFeature($featureFile) : FeatureNode; | ||
|
|
||
| /** | ||
| * @dataProvider etalonsProvider | ||
| */ | ||
| public function testItParsesTheBehatEtalons($yamlFile, $featureFile) | ||
| { | ||
| $fixture = $this->getYamlParser()->load($yamlFile)[0]; | ||
| $feature = $this->parseFeature($featureFile); | ||
|
|
||
| $this->compare($fixture, $feature); | ||
| } | ||
|
|
||
| public function etalonsProvider() | ||
| { | ||
| foreach (glob(__DIR__ . '/../Fixtures/etalons/*.yml') as $file) { | ||
| $testname = basename($file, '.yml'); | ||
|
|
||
| if (!in_array($testname, $this->etalons_skip)) { | ||
| yield $testname => [$file, __DIR__ . '/../Fixtures/features/'.$testname.'.feature']; | ||
| } | ||
|
|
||
| } | ||
| } | ||
|
|
||
| protected function getYamlParser() | ||
| { | ||
| if (null === $this->yaml) { | ||
| $this->yaml = new YamlFileLoader(); | ||
| } | ||
|
|
||
| return $this->yaml; | ||
| } | ||
|
|
||
| private function compare(FeatureNode $fixture, ?FeatureNode $feature): void | ||
| { | ||
| $rc = new \ReflectionClass(FeatureNode::class); | ||
| $rp = $rc->getProperty('file'); | ||
| $rp->setAccessible(true); | ||
| $rp->setValue($fixture, null); | ||
| $rp->setValue($feature, null); | ||
|
|
||
| $this->assertEquals($fixture, $feature); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| <?php declare(strict_types=1); | ||
|
|
||
| namespace Tests\Behat\Gherkin\Acceptance; | ||
|
|
||
| use Behat\Gherkin\Loader\CucumberGherkinLoader; | ||
| use Behat\Gherkin\Node\FeatureNode; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| /** @group cucumber */ | ||
| final class CucumberParserTest extends TestCase | ||
| { | ||
| protected $etalons_skip = [ | ||
| 'comments', # see https://github.com/cucumber/common/issues/1413 | ||
| 'multiline_name_with_newlines', # cucumber does not preserve leading newlines in description blocks | ||
| ]; | ||
|
|
||
| public function setUp() : void | ||
| { | ||
| $this->loader = new CucumberGherkinLoader(); | ||
| } | ||
|
|
||
| use CompatibilityTestTrait; | ||
|
|
||
| protected function parseFeature($featureFile): FeatureNode | ||
| { | ||
| return $this->loader->load($featureFile)[0]; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| <?php | ||
|
|
||
| namespace Tests\Behat\Gherkin\Acceptance; | ||
|
|
||
| use Behat\Gherkin\Keywords\ArrayKeywords; | ||
| use Behat\Gherkin\Lexer; | ||
| use Behat\Gherkin\Node\FeatureNode; | ||
| use Behat\Gherkin\Parser; | ||
| use PHPUnit\Framework\TestCase; | ||
|
|
||
| final class LegacyParserTest extends TestCase | ||
| { | ||
| private $gherkin; | ||
| protected $etalons_skip = []; | ||
|
|
||
| use CompatibilityTestTrait; | ||
|
|
||
| protected function parseFeature($featureFile) : FeatureNode | ||
| { | ||
| return $this->getGherkinParser()->parse(file_get_contents($featureFile), $featureFile); | ||
| } | ||
|
|
||
| protected function getGherkinParser() | ||
| { | ||
| if (null === $this->gherkin) { | ||
| $keywords = new ArrayKeywords(array( | ||
| 'en' => array( | ||
| 'feature' => 'Feature', | ||
| 'background' => 'Background', | ||
| 'scenario' => 'Scenario', | ||
| 'scenario_outline' => 'Scenario Outline', | ||
| 'examples' => 'Examples', | ||
| 'given' => 'Given', | ||
| 'when' => 'When', | ||
| 'then' => 'Then', | ||
| 'and' => 'And', | ||
| 'but' => 'But' | ||
| ), | ||
| 'ru' => array( | ||
| 'feature' => 'Функционал', | ||
| 'background' => 'Предыстория', | ||
| 'scenario' => 'Сценарий', | ||
| 'scenario_outline' => 'Структура сценария', | ||
| 'examples' => 'Примеры', | ||
| 'given' => 'Допустим', | ||
| 'when' => 'Если', | ||
| 'then' => 'То', | ||
| 'and' => 'И', | ||
| 'but' => 'Но' | ||
| ), | ||
| 'ja' => array ( | ||
| 'feature' => 'フィーチャ', | ||
| 'background' => '背景', | ||
| 'scenario' => 'シナリオ', | ||
| 'scenario_outline' => 'シナリオアウトライン', | ||
| 'examples' => '例|サンプル', | ||
| 'given' => '前提<', | ||
| 'when' => 'もし<', | ||
| 'then' => 'ならば<', | ||
| 'and' => 'かつ<', | ||
| 'but' => 'しかし<' | ||
| ) | ||
| )); | ||
| $this->gherkin = new Parser(new Lexer($keywords)); | ||
| } | ||
|
|
||
| return $this->gherkin; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.