X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FHook%2FContext%2FAnnotation%2FHookAnnotationReader.php;fp=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FHook%2FContext%2FAnnotation%2FHookAnnotationReader.php;h=86a95cca5770e14768e5154fc3ecca92bf48fb61;hp=0000000000000000000000000000000000000000;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68 diff --git a/vendor/behat/behat/src/Behat/Behat/Hook/Context/Annotation/HookAnnotationReader.php b/vendor/behat/behat/src/Behat/Behat/Hook/Context/Annotation/HookAnnotationReader.php new file mode 100644 index 000000000..86a95cca5 --- /dev/null +++ b/vendor/behat/behat/src/Behat/Behat/Hook/Context/Annotation/HookAnnotationReader.php @@ -0,0 +1,65 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Behat\Behat\Hook\Context\Annotation; + +use Behat\Behat\Context\Annotation\AnnotationReader; +use Behat\Testwork\Hook\Call\RuntimeHook; +use ReflectionMethod; + +/** + * Reads hook callees from context method annotations. + * + * @author Konstantin Kudryashov + */ +final class HookAnnotationReader implements AnnotationReader +{ + /** + * @var string + */ + private static $regex = '/^\@(beforesuite|aftersuite|beforefeature|afterfeature|beforescenario|afterscenario|beforestep|afterstep)(?:\s+(.+))?$/i'; + /** + * @var string[] + */ + private static $classes = array( + 'beforesuite' => 'Behat\Testwork\Hook\Call\BeforeSuite', + 'aftersuite' => 'Behat\Testwork\Hook\Call\AfterSuite', + 'beforefeature' => 'Behat\Behat\Hook\Call\BeforeFeature', + 'afterfeature' => 'Behat\Behat\Hook\Call\AfterFeature', + 'beforescenario' => 'Behat\Behat\Hook\Call\BeforeScenario', + 'afterscenario' => 'Behat\Behat\Hook\Call\AfterScenario', + 'beforestep' => 'Behat\Behat\Hook\Call\BeforeStep', + 'afterstep' => 'Behat\Behat\Hook\Call\AfterStep' + ); + + /** + * Loads step callees (if exist) associated with specific method. + * + * @param string $contextClass + * @param ReflectionMethod $method + * @param string $docLine + * @param string $description + * + * @return null|RuntimeHook + */ + public function readCallee($contextClass, ReflectionMethod $method, $docLine, $description) + { + if (!preg_match(self::$regex, $docLine, $match)) { + return null; + } + + $type = strtolower($match[1]); + $class = self::$classes[$type]; + $pattern = isset($match[2]) ? $match[2] : null; + $callable = array($contextClass, $method->getName()); + + return new $class($pattern, $callable, $description); + } +}