X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FTestwork%2FHook%2FCall%2FRuntimeSuiteHook.php;fp=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FTestwork%2FHook%2FCall%2FRuntimeSuiteHook.php;h=237bc76158c7f5d028f1a7af3d8749eb6e3f5233;hp=0000000000000000000000000000000000000000;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68 diff --git a/vendor/behat/behat/src/Behat/Testwork/Hook/Call/RuntimeSuiteHook.php b/vendor/behat/behat/src/Behat/Testwork/Hook/Call/RuntimeSuiteHook.php new file mode 100644 index 000000000..237bc7615 --- /dev/null +++ b/vendor/behat/behat/src/Behat/Testwork/Hook/Call/RuntimeSuiteHook.php @@ -0,0 +1,83 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Behat\Testwork\Hook\Call; + +use Behat\Testwork\Call\Exception\BadCallbackException; +use Behat\Testwork\Hook\Scope\HookScope; +use Behat\Testwork\Hook\Scope\SuiteScope; +use Behat\Testwork\Suite\Suite; + +/** + * Represents suite hook executed in the runtime. + * + * @author Konstantin Kudryashov + */ +abstract class RuntimeSuiteHook extends RuntimeFilterableHook +{ + /** + * Initializes hook. + * + * @param string $scopeName + * @param null|string $filterString + * @param callable $callable + * @param null|string $description + * + * @throws BadCallbackException If callback is method, but not a static one + */ + public function __construct($scopeName, $filterString, $callable, $description = null) + { + parent::__construct($scopeName, $filterString, $callable, $description); + + if ($this->isAnInstanceMethod()) { + throw new BadCallbackException(sprintf( + 'Suite hook callback: %s::%s() must be a static method', + $callable[0], + $callable[1] + ), $callable); + } + } + + /** + * {@inheritdoc} + */ + public function filterMatches(HookScope $scope) + { + if (!$scope instanceof SuiteScope) { + return false; + } + if (null === ($filterString = $this->getFilterString())) { + return true; + } + + if (!empty($filterString)) { + return $this->isSuiteMatch($scope->getSuite(), $filterString); + } + + return false; + } + + /** + * Checks if Feature matches specified filter. + * + * @param Suite $suite + * @param string $filterString + * + * @return Boolean + */ + private function isSuiteMatch(Suite $suite, $filterString) + { + if ('/' === $filterString[0]) { + return 1 === preg_match($filterString, $suite->getName()); + } + + return false !== mb_strpos($suite->getName(), $filterString, 0, 'utf8'); + } +}