コード例 #1
0
ファイル: Example.php プロジェクト: malukenho/kawaii-gherkin
 /**
  * @param OutlineNode $scenario
  *
  * @return string
  */
 public function format(OutlineNode $scenario)
 {
     if (!$scenario->hasExamples()) {
         return;
     }
     // TODO: refactor this part
     return implode(array_merge([$this->indent(self::INDENTATION * 2) . rtrim($scenario->getExampleTable()->getKeyword()) . ":\n"], array_map(function ($arguments) {
         return $this->indent(self::INDENTATION * 2 + 2) . trim($arguments) . "\n";
     }, explode("\n", $scenario->getExampleTable()->getTableAsString()))));
 }
コード例 #2
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());
 }
コード例 #3
0
 /**
  * Creates wrapper-closure for the example table.
  *
  * @param OutlineNode   $outline
  * @param ExampleNode   $example
  * @param AfterStepTested[] $stepEvents
  *
  * @return callable
  */
 private function getWrapperClosure(OutlineNode $outline, ExampleNode $example, array $stepEvents)
 {
     $resultConverter = $this->resultConverter;
     return function ($value, $column) use($outline, $example, $stepEvents, $resultConverter) {
         $results = array();
         foreach ($stepEvents as $event) {
             $index = array_search($event->getStep(), $example->getSteps());
             $header = $outline->getExampleTable()->getRow(0);
             $steps = $outline->getSteps();
             $outlineStepText = $steps[$index]->getText();
             if (false !== strpos($outlineStepText, '<' . $header[$column] . '>')) {
                 $results[] = $event->getTestResult();
             }
         }
         $result = new TestResults($results);
         $style = $resultConverter->convertResultToString($result);
         return sprintf('{+%s}%s{-%s}', $style, $value, $style);
     };
 }