/** * {@inheritdoc} */ public function isScenarioMatch(ScenarioNode $scenario) { if ('/' === $this->filterString[0] && 1 === preg_match($this->filterString, $scenario->getTitle())) { return true; } elseif (false !== mb_strpos($scenario->getTitle(), $this->filterString)) { return true; } if (null !== $scenario->getFeature()) { return $this->isFeatureMatch($scenario->getFeature()); } return false; }
public function testTitle() { $scenario = new ScenarioNode(); $this->assertNull($scenario->getTitle()); $scenario->setTitle('test title 1'); $this->assertEquals('test title 1', $scenario->getTitle()); $scenario = new ScenarioNode('test title 2'); $this->assertEquals('test title 2', $scenario->getTitle()); }
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()); }
public function call($suffix = null) { $this->calls++; $scenario = $this->scenario; if (isset($suffix)) { $scenario = new ScenarioNode($scenario->getTitle() . $suffix, $scenario->getTags(), $scenario->getSteps(), $scenario->getKeyword(), $scenario->getLine()); } $feature = $this->feature; $skip = $this->skip; $isolatedEnvironment = $this->env; $tester = $scenario instanceof OutlineNode ? $this->outlineTester : $this->scenarioTester; $setup = $tester->setUp($isolatedEnvironment, $feature, $scenario, $skip); $localSkip = !$setup->isSuccessful() || $skip; $testResult = $tester->test($isolatedEnvironment, $feature, $scenario, $localSkip); $teardown = $tester->tearDown($isolatedEnvironment, $feature, $scenario, $localSkip, $testResult); $integerResult = new IntegerTestResult($testResult->getResultCode()); $result = new TestWithSetupResult($setup, $integerResult, $teardown); $this->results[] = $result; }
protected function printTestCase(ScenarioNode $scenario, $time, EventInterface $event) { $className = $this->formatClassname($scenario->getFeature()); $name = $scenario->getTitle(); if ($event instanceof OutlineExampleEvent) { $name .= sprintf(', Ex #%d', $event->getIteration() + 1); } $caseStats = sprintf('classname="%s" name="%s" time="%F" assertions="%d"', htmlspecialchars($className), htmlspecialchars($name), $time, $this->scenarioStepsCount); $xml = " <testcase {$caseStats}>\n"; foreach ($this->exceptions as $exception) { $error = $this->exceptionToString($exception); $elemType = $this->getElementType($event->getResult()); $elemAttributes = ''; if ('skipped' !== $elemType) { $elemAttributes = sprintf('message="%s" type="%s"', htmlspecialchars($error), $this->getResultColorCode($event->getResult())); } $xml .= sprintf(' <%s %s>', $elemType, $elemAttributes); $exception = str_replace(['<![CDATA[', ']]>'], '', (string) $exception); $xml .= sprintf("<![CDATA[\n%s\n]]></%s>\n", $exception, $elemType); } $this->exceptions = []; $xml .= " </testcase>"; $this->testcases[] = $xml; }
/** * Prints testcase. * * @param ScenarioNode $scenario * @param float $time * @param EventInterface $event */ protected function printTestCase(ScenarioNode $scenario, $time, EventInterface $event) { $className = $scenario->getFeature()->getTitle(); $name = $scenario->getTitle(); $name .= $event instanceof OutlineExampleEvent ? ', Ex #' . ($event->getIteration() + 1) : ''; $caseStats = sprintf('classname="%s" name="%s" time="%F"', htmlspecialchars($className), htmlspecialchars($name), $time); $xml = " <testcase {$caseStats}>\n"; foreach ($this->exceptions as $exception) { $xml .= sprintf(' <failure message="%s" type="%s">', htmlspecialchars($exception->getMessage()), $this->getResultColorCode($event->getResult())); $exception = str_replace(array('<![CDATA[', ']]>'), '', (string) $exception); $xml .= "<![CDATA[\n{$exception}\n]]></failure>\n"; } $this->exceptions = array(); $xml .= " </testcase>"; $this->testcases[] = $xml; }
public function getRegex() { $regexp = "/^" . $this->scenario->getTitle() . "\$/is"; $regexp = preg_replace("/(<.*?>)/is", "(?P\$1.*?)", $regexp); return $regexp; }
/** * Dumps scenario. * * @param ScenarioNode $scenario Scenario instance * * @return string */ public function dumpScenario(ScenarioNode $scenario) { $keyWordToUse = $scenario instanceof OutlineNode ? $this->keywords->getOutlineKeywords() : $this->keywords->getScenarioKeywords(); $content = '' . (sizeof($scenario->getTags()) > 0 ? PHP_EOL . $this->dumpTags($scenario->getTags(), 1) : '') . PHP_EOL . $this->dumpKeyword($keyWordToUse, $scenario->getTitle(), 1); foreach ($scenario->getSteps() as $step) { $content .= PHP_EOL . $this->dumpIndent(2) . $this->dumpStep($step); } if ($scenario instanceof OutlineNode) { $content .= '' . PHP_EOL . PHP_EOL . $this->dumpKeyword($this->keywords->getExamplesKeywords(), '', 1); $examples = $scenario->getExamples(); $content .= $this->dumpTableNode($examples, 2); } return $content; }
/** * Prints scenario header. * * @param ScenarioNode $scenario Current scenario object * @return [void] * * @uses printFeatureOrScenarioTags() * @uses printScenarioName() */ protected function printScenarioHeader(ScenarioNode $scenario) { $this->_feature_info = ''; $this->writeln('<tr>'); echo $scenario->getTitle() . PHP_EOL; }
/** * Prints testcase. * * @param Behat\Gherkin\Node\ScenarioNode $feature * @param float $time * @param Behat\Behat\Event\EventInterface $event */ protected function printTestCase(ScenarioNode $scenario, $time, EventInterface $event) { $className = $scenario->getFeature()->getTitle() . '.' . $scenario->getTitle(); $name = $scenario->getTitle(); $caseStats = sprintf('classname="%s" name="%s" time="%f"', htmlspecialchars($className), htmlspecialchars($name), htmlspecialchars($time)); $xml = " <testcase {$caseStats}>\n"; foreach ($this->exceptions as $exception) { $xml .= sprintf(' <failure message="%s" type="%s">' . "\n", htmlspecialchars($exception->getMessage()), $this->getResultColorCode($event->getResult())); $xml .= "<![CDATA[\n{$exception}\n]]>"; $xml .= " </failure>\n"; } $xml .= " </testcase>"; $this->testcases[] = $xml; }