Exemplo n.º 1
0
 public function testParent()
 {
     $step = new StepNode('Given');
     $this->assertNull($step->getParent());
     $step->setParent($scenario = new ScenarioNode());
     $this->assertSame($scenario, $step->getParent());
 }
 /**
  * Executes steps chain (if there's one).
  *
  * Added code to trigger the BeforeStep and AfterStep hooks.
  *
  * @param StepNode $step  step node
  * @param mixed    $chain chain
  *
  * @throws \Exception
  */
 protected function executeStepsChain(StepNode $step, $chain = null)
 {
     if (null === $chain) {
         return;
     }
     $chain = is_array($chain) ? $chain : array($chain);
     foreach ($chain as $chainItem) {
         if ($chainItem instanceof SubstepInterface) {
             $substepNode = $chainItem->getStepNode();
             $substepNode->setParent($step->getParent());
             $this->dispatcher->dispatch('beforeStep', new StepEvent($substepNode, $this->logicalParent, $this->context));
             $substepEvent = $this->executeStep($substepNode);
             if (StepEvent::PASSED !== $substepEvent->getResult()) {
                 throw $substepEvent->getException();
             }
             if ($substepEvent->getLogicalParent()->getKeyword() != 'Scenario Outline') {
                 $this->dispatcher->dispatch('afterStep', $substepEvent);
             }
         } elseif (is_callable($chainItem)) {
             $this->executeStepsChain($step, call_user_func($chainItem));
         }
     }
 }
Exemplo n.º 3
0
 /**
  * Prints path to step.
  *
  * @param   Behat\Gherkin\Node\StepNode         $step           step node
  * @param   Behat\Behat\Definition\Definition   $definition     definition (if step defined)
  * @param   Exception                           $exception      exception (if step failed)
  */
 protected function printStepPath(StepNode $step, Definition $definition = null, \Exception $exception = null)
 {
     $color = $exception instanceof Pending ? 'pending' : 'failed';
     $type = $step->getType();
     $text = $step->getText();
     $stepPath = "In step `{$type} {$text}'.";
     $stepPathLn = mb_strlen($stepPath);
     $node = $step->getParent();
     if ($node instanceof BackgroundNode) {
         $scenarioPath = "From scenario background.";
     } else {
         $title = $node->getTitle();
         $title = $title ? "`{$title}'" : '***';
         $scenarioPath = "From scenario {$title}.";
     }
     $scenarioPathLn = mb_strlen($scenarioPath);
     $this->maxLineLength = max($this->maxLineLength, $stepPathLn);
     $this->maxLineLength = max($this->maxLineLength, $scenarioPathLn);
     $this->write("    {+{$color}}{$stepPath}{-{$color}}");
     if (null !== $definition) {
         $indentCount = $this->maxLineLength - $stepPathLn;
         $this->printPathComment($definition->getFile(), $definition->getLine(), $indentCount);
     } else {
         $this->writeln();
     }
     $this->write("    {+{$color}}{$scenarioPath}{-{$color}}");
     $indentCount = $this->maxLineLength - $scenarioPathLn;
     $this->printPathComment($node->getFile(), $node->getLine(), $indentCount);
     $this->writeln();
 }
 /**
  * Executes steps chain (if there's one).
  *
  * Overwriten method to run behat hooks between chain steps.
  *
  * @param StepNode $step  step node
  * @param mixed    $chain chain
  *
  * @throws \Exception
  */
 private function executeStepsChainWithHooks(StepNode $step, $chain = null)
 {
     if (null === $chain) {
         // If there are no more chained steps below we will dispatch the
         // after step event, skipping the step that looks for exceptions here.
         if (strstr($step->getText(), self::EXCEPTIONS_STEP_TEXT) === false) {
             $this->dispatchafterstep = true;
         }
         return;
     }
     $chain = is_array($chain) ? $chain : array($chain);
     foreach ($chain as $chainItem) {
         if ($chainItem instanceof SubstepInterface) {
             $substepNode = $chainItem->getStepNode();
             $substepNode->setParent($step->getParent());
             // Replace by tokens when needed.
             if ($substepNode->getParent() instanceof OutlineNode) {
                 $substepNode = $substepNode->createExampleRowStep($this->tokens);
             }
             $this->dispatchafterstep = false;
             // Dispatch beforeStep event.
             $this->moodledispatcher->dispatch('beforeStep', new StepEvent($substepNode, $this->moodlelogicalParent, $this->moodlecontext));
             $substepEvent = $this->executeStep($substepNode);
             // Dispatch afterStep event.
             if ($this->dispatchafterstep === true) {
                 $this->moodledispatcher->dispatch('afterStep', $substepEvent);
                 $this->dispatchafterstep = false;
             }
             // Here we mark the step as failed so parent steps in the chain
             // will not continue dispatching the afterStep event.
             if (StepEvent::PASSED !== $substepEvent->getResult()) {
                 $this->failedstep = true;
                 throw $substepEvent->getException();
             }
         } elseif (is_callable($chainItem)) {
             $this->executeStepsChainWithHooks($step, call_user_func($chainItem));
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Executes steps chain (if there's one).
  *
  * @param StepNode $step  step node
  * @param mixed    $chain chain
  *
  * @throws \Exception
  */
 private function executeStepsChain(StepNode $step, $chain = null)
 {
     if (null === $chain) {
         return;
     }
     $chain = is_array($chain) ? $chain : array($chain);
     foreach ($chain as $chainItem) {
         if ($chainItem instanceof SubstepInterface) {
             $substepNode = $chainItem->getStepNode();
             $substepNode->setParent($step->getParent());
             $substepEvent = $this->executeStep($substepNode);
             if (StepEvent::PASSED !== $substepEvent->getResult()) {
                 throw $substepEvent->getException();
             }
         } elseif (is_callable($chainItem)) {
             $this->executeStepsChain($step, call_user_func($chainItem));
         }
     }
 }