Last active
March 1, 2017 16:24
-
-
Save naxhh/e85bd52715e856b73e1d to your computer and use it in GitHub Desktop.
Behat Scenario parser
This file contains 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
<?php | |
require __DIR__ . '/vendor/autoload.php'; | |
$features_path = __DIR__ . 'test/Behat/'; | |
$project = 'project'; | |
$keywords = new Behat\Gherkin\Keywords\CachedArrayKeywords( __DIR__ . '/vendor/behat/gherkin/i18n.php' ); | |
$lexer = new Behat\Gherkin\Lexer($keywords); | |
$parser = new Behat\Gherkin\Parser($lexer); | |
$gherkin = new Behat\Gherkin\Gherkin(); | |
$gherkin->addLoader(new Behat\Gherkin\Loader\DirectoryLoader($gherkin)); | |
$gherkin->addLoader(new Behat\Gherkin\Loader\GherkinFileLoader($parser)); | |
$gherkin->setBasePath( $features_path ); | |
try | |
{ | |
/** | |
* @var FeatureNode[] | |
* | |
* @see https://github.com/Behat/Gherkin/blob/2.3/src/Behat/Gherkin/Node/FeatureNode.php | |
*/ | |
$features = $gherkin->load( $project ); // all features in provided directory | |
} catch( \InvalidArgumentException $e ) | |
{ | |
throw new InvalidArgumentException( 'Seems the project "'. $project .'" does not exist!' ); | |
} | |
foreach ( $features as $feature ) { | |
printnl( $feature->getTitle() ); | |
runButton( $feature->getFile(), $project, $feature->getTitle() ) | |
if ( $description = $feature->getDescription() ) { | |
printnl( $description ); | |
} | |
foreach( $feature->getScenarios() as $scenario ) { | |
printnl( $scenario->getTitle() ); | |
foreach ($scenario->getSteps() as $step ) { | |
printnl( $step->getText() ); | |
foreach ($step->getArguments() as $argument ) { | |
if ( $argument instanceof Behat\Gherkin\Node\PyStringNode ) { | |
foreach ($argument->getLines() as $line ) { | |
printnl( $line ); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment