/**
  * @param  FeatureNode  $featureNode
  * @param  ScenarioInterface $scenarioNode
  *
  * @return string
  */
 public function generateFileName(FeatureNode $featureNode, ScenarioInterface $scenarioNode)
 {
     $feature = $this->relativizePaths($featureNode->getFile());
     $line = $scenarioNode->getLine();
     $fileName = join('_', [$feature, $line]);
     return preg_replace('/[^A-Za-z0-9\\-]/', '_', mb_strtolower($fileName)) . '.png';
 }
示例#2
0
 /**
  * Checks if scenario or outline matches specified filter.
  *
  * @param ScenarioInterface $scenario Scenario or Outline node instance
  *
  * @return Boolean
  */
 public function isScenarioMatch(ScenarioInterface $scenario)
 {
     if ('/' === $this->filterString[0] && 1 === preg_match($this->filterString, $scenario->getTitle())) {
         return true;
     } elseif (false !== mb_strpos($scenario->getTitle(), $this->filterString, 0, 'utf8')) {
         return true;
     }
     return false;
 }
 public function resolve(ScenarioInterface $scenario)
 {
     $scenarioTags = $scenario->getTags();
     foreach ($this->extensionConfiguration['behat_tags'] as $tagConfiguration) {
         if ($this->isConfigurationMatchToTags($tagConfiguration, $scenarioTags)) {
             return $this->createConfiguration($tagConfiguration);
         }
     }
     return null;
 }
示例#4
0
 /**
  * update scenario results based on step tests results
  * @param  FeatureNode       $feature    object
  * @param  ScenarioInterface $scenario   object
  * @param  TestResult        $testResult object
  * @return null
  */
 public function updateScenarioStatus(FeatureNode $feature, ScenarioInterface $scenario, TestResult $testResult)
 {
     $featurePath = $feature->getFile();
     $scenarioLine = $scenario->getLine();
     $resultCode = $testResult->getResultCode();
     if ($resultCode > $this->testResults[$featurePath]["scenarios"][$scenarioLine]["testResultCode"]) {
         $this->testResults[$featurePath]["scenarios"][$scenarioLine]["testResultCode"] = $resultCode;
         $this->testResults[$featurePath]["scenarios"][$scenarioLine]["testResult"] = self::RESULT_CODES_MAPPING[$resultCode];
     }
 }
示例#5
0
 /**
  * Checks if scenario or outline matches specified filter.
  *
  * @param ScenarioInterface $scenario Scenario or Outline node instance
  *
  * @return Boolean
  */
 public function isScenarioMatch(ScenarioInterface $scenario)
 {
     if ($this->filterLine === $scenario->getLine()) {
         return true;
     }
     if ($scenario instanceof OutlineNode && $scenario->hasExamples()) {
         return $this->filterLine === $scenario->getLine() || in_array($this->filterLine, $scenario->getExampleTable()->getLines());
     }
     return false;
 }
示例#6
0
 public function __construct(FeatureNode $featureNode, ScenarioInterface $scenarioNode, $steps = [])
 {
     $this->featureNode = $featureNode;
     $this->scenarioNode = $scenarioNode;
     $this->steps = $steps;
     $this->setMetadata(new Metadata());
     $this->scenario = new Scenario($this);
     $this->getMetadata()->setName($featureNode->getTitle());
     $this->getMetadata()->setFeature($scenarioNode->getTitle());
     $this->getMetadata()->setFilename($featureNode->getFile());
 }
 public function createFilename(FeatureNode $feature, ScenarioInterface $scenario, OutlineNode $outline = null)
 {
     $filename = Transliterator::transliterate($feature->getTitle(), $this->separator) . DIRECTORY_SEPARATOR;
     if ($outline) {
         $filename .= Transliterator::transliterate($outline->getTitle(), $this->separator) . DIRECTORY_SEPARATOR . $this->separator;
     }
     $filename .= Transliterator::transliterate($scenario->getTitle(), $this->separator);
     if ($outline) {
         $filename .= $this->separator;
     }
     return $filename;
 }
示例#8
0
 /**
  * Checks if scenario or outline matches specified filter.
  *
  * @param ScenarioInterface $scenario Scenario or Outline node instance
  *
  * @return Boolean
  */
 public function isScenarioMatch(ScenarioInterface $scenario)
 {
     if ($this->filterMinLine <= $scenario->getLine() && $this->filterMaxLine >= $scenario->getLine()) {
         return true;
     }
     if ($scenario instanceof OutlineNode && $scenario->hasExamples()) {
         foreach ($scenario->getExampleTable()->getLines() as $line) {
             if ($this->filterMinLine <= $line && $this->filterMaxLine >= $line) {
                 return true;
             }
         }
     }
     return false;
 }
 private function getSteps(ScenarioInterface $scenario)
 {
     if (!$scenario->hasSteps()) {
         return;
     }
     $recue = self::INDENTATION * 2;
     // TODO: abstract scenario formatter logic
     $longDesc = '';
     foreach ($scenario->getSteps() as $step) {
         $indentSpaces = $recue - strlen(trim($step->getKeyword())) + 1;
         $longDesc .= str_repeat(' ', $indentSpaces + self::INDENTATION) . trim($step->getKeyword()) . ' ' . trim($step->getText()) . PHP_EOL;
         if ($step->hasArguments()) {
             /* @var $argument TableNode */
             foreach ($step->getArguments() as $argument) {
                 if ($argument->getNodeType() === 'Table') {
                     $longDesc .= implode('', array_map(function ($arguments) use($recue) {
                         return str_repeat(' ', $recue + 4) . trim($arguments) . PHP_EOL;
                     }, explode("\n", $argument->getTableAsString())));
                 }
             }
         }
     }
     return $longDesc . PHP_EOL;
 }
示例#10
0
 /**
  * @param ScenarioInterface $scenario
  * @return array
  */
 private function getTitleLines(ScenarioInterface $scenario)
 {
     return array_map('trim', explode("\n", $scenario->getTitle()));
 }
 public function createFilename(FeatureNode $feature, ScenarioInterface $scenario, OutlineNode $outline = null)
 {
     return $this->directory . DIRECTORY_SEPARATOR . Transliterator::transliterate(implode($this->separator, $scenario->getTags()), $this->separator);
 }
 function it_does_not_save_screenshot_if_there_isnt_any(ScreenshotTaker $screenshotTaker, ScreenshotUploader $screenshotUploader, FilenameGenerator $filenameGenerator, Environment $env, FeatureNode $feature, ScenarioInterface $scenario, TestResult $result, Teardown $tearDown)
 {
     $event = new AfterScenarioTested($env->getWrappedObject(), $feature->getWrappedObject(), $scenario->getWrappedObject(), $result->getWrappedObject(), $tearDown->getWrappedObject());
     $result->getResultCode()->willReturn(TestResult::FAILED);
     $screenshotTaker->hasScreenshot()->willReturn(false)->shouldBeCalled();
     $filenameGenerator->generateFileName($feature, $scenario)->shouldNotBeCalled();
     $screenshotTaker->getImage()->shouldNotBeCalled();
     $screenshotUploader->upload(Argument::any(), Argument::any())->shouldNotBeCalled();
     $screenshotTaker->reset()->willReturn(null)->shouldBeCalled();
     $this->saveScreenshot($event);
 }
 function it_should_return_a_nice_filename(FeatureNode $featureNode, ScenarioInterface $scenarioNode)
 {
     $featureNode->getFile()->willReturn('base-path/example.feature');
     $scenarioNode->getLine()->willReturn(42);
     $this->generateFileName($featureNode, $scenarioNode)->shouldReturn('example_feature_42.png');
 }
 /**
  * @param ScenarioInterface $scenario
  *
  * @return bool
  */
 private function isParallelExamples(ScenarioInterface $scenario)
 {
     return $scenario instanceof OutlineNode && in_array(self::TAG_PARALLEL_EXAMPLES, $scenario->getTags());
 }
示例#15
0
 /**
  * Checks if scenario or outline matches specified filter.
  *
  * @param FeatureNode       $feature  Feature node instance
  * @param ScenarioInterface $scenario Scenario or Outline node instance
  *
  * @return Boolean
  */
 public function isScenarioMatch(FeatureNode $feature, ScenarioInterface $scenario)
 {
     return $this->isTagsMatchCondition(array_merge($feature->getTags(), $scenario->getTags()));
 }