/**
  * @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));
 }
 /**
  * @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';
 }
 public function testFile()
 {
     $feature = new FeatureNode();
     $this->assertNull($feature->getFile());
     $feature = new FeatureNode(null, null, 'path/to/file_2');
     $this->assertEquals('path/to/file_2', $feature->getFile());
 }
示例#4
0
 /**
  * Checks if Feature matches specified filter.
  *
  * @param FeatureNode $feature Feature instance
  *
  * @return Boolean
  */
 public function isFeatureMatch(FeatureNode $feature)
 {
     foreach ($this->filterPaths as $path) {
         if (0 === strpos($feature->getFile(), $path)) {
             return true;
         }
     }
     return false;
 }
示例#5
0
 /**
  * update feature results based on step tests results
  * @param  FeatureNode $feature    object
  * @param  TestResult  $testResult object
  * @return null
  */
 public function updateFeatureStatus(FeatureNode $feature, TestResult $testResult)
 {
     $featurePath = $feature->getFile();
     $resultCode = $testResult->getResultCode();
     if ($resultCode > $this->testResults[$featurePath]["testResultCode"]) {
         $this->testResults[$featurePath]["testResultCode"] = $resultCode;
         $this->testResults[$featurePath]["testResult"] = self::RESULT_CODES_MAPPING[$resultCode];
     }
 }
 /**
  * {@inheritdoc}
  */
 public function test(Environment $env, FeatureNode $feature, $skip)
 {
     $background = $feature->getBackground();
     if (null === $background) {
         throw new FeatureHasNoBackgroundException(sprintf('Feature `%s` has no background that could be tested.', $feature->getFile()), $feature);
     }
     $results = $this->containerTester->test($env, $feature, $background, $skip);
     return new TestResults($results);
 }
示例#7
0
 public function __construct(FeatureNode $featureNode, ScenarioNode $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());
 }
 function its_printHeader_when_basePath_is_specified_should_output_file_and_line_with_relative_path(Formatter $formatter, FeatureNode $featureNode, Scenario $scenario, OutputPrinter $printer)
 {
     $folderName = 'foldername';
     $filename = 'file';
     $lineNumber = 2;
     $this->beConstructedWith($folderName);
     $formatter->getOutputPrinter()->shouldBeCalled()->willReturn($printer);
     $featureNode->getFile()->shouldBeCalled()->willReturn($folderName . '/' . $filename);
     $scenario->getLine()->shouldBeCalled()->willReturn($lineNumber);
     $printer->write("{$filename}:{$lineNumber}")->shouldBeCalled();
     $this->printHeader($formatter, $featureNode, $scenario);
 }
示例#9
0
 /**
  * Prints scenario path comment.
  *
  * @param Formatter   $formatter
  * @param FeatureNode $feature
  * @param Scenario    $scenario
  * @param integer     $indentation
  */
 public function printScenarioPath(Formatter $formatter, FeatureNode $feature, Scenario $scenario, $indentation)
 {
     $printer = $formatter->getOutputPrinter();
     if (!$formatter->getParameter('paths')) {
         $printer->writeln();
         return;
     }
     $fileAndLine = sprintf('%s:%s', $this->relativizePaths($feature->getFile()), $scenario->getLine());
     $headerWidth = $this->widthCalculator->calculateScenarioHeaderWidth($scenario, $indentation);
     $scenarioWidth = $this->widthCalculator->calculateScenarioWidth($scenario, $indentation, 2);
     $spacing = str_repeat(' ', max(0, $scenarioWidth - $headerWidth));
     $printer->writeln(sprintf('%s {+comment}# %s{-comment}', $spacing, $fileAndLine));
 }
 /**
  * {@inheritdoc}
  */
 public function printHeader(Formatter $formatter, FeatureNode $feature, Scenario $scenario)
 {
     $printer = $formatter->getOutputPrinter();
     $fileAndLine = sprintf('%s:%s', $this->relativePath($feature->getFile()), $scenario->getLine());
     $printer->write(sprintf('%s', $fileAndLine));
 }
示例#11
0
 /**
  * Prints testsuite footer.
  *
  * @param FeatureNode $feature
  * @param float       $time
  */
 protected function printTestSuiteFooter(FeatureNode $feature, $time)
 {
     $suiteStats = sprintf('classname="behat.features" errors="0" failures="%d" name="%s" file="%s" tests="%d" time="%F"', $this->exceptionsCount, htmlspecialchars($feature->getTitle()), htmlspecialchars($feature->getFile()), $this->stepsCount, $time);
     $this->writeln("<testsuite {$suiteStats}>");
     $this->writeln(implode("\n", $this->testcases));
     $this->writeln('</testsuite>');
 }
示例#12
0
 /**
  * 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($scenario)) {
             continue;
         }
         if ($scenario instanceof OutlineNode && $scenario->hasExamples()) {
             $table = $scenario->getExampleTable()->getTable();
             $lines = array_keys($table);
             $filteredTable = array($lines[0] => $table[$lines[0]]);
             unset($table[$lines[0]]);
             foreach ($table as $line => $row) {
                 if ($this->filterMinLine <= $line && $this->filterMaxLine >= $line) {
                     $filteredTable[$line] = $row;
                 }
             }
             $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());
 }
 /**
  * @param FeatureNode $feature
  *
  * @return string
  */
 private function formatClassname(FeatureNode $feature)
 {
     $filepath = htmlspecialchars($feature->getFile());
     $classname = substr($filepath, strpos($filepath, 'features/') + strlen('features/'));
     return str_replace('/', '__', $classname);
 }
 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');
 }
示例#15
0
 public function getFile()
 {
     return $this->featureNode->getFile();
 }