コード例 #1
0
ファイル: OutlineTester.php プロジェクト: kingsj/core
 /**
  * Visits & tests OutlineNode example.
  *
  * @param   Behat\Gherkin\Node\OutlineNode  $outline
  * @param   integer                         $row        row number
  * @param   array                           $tokens     step replacements for tokens
  *
  * @return  integer
  */
 private function visitOutlineExample(OutlineNode $outline, $row, array $tokens = array())
 {
     $context = $this->container->get('behat.context_dispatcher')->createContext();
     $itResult = 0;
     $skip = false;
     $this->dispatcher->dispatch('beforeOutlineExample', new OutlineExampleEvent($outline, $row, $context));
     // Visit & test background if has one
     if ($outline->getFeature()->hasBackground()) {
         $bgResult = $this->visitBackground($outline->getFeature()->getBackground(), $context);
         if (0 !== $bgResult) {
             $skip = true;
         }
         $itResult = max($itResult, $bgResult);
     }
     // Visit & test steps
     foreach ($outline->getSteps() as $step) {
         $stResult = $this->visitStep($step, $context, $tokens, $skip, true);
         if (0 !== $stResult) {
             $skip = true;
         }
         $itResult = max($itResult, $stResult);
     }
     $this->dispatcher->dispatch('afterOutlineExample', new OutlineExampleEvent($outline, $row, $context, $itResult, $skip));
     return $itResult;
 }
コード例 #2
0
 public function testSteps()
 {
     $outline = new OutlineNode();
     $this->assertEquals(0, count($outline->getSteps()));
     $this->assertFalse($outline->hasSteps());
     $outline->addStep(new StepNode('Given', 'Something'));
     $this->assertEquals(1, count($outline->getSteps()));
     $this->assertTrue($outline->hasSteps());
     $outline->addStep(new StepNode('Then', 'Do'));
     $this->assertEquals(2, count($outline->getSteps()));
     $this->assertTrue($outline->hasSteps());
     $steps = $outline->getSteps();
     $this->assertInstanceOf('Behat\\Gherkin\\Node\\StepNode', $steps[0]);
     $this->assertEquals('Given', $steps[0]->getType());
     $this->assertEquals('Something', $steps[0]->getText());
     $this->assertSame($outline, $steps[0]->getParent());
     $this->assertEquals('Then', $steps[1]->getType());
     $this->assertEquals('Do', $steps[1]->getText());
     $this->assertSame($outline, $steps[1]->getParent());
 }
コード例 #3
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());
 }
コード例 #4
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);
     };
 }