public function __construct(EventInterface $event)
 {
     $tags = array();
     if ($event instanceof ScenarioEvent) {
         $tags = $event->getScenario()->getOwnTags();
     } else {
         if ($event instanceof FeatureEvent) {
             $tags = $event->getFeature()->getTags();
         } else {
             if ($event instanceof OutlineExampleEvent) {
                 $tags = $event->getOutline()->getOwnTags();
             } else {
                 throw new \InvalidArgumentException(get_class($event) . ' is unsupported event type.');
             }
         }
     }
     parent::__construct($tags);
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function filterMatches(EventInterface $event)
 {
     if (null === ($filterString = $this->getFilter())) {
         return true;
     }
     $scenario = $event->getStep()->getParent();
     if (false !== strpos($filterString, '@')) {
         $filter = new TagFilter($filterString);
         if ($filter->isScenarioMatch($scenario)) {
             return true;
         }
     } elseif (!empty($filterString)) {
         $filter = new NameFilter($filterString);
         if ($filter->isScenarioMatch($scenario)) {
             return true;
         }
     }
     return false;
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function filterMatches(EventInterface $event)
 {
     if (null === ($filterString = $this->getFilter())) {
         return true;
     }
     $feature = $event->getFeature();
     if (false !== strpos($filterString, '@')) {
         $filter = new TagFilter($filterString);
         if ($filter->isFeatureMatch($feature)) {
             return true;
         }
     } elseif (!empty($filterString)) {
         $filter = new NameFilter($filterString);
         if ($filter->isFeatureMatch($feature)) {
             return true;
         }
     }
     return false;
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function filterMatches(EventInterface $event)
 {
     if (null === ($filterString = $this->getFilter())) {
         return true;
     }
     if ($event instanceof ScenarioEvent) {
         $scenario = $event->getScenario();
     } else {
         $scenario = $event->getOutline();
     }
     if (false !== strpos($filterString, '@')) {
         $filter = new TagFilter($filterString);
         if ($filter->isScenarioMatch($scenario)) {
             return true;
         }
     } elseif (!empty($filterString)) {
         $filter = new NameFilter($filterString);
         if ($filter->isScenarioMatch($scenario)) {
             return true;
         }
     }
     return false;
 }
 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;
 }
Example #6
0
 /**
  * Runs scenario hooks with specified name.
  *
  * @param   string                              $name   hooks name
  * @param   Behat\Behat\Event\EventInterface    $event  event to which hooks glued
  */
 protected function fireScenarioHooks($name, EventInterface $event)
 {
     if (!count($this->hooks)) {
         $this->loadHooks();
     }
     if ($event instanceof ScenarioEvent) {
         $scenario = $event->getScenario();
     } else {
         $scenario = $event->getOutline();
     }
     $hooks = isset($this->hooks[$name]) ? $this->hooks[$name] : array();
     foreach ($hooks as $hook) {
         if (is_callable($hook)) {
             call_user_func($hook, $event);
         } elseif (!empty($hook[0]) && false !== strpos($hook[0], '@')) {
             $filter = new TagFilter($hook[0]);
             if ($filter->isScenarioMatch($scenario)) {
                 call_user_func($hook[1], $event);
             }
         } elseif (!empty($hook[0])) {
             $filter = new NameFilter($hook[0]);
             if ($filter->isScenarioMatch($scenario)) {
                 call_user_func($hook[1], $event);
             }
         } else {
             call_user_func($hook[1], $event);
         }
     }
 }
Example #7
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;
 }
Example #8
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;
 }