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); }
/** * {@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; }
/** * 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); } } }