4 * This file is part of the Behat Testwork.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Testwork\Hook\Call;
13 use Behat\Testwork\Call\Exception\BadCallbackException;
14 use Behat\Testwork\Hook\Scope\HookScope;
15 use Behat\Testwork\Hook\Scope\SuiteScope;
16 use Behat\Testwork\Suite\Suite;
19 * Represents suite hook executed in the runtime.
21 * @author Konstantin Kudryashov <ever.zet@gmail.com>
23 abstract class RuntimeSuiteHook extends RuntimeFilterableHook
28 * @param string $scopeName
29 * @param null|string $filterString
30 * @param callable $callable
31 * @param null|string $description
33 * @throws BadCallbackException If callback is method, but not a static one
35 public function __construct($scopeName, $filterString, $callable, $description = null)
37 parent::__construct($scopeName, $filterString, $callable, $description);
39 if ($this->isAnInstanceMethod()) {
40 throw new BadCallbackException(sprintf(
41 'Suite hook callback: %s::%s() must be a static method',
51 public function filterMatches(HookScope $scope)
53 if (!$scope instanceof SuiteScope) {
56 if (null === ($filterString = $this->getFilterString())) {
60 if (!empty($filterString)) {
61 return $this->isSuiteMatch($scope->getSuite(), $filterString);
68 * Checks if Feature matches specified filter.
71 * @param string $filterString
75 private function isSuiteMatch(Suite $suite, $filterString)
77 if ('/' === $filterString[0]) {
78 return 1 === preg_match($filterString, $suite->getName());
81 return false !== mb_strpos($suite->getName(), $filterString, 0, 'utf8');