Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Testwork / Hook / Call / RuntimeSuiteHook.php
1 <?php
2
3 /*
4  * This file is part of the Behat Testwork.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Testwork\Hook\Call;
12
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;
17
18 /**
19  * Represents suite hook executed in the runtime.
20  *
21  * @author Konstantin Kudryashov <ever.zet@gmail.com>
22  */
23 abstract class RuntimeSuiteHook extends RuntimeFilterableHook
24 {
25     /**
26      * Initializes hook.
27      *
28      * @param string      $scopeName
29      * @param null|string $filterString
30      * @param callable    $callable
31      * @param null|string $description
32      *
33      * @throws BadCallbackException If callback is method, but not a static one
34      */
35     public function __construct($scopeName, $filterString, $callable, $description = null)
36     {
37         parent::__construct($scopeName, $filterString, $callable, $description);
38
39         if ($this->isAnInstanceMethod()) {
40             throw new BadCallbackException(sprintf(
41                 'Suite hook callback: %s::%s() must be a static method',
42                 $callable[0],
43                 $callable[1]
44             ), $callable);
45         }
46     }
47
48     /**
49      * {@inheritdoc}
50      */
51     public function filterMatches(HookScope $scope)
52     {
53         if (!$scope instanceof SuiteScope) {
54             return false;
55         }
56         if (null === ($filterString = $this->getFilterString())) {
57             return true;
58         }
59
60         if (!empty($filterString)) {
61             return $this->isSuiteMatch($scope->getSuite(), $filterString);
62         }
63
64         return false;
65     }
66
67     /**
68      * Checks if Feature matches specified filter.
69      *
70      * @param Suite  $suite
71      * @param string $filterString
72      *
73      * @return Boolean
74      */
75     private function isSuiteMatch(Suite $suite, $filterString)
76     {
77         if ('/' === $filterString[0]) {
78             return 1 === preg_match($filterString, $suite->getName());
79         }
80
81         return false !== mb_strpos($suite->getName(), $filterString, 0, 'utf8');
82     }
83 }