4 * This file is part of the Behat.
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\Behat\Hook\Context\Annotation;
13 use Behat\Behat\Context\Annotation\AnnotationReader;
14 use Behat\Testwork\Hook\Call\RuntimeHook;
18 * Reads hook callees from context method annotations.
20 * @author Konstantin Kudryashov <ever.zet@gmail.com>
22 final class HookAnnotationReader implements AnnotationReader
27 private static $regex = '/^\@(beforesuite|aftersuite|beforefeature|afterfeature|beforescenario|afterscenario|beforestep|afterstep)(?:\s+(.+))?$/i';
31 private static $classes = array(
32 'beforesuite' => 'Behat\Testwork\Hook\Call\BeforeSuite',
33 'aftersuite' => 'Behat\Testwork\Hook\Call\AfterSuite',
34 'beforefeature' => 'Behat\Behat\Hook\Call\BeforeFeature',
35 'afterfeature' => 'Behat\Behat\Hook\Call\AfterFeature',
36 'beforescenario' => 'Behat\Behat\Hook\Call\BeforeScenario',
37 'afterscenario' => 'Behat\Behat\Hook\Call\AfterScenario',
38 'beforestep' => 'Behat\Behat\Hook\Call\BeforeStep',
39 'afterstep' => 'Behat\Behat\Hook\Call\AfterStep'
43 * Loads step callees (if exist) associated with specific method.
45 * @param string $contextClass
46 * @param ReflectionMethod $method
47 * @param string $docLine
48 * @param string $description
50 * @return null|RuntimeHook
52 public function readCallee($contextClass, ReflectionMethod $method, $docLine, $description)
54 if (!preg_match(self::$regex, $docLine, $match)) {
58 $type = strtolower($match[1]);
59 $class = self::$classes[$type];
60 $pattern = isset($match[2]) ? $match[2] : null;
61 $callable = array($contextClass, $method->getName());
63 return new $class($pattern, $callable, $description);