/**
  * @param \Symfony\Component\DependencyInjection\ContainerInterface $container
  * @param \Doctrine\Common\Persistence\ManagerRegistry $doctrine
  * @param \Doctrine\Common\Persistence\ObjectManager $manager
  * @param \Behat\Behat\Hook\Scope\ScenarioScope $event
  * @param \Behat\Gherkin\Node\FeatureNode $feature
  * @param \Behat\Gherkin\Node\ScenarioNode $scenario
  * @param \Knp\FriendlyContexts\Alice\Loader\Yaml $loader
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadataFactory $metadataFactory
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $userMetadata
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $placeMetadata
  * @param \Doctrine\Common\Persistence\Mapping\ClassMetadata $productMetadata
  */
 function let($container, $doctrine, $manager, $event, $loader, $feature, $scenario, $metadataFactory, $userMetadata, $placeMetadata, $productMetadata)
 {
     $doctrine->getManager()->willReturn($manager);
     $feature->getTags()->willReturn(['alice(Place)', 'admin']);
     $scenario->getTags()->willReturn(['alice(User)']);
     $event->getFeature()->willReturn($feature);
     $event->getScenario()->willReturn($scenario);
     $loader->load('user.yml')->willReturn([]);
     $loader->load('product.yml')->willReturn([]);
     $loader->load('place.yml')->willReturn([]);
     $loader->getCache()->willReturn([]);
     $loader->clearCache()->willReturn(null);
     $fixtures = ['User' => 'user.yml', 'Product' => 'product.yml', 'Place' => 'place.yml'];
     $config = ['alice' => ['fixtures' => $fixtures, 'dependencies' => []]];
     $container->has(Argument::any())->willReturn(true);
     $container->hasParameter(Argument::any())->willReturn(true);
     $container->get('friendly.alice.loader.yaml')->willReturn($loader);
     $container->get('doctrine')->willReturn($doctrine);
     $container->getParameter('friendly.alice.fixtures')->willReturn($fixtures);
     $container->getParameter('friendly.alice.dependencies')->willReturn([]);
     $manager->getMetadataFactory()->willReturn($metadataFactory);
     $metadataFactory->getAllMetadata()->willReturn([$userMetadata, $placeMetadata, $productMetadata]);
     $userMetadata->getName()->willReturn('User');
     $placeMetadata->getName()->willReturn('Place');
     $productMetadata->getName()->willReturn('Product');
     $this->initialize($config, $container);
 }
 /**
  * @BeforeStep
  */
 public function debugStepsBefore(BeforeStepScope $scope)
 {
     // Tests tagged with @debugBeforeEach will wait for [ENTER] before running each step.
     if ($this->scenario->hasTag('debugBeforeEach')) {
         $this->printUrl();
         $this->iPutABreakpoint();
     }
 }
示例#3
0
 /**
  * Checks if scenario or outline matches specified filter.
  *
  * @param ScenarioNode $scenario Scenario or Outline node instance
  *
  * @return Boolean
  */
 public function isScenarioMatch(ScenarioNode $scenario)
 {
     if ($this->filterLine === $scenario->getLine()) {
         return true;
     }
     if ($scenario instanceof OutlineNode && $scenario->hasExamples()) {
         return $this->filterLine === $scenario->getLine() || in_array($this->filterLine, $scenario->getExamples()->getRowLines());
     }
     return false;
 }
示例#4
0
 /**
  * {@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;
 }
示例#5
0
 /**
  * Checks if scenario or outline matches specified filter.
  *
  * @param ScenarioNode $scenario Scenario or Outline node instance
  *
  * @return Boolean
  */
 public function isScenarioMatch(ScenarioNode $scenario)
 {
     if ($this->filterMinLine <= $scenario->getLine() && $this->filterMaxLine >= $scenario->getLine()) {
         return true;
     }
     if ($scenario instanceof OutlineNode && $scenario->hasExamples()) {
         foreach ($scenario->getExamples()->getRowLines() as $line) {
             if ($line >= $this->filterMinLine && $line <= $this->filterMaxLine) {
                 return true;
             }
         }
     }
     return false;
 }
示例#6
0
 public function test()
 {
     $this->makeContexts();
     $description = explode("\n", $this->featureNode->getDescription());
     foreach ($description as $line) {
         $this->getScenario()->runStep(new Comment($line));
     }
     if ($background = $this->featureNode->getBackground()) {
         foreach ($background->getSteps() as $step) {
             $this->runStep($step);
         }
     }
     foreach ($this->scenarioNode->getSteps() as $step) {
         $this->runStep($step);
     }
 }
 public function testIsScenarioMatchFilter()
 {
     $feature = new Node\FeatureNode(null, null, '/some/path/with/some.feature', 1);
     $scenario = new Node\ScenarioNode(null, 2);
     $scenario->setFeature($feature);
     $filter = new PathsFilter(array('/some'));
     $this->assertTrue($filter->isScenarioMatch($scenario));
     $filter = new PathsFilter(array('/abc', '/def', '/some'));
     $this->assertTrue($filter->isScenarioMatch($scenario));
     $filter = new PathsFilter(array('/abc', '/def', '/some/path'));
     $this->assertTrue($filter->isScenarioMatch($scenario));
     $filter = new PathsFilter(array('/abc', '/some/path', '/def'));
     $this->assertTrue($filter->isScenarioMatch($scenario));
     $filter = new PathsFilter(array('/abc', '/def', '/wrong/path'));
     $this->assertFalse($filter->isScenarioMatch($scenario));
 }
 public function testTokens()
 {
     $step = new StepNode('When', 'Some "<text>" in <string>');
     $scenario = new ScenarioNode();
     $scenario->addStep($step);
     $feature = new FeatureNode();
     $feature->addScenario($scenario);
     $feature->freeze();
     $step1 = $step->createExampleRowStep(array('text' => 'change'));
     $this->assertNotSame($step, $step1);
     $this->assertEquals('Some "change" in <string>', $step1->getText());
     $this->assertEquals('Some "<text>" in <string>', $step1->getCleanText());
     $step2 = $step->createExampleRowStep(array('text' => 'change', 'string' => 'browser'));
     $this->assertNotSame($step, $step2);
     $this->assertEquals('Some "change" in browser', $step2->getText());
     $this->assertEquals('Some "<text>" in <string>', $step2->getCleanText());
 }
    public function testIsScenarioMatchFilter()
    {
        $feature = new Node\FeatureNode(null, <<<NAR
In order to be able to read news in my own language
As a french user
I need to be able to switch website language to french
NAR
, null, 1);
        $scenario = new Node\ScenarioNode(null, 2);
        $scenario->setFeature($feature);
        $filter = new RoleFilter('french user');
        $this->assertTrue($filter->isScenarioMatch($scenario));
        $filter = new RoleFilter('french *');
        $this->assertTrue($filter->isScenarioMatch($scenario));
        $filter = new RoleFilter('french');
        $this->assertFalse($filter->isScenarioMatch($scenario));
        $filter = new RoleFilter('user');
        $this->assertFalse($filter->isScenarioMatch($scenario));
        $filter = new RoleFilter('*user');
        $this->assertTrue($filter->isScenarioMatch($scenario));
        $filter = new RoleFilter('French User');
        $this->assertTrue($filter->isScenarioMatch($scenario));
    }
 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;
 }
 /**
  * Runs definition callback.
  *
  * @param ContextInterface $context
  *
  * @return mixed
  *
  * @throws BehaviorException
  */
 public function run(ContextInterface $context)
 {
     preg_match($this->getRegex(), $this->getMatchedText(), $matches);
     $replacements = array();
     foreach ($matches as $key => $value) {
         if (!is_numeric($key)) {
             $replacements["<{$key}>"] = $value;
         }
     }
     $steps = array();
     foreach ($this->scenario->getSteps() as $stepOutline) {
         /** @var $step StepNode */
         $step = clone $stepOutline;
         $step->setText(strtr($step->getText(), $replacements));
         $steps[] = new Step($step);
     }
     return $steps;
 }
 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;
 }
示例#13
0
    public function translationTestDataProvider()
    {
        $keywords = $this->getKeywords();
        $lexer = new Lexer($keywords);
        $parser = new Parser($lexer);
        $dumper = new KeywordsDumper($keywords);
        $data = array();
        foreach ($this->getKeywordsArray() as $lang => $i18nKeywords) {
            $features = array();
            foreach (explode('|', $i18nKeywords['feature']) as $transNum => $featureKeyword) {
                $line = 1;
                if ('en' !== $lang) {
                    $line = 2;
                }
                $feature = new Node\FeatureNode('Internal operations', <<<DESC
In order to stay secret
As a secret organization
We need to be able to erase past agents' memory
DESC
, $lang . '_' . ($transNum + 1) . '.feature', $line);
                $feature->setLanguage($lang);
                $feature->setKeyword($featureKeyword);
                $line += 5;
                $background = new Node\BackgroundNode(null, $line);
                $keywords = explode('|', $i18nKeywords['background']);
                $background->setKeyword($keywords[0]);
                $line += 1;
                $line = $this->addSteps($background, $i18nKeywords['given'], 'there is agent A', $line);
                $line = $this->addSteps($background, $i18nKeywords['and'], 'there is agent B', $line);
                $feature->setBackground($background);
                $line += 1;
                foreach (explode('|', $i18nKeywords['scenario']) as $scenarioKeyword) {
                    $scenario = new Node\ScenarioNode('Erasing agent memory', $line);
                    $scenario->setKeyword($scenarioKeyword);
                    $line += 1;
                    $line = $this->addSteps($scenario, $i18nKeywords['given'], 'there is agent J', $line);
                    $line = $this->addSteps($scenario, $i18nKeywords['and'], 'there is agent K', $line);
                    $line = $this->addSteps($scenario, $i18nKeywords['when'], 'I erase agent K\'s memory', $line);
                    $line = $this->addSteps($scenario, $i18nKeywords['then'], 'there should be agent J', $line);
                    $line = $this->addSteps($scenario, $i18nKeywords['but'], 'there should not be agent K', $line);
                    $feature->addScenario($scenario);
                    $line += 1;
                }
                foreach (explode('|', $i18nKeywords['scenario_outline']) as $outlineKeyword) {
                    $outline = new Node\OutlineNode('Erasing other agents\' memory', $line);
                    $outline->setKeyword($outlineKeyword);
                    $line += 1;
                    $line = $this->addSteps($outline, $i18nKeywords['given'], 'there is agent <agent1>', $line);
                    $line = $this->addSteps($outline, $i18nKeywords['and'], 'there is agent <agent2>', $line);
                    $line = $this->addSteps($outline, $i18nKeywords['when'], 'I erase agent <agent2>\'s memory', $line);
                    $line = $this->addSteps($outline, $i18nKeywords['then'], 'there should be agent <agent1>', $line);
                    $line = $this->addSteps($outline, $i18nKeywords['but'], 'there should not be agent <agent2>', $line);
                    $line += 1;
                    $outline->setExamples($examples = new Node\TableNode(<<<TABLE
                      | agent1 | agent2 |
                      | D      | M      |
TABLE
));
                    $keywords = explode('|', $i18nKeywords['examples']);
                    $examples->setKeyword($keywords[0]);
                    $line += 3;
                    $feature->addScenario($outline);
                    $line += 1;
                }
                $features[] = $feature;
            }
            $dumped = $dumper->dump($lang, false);
            $parsed = array();
            try {
                foreach ($dumped as $num => $dumpedFeature) {
                    $parsed[] = $parser->parse($dumpedFeature, $lang . '_' . ($num + 1) . '.feature');
                }
            } catch (\Exception $e) {
                throw new \Exception($e->getMessage() . ":\n" . $dumped, 0, $e);
            }
            $data[] = array($lang, $features, $parsed);
        }
        return $data;
    }
 public function testTags()
 {
     $scenario = new ScenarioNode();
     $this->assertFalse($scenario->hasTags());
     $this->assertInternalType('array', $scenario->getTags());
     $this->assertEquals(0, count($scenario->getTags()));
     $scenario->setTags($tags = array('tag1', 'tag2'));
     $this->assertEquals($tags, $scenario->getTags());
     $scenario->addTag('tag3');
     $this->assertEquals(array('tag1', 'tag2', 'tag3'), $scenario->getTags());
     $this->assertFalse($scenario->hasTag('tag4'));
     $this->assertTrue($scenario->hasTag('tag2'));
     $this->assertTrue($scenario->hasTag('tag3'));
 }
 public function translationTestDataProvider()
 {
     $data = array();
     $translator = $this->getTranslator();
     $parser = $this->getParser();
     $finder = new Finder();
     $i18ns = $finder->files()->name('*.xliff')->in(__DIR__ . '/../Fixtures/i18n');
     foreach ($i18ns as $i18n) {
         $language = basename($i18n, '.xliff');
         $translator->addResource('xliff', $i18n, $language, 'gherkin');
         $etalon = array();
         $features = array();
         foreach ($this->getTranslatedKeywords('Feature', $language) as $featureNum => $featureKeyword) {
             $gherkin = "# language: {$language}";
             $lineNum = 1;
             $feature = new Node\FeatureNode(null, null, null, ++$lineNum);
             $feature->setLanguage($language);
             $feature->setKeyword($featureKeyword);
             $feature->setTitle($title = "title of the feature N{$featureNum}");
             $feature->setDescription($description = "some\nfeature\ndescription");
             $gherkin .= "\n{$featureKeyword}: {$title}";
             $gherkin .= "\n{$description}";
             $lineNum += 3;
             $stepKeywords = $this->getTranslatedKeywords('Given|When|Then|And|But', $language);
             $backgroundKeywords = $this->getTranslatedKeywords('Background', $language);
             $examplesKeywords = $this->getTranslatedKeywords('Examples', $language);
             // Background
             $backgroundKeyword = $backgroundKeywords[0];
             $background = new Node\BackgroundNode(null, ++$lineNum);
             $background->setKeyword($backgroundKeyword);
             $feature->setBackground($background);
             $gherkin .= "\n{$backgroundKeyword}:";
             foreach ($stepKeywords as $stepNum => $stepKeyword) {
                 $step = new Node\StepNode($stepKeyword, $text = "text of the step N{$stepNum}", ++$lineNum);
                 $background->addStep($step);
                 $gherkin .= "\n{$stepKeyword} {$text}";
             }
             // Scenarios
             foreach ($this->getTranslatedKeywords('Scenario', $language) as $scenarioNum => $scenarioKeyword) {
                 $scenario = new Node\ScenarioNode($title = "title of the scenario N{$scenarioNum}", ++$lineNum);
                 $scenario->setKeyword($scenarioKeyword);
                 $feature->addScenario($scenario);
                 $gherkin .= "\n{$scenarioKeyword}: {$title}";
                 foreach ($stepKeywords as $stepNum => $stepKeyword) {
                     $step = new Node\StepNode($stepKeyword, $text = "text of the step N{$stepNum}", ++$lineNum);
                     $scenario->addStep($step);
                     $gherkin .= "\n{$stepKeyword} {$text}";
                 }
             }
             // Scenario Outlines
             foreach ($this->getTranslatedKeywords('Scenario Outline', $language) as $outlineNum => $outlineKeyword) {
                 $outline = new Node\OutlineNode($title = "title of the outline N{$outlineNum}", ++$lineNum);
                 $outline->setKeyword($outlineKeyword);
                 $feature->addScenario($outline);
                 $gherkin .= "\n{$outlineKeyword}: {$title}";
                 $stepKeyword = $stepKeywords[0];
                 $step = new Node\StepNode($stepKeyword, $text = "text of the step <num>", ++$lineNum);
                 $outline->addStep($step);
                 $gherkin .= "\n{$stepKeyword} {$text}";
                 $examplesKeyword = $examplesKeywords[0];
                 $examples = new Node\TableNode();
                 $examples->setKeyword($examplesKeyword);
                 $examples->addRow(array('num'));
                 $examples->addRow(array(2));
                 $outline->setExamples($examples);
                 $gherkin .= "\n{$examplesKeyword}:";
                 $gherkin .= "\n  | num |";
                 $gherkin .= "\n  | 2   |";
                 $lineNum += 3;
             }
             $etalon[] = $feature;
             $features[] = $this->getParser()->parse($gherkin);
         }
         $data[] = array($language, $etalon, $features);
     }
     return $data;
 }
   public function testDumpScenarioWithTagsAddTagsToTheContent()
   {
       $dumper = new Dumper($this->keywords);
       $scenario = new ScenarioNode('my scenario');
       $scenario->addStep(new StepNode('Given', 'my example1'));
       $scenario->addTag('tag1');
       $scenario->addTag('tag2');
       $expected = '
 @tag1 @tag2
 Scenario: my scenario
   Given my example1';
       $this->assertEquals($expected, $dumper->dumpScenario($scenario));
   }
 /**
  * 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;
 }
 protected function scenarioEventMock($tag)
 {
     $scenario = new ScenarioNode();
     $scenario->addTag($tag);
     return new ScenarioEvent($scenario, $this->getMock('Behat\\Behat\\Context\\ContextInterface'));
 }
示例#19
0
 /**
  * Checks if scenario or outline matches specified filter.
  *
  * @param ScenarioNode $scenario Scenario or Outline node instance
  *
  * @return Boolean
  */
 public function isScenarioMatch(ScenarioNode $scenario)
 {
     return $this->isFeatureMatch($scenario->getFeature());
 }
示例#20
0
 /**
  * Loads scenario from provided scenario hash.
  *
  * @param array   $hash Scenario hash
  * @param integer $line Scenario definition line
  *
  * @return ScenarioNode
  */
 protected function loadScenarioHash(array $hash, $line = 0)
 {
     $scenario = new Node\ScenarioNode(null, isset($hash['line']) ? $hash['line'] : $line);
     $scenario->setKeyword(isset($hash['keyword']) ? $hash['keyword'] : 'Scenario');
     if (isset($hash['title'])) {
         $scenario->setTitle($hash['title']);
     }
     if (isset($hash['tags'])) {
         $scenario->setTags($hash['tags']);
     }
     if (isset($hash['steps'])) {
         foreach ($hash['steps'] as $stepIterator => $stepHash) {
             $scenario->addStep($this->loadStepHash($stepHash, $stepIterator));
         }
     }
     return $scenario;
 }
示例#21
0
    public function testCanFormatStepsWithPyString()
    {
        $this->formatter = new Step(Step::ALIGN_TO_LEFT);
        $expected = <<<EOS
        Given I am a Java programmer
        And I am not Kawaii
        When I start to contribute to a php project:
        """
          This is a pyString
          Multi-line :D

          Meh... kawaii hu!?
        """
        Then I start to love php
        When I go to a php events
        Then I start to become a Kawaii guy

EOS;
        $tableNode = new PyStringNode(['This is a pyString', 'Multi-line :D', '', 'Meh... kawaii hu!?'], 1);
        $scenario = new ScenarioNode(' Not all people who program php are becoming kawaii ', [' kawaii ', ' kawaii-bug-12 '], [new StepNode('Given', '       I am a Java programmer ', [], 1, 'Given'), new StepNode('And', '  I am not Kawaii ', [], 2, 'And'), new StepNode('When', '  I start to contribute to a php project: ', [$tableNode], 3, 'And'), new StepNode('Then', '  I start to love php ', [], 4, 'And'), new StepNode('When', ' I go to a php events ', [], 5, 'And'), new StepNode('Then', 'I start to become a Kawaii guy ', [], 5, 'And')], 'Scenario', 1);
        self::assertSame($expected, $this->formatter->format($scenario->getSteps()));
    }
示例#22
0
文件: Parser.php 项目: kingsj/core
 /**
  * Parses scenario token & returns it's node.
  *
  * @return  Behat\Gherkin\Node\ScenarioNode
  */
 protected function parseScenario()
 {
     $token = $this->expectTokenType('Scenario');
     $node = new Node\ScenarioNode(trim($token->value) ?: null, $token->line);
     $node->setKeyword($token->keyword);
     // Parse tags
     $this->parseNodeTags($node);
     // Parse title
     $this->parseNodeDescription($node, $token->indent + 2);
     // Parse scenario steps
     while ('Step' === $this->predictTokenType()) {
         $node->addStep($this->parseExpression());
     }
     return $node;
 }
示例#23
0
 /**
  * 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;
 }
示例#24
0
 /**
  * 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;
 }
示例#25
0
 /**
  * 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;
 }
示例#26
0
 /**
  * {@inheritdoc}
  */
 public function isScenarioMatch(ScenarioNode $scenario)
 {
     return $this->filterLine === $scenario->getLine();
 }