コード例 #1
0
 private function findStepNodes()
 {
     $scenarios = $this->featureNode->getScenarios();
     if (count($scenarios) === 0) {
         throw new \InvalidArgumentException('Unable to find any scenarios in dummy feature');
     }
     $scenario = $scenarios[0];
     $steps = $scenario->getSteps();
     if (count($steps) === 0) {
         throw new \InvalidArgumentException('Unable to find any steps in dummy feature');
     }
     $this->stepNodes = $steps;
 }
コード例 #2
0
 /**
  * @param FeatureNode $feature
  *
  * @return array
  */
 public function extract(FeatureNode $feature)
 {
     $allScenarios = [];
     foreach ($feature->getScenarios() as $scenario) {
         $scenarios = [];
         switch (true) {
             case $scenario instanceof OutlineNode && $this->isParallelExamples($scenario):
                 foreach ($scenario->getExamples() as $exampleNode) {
                     $scenarios[] = new ScenarioInfo($feature->getFile(), $exampleNode->getLine());
                 }
                 break;
             case $scenario instanceof OutlineNode:
             case $scenario instanceof ScenarioInterface:
                 $scenarios[] = new ScenarioInfo($feature->getFile(), $scenario->getLine());
         }
         if ($this->isParallelWait($scenario) || !$this->isParallel($scenario)) {
             $allScenarios[] = [];
         }
         $lastIndex = empty($allScenarios) ? 0 : count($allScenarios) - 1;
         if (!array_key_exists($lastIndex, $allScenarios)) {
             $allScenarios[$lastIndex] = [];
         }
         $allScenarios[$lastIndex] = array_merge($allScenarios[$lastIndex], $scenarios);
         if (!$this->isParallel($scenario)) {
             $allScenarios[] = [];
         }
     }
     return array_values(array_filter($allScenarios));
 }
コード例 #3
0
 public function testScenarios()
 {
     $feature = new FeatureNode();
     $this->assertEquals(0, count($feature->getScenarios()));
     $this->assertFalse($feature->hasScenarios());
     $feature->addScenario(new ScenarioNode());
     $this->assertEquals(1, count($feature->getScenarios()));
     $this->assertTrue($feature->hasScenarios());
     $feature->addScenario(new OutlineNode());
     $this->assertEquals(2, count($feature->getScenarios()));
     $this->assertTrue($feature->hasScenarios());
     $scenarios = $feature->getScenarios();
     $this->assertInstanceOf('Behat\\Gherkin\\Node\\ScenarioNode', $scenarios[0]);
     $this->assertSame($feature, $scenarios[0]->getFeature());
     $this->assertInstanceOf('Behat\\Gherkin\\Node\\OutlineNode', $scenarios[1]);
     $this->assertSame($feature, $scenarios[1]->getFeature());
 }
コード例 #4
0
 /**
  * Filters feature according to the filter.
  *
  * @param FeatureNode $feature
  */
 public function filterFeature(FeatureNode $feature)
 {
     $scenarios = $feature->getScenarios();
     foreach ($scenarios as $i => $scenario) {
         if (!$this->isScenarioMatch($scenario)) {
             unset($scenarios[$i]);
         }
     }
     $feature->setScenarios($scenarios);
 }
コード例 #5
0
ファイル: ComplexFilter.php プロジェクト: higrow/Gherkin
 /**
  * Filters feature according to the filter.
  *
  * @param FeatureNode $feature
  *
  * @return FeatureNode
  */
 public function filterFeature(FeatureNode $feature)
 {
     $scenarios = array();
     foreach ($feature->getScenarios() as $scenario) {
         if (!$this->isScenarioMatch($feature, $scenario)) {
             continue;
         }
         $scenarios[] = $scenario;
     }
     return new FeatureNode($feature->getTitle(), $feature->getDescription(), $feature->getTags(), $feature->getBackground(), $scenarios, $feature->getKeyword(), $feature->getLanguage(), $feature->getFile(), $feature->getLine());
 }
コード例 #6
0
 /**
  * Filters feature according to the filter.
  *
  * @param FeatureNode $feature
  */
 public function filterFeature(FeatureNode $feature)
 {
     $scenarios = $feature->getScenarios();
     foreach ($scenarios as $i => $scenario) {
         if (!$this->isScenarioMatch($scenario)) {
             unset($scenarios[$i]);
             continue;
         }
         if ($scenario instanceof OutlineNode && $scenario->hasExamples()) {
             $lines = $scenario->getExamples()->getRowLines();
             $rows = $scenario->getExamples()->getNumeratedRows();
             if (current($lines) <= $this->filterLine && end($lines) >= $this->filterLine) {
                 $scenario->getExamples()->setRows(array());
                 $scenario->getExamples()->addRow($rows[$lines[0]], $lines[0]);
                 if ($lines[0] !== $this->filterLine) {
                     $scenario->getExamples()->addRow($rows[$this->filterLine], $this->filterLine);
                 }
             }
         }
     }
     $feature->setScenarios($scenarios);
 }
コード例 #7
0
ファイル: LineFilter.php プロジェクト: higrow/Gherkin
 /**
  * Filters feature according to the filter and returns new one.
  *
  * @param FeatureNode $feature
  *
  * @return FeatureNode
  */
 public function filterFeature(FeatureNode $feature)
 {
     $scenarios = array();
     foreach ($feature->getScenarios() as $scenario) {
         if (!$this->isScenarioMatch($scenario)) {
             continue;
         }
         if ($scenario instanceof OutlineNode && $scenario->hasExamples()) {
             $table = $scenario->getExampleTable()->getTable();
             $lines = array_keys($table);
             if (in_array($this->filterLine, $lines)) {
                 $filteredTable = array($lines[0] => $table[$lines[0]]);
                 if ($lines[0] !== $this->filterLine) {
                     $filteredTable[$this->filterLine] = $table[$this->filterLine];
                 }
                 $scenario = new OutlineNode($scenario->getTitle(), $scenario->getTags(), $scenario->getSteps(), new ExampleTableNode($filteredTable, $scenario->getExampleTable()->getKeyword()), $scenario->getKeyword(), $scenario->getLine());
             }
         }
         $scenarios[] = $scenario;
     }
     return new FeatureNode($feature->getTitle(), $feature->getDescription(), $feature->getTags(), $feature->getBackground(), $scenarios, $feature->getKeyword(), $feature->getLanguage(), $feature->getFile(), $feature->getLine());
 }
コード例 #8
0
 /**
  * Dumps feature.
  *
  * @param FeatureNode $feature Feature instance
  *
  * @return string
  */
 public function dumpFeature(FeatureNode $feature)
 {
     $language = $feature->getLanguage();
     $this->keywords->setLanguage($language);
     $content = '' . $this->dumpLanguage($language) . ($feature->getTags() ? PHP_EOL . $this->dumpTags($feature->getTags(), 0) : '') . PHP_EOL . $this->dumpKeyword($this->keywords->getFeatureKeywords(), $feature->getTitle(), 0) . PHP_EOL . $this->dumpText($feature->getDescription(), 1);
     if ($feature->getBackground()) {
         $content .= $this->dumpBackground($feature->getBackground());
     }
     $scenarios = $feature->getScenarios();
     foreach ($scenarios as $scenario) {
         $content .= PHP_EOL . $this->dumpScenario($scenario);
     }
     return $content;
 }
 /**
  * @param FeatureNode $featureNode
  * @param StepNode $stepNode
  * @return ScenarioInterface|null
  */
 private function detectScenario(FeatureNode $featureNode, StepNode $stepNode)
 {
     foreach ($featureNode->getScenarios() as $scenario) {
         foreach ($scenario->getSteps() as $step) {
             if ($step->getLine() === $stepNode->getLine() && $step->getText() === $stepNode->getText()) {
                 return $scenario;
             }
         }
     }
     return null;
 }
コード例 #10
0
ファイル: Gherkin.php プロジェクト: charlycoste/BDDWizard
 public function getScenarios()
 {
     return $this->featureNode->getScenarios();
 }