1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Drupal\DrupalExtension\Context\Annotation; |
4
|
|
|
|
5
|
|
|
use Behat\Behat\Context\Annotation\AnnotationReader; |
6
|
|
|
use Drupal\DrupalExtension\Hook\Dispatcher; |
7
|
|
|
use ReflectionMethod; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Annotated contexts reader. |
11
|
|
|
* |
12
|
|
|
* @see \Behat\Behat\Context\Loader\AnnotatedLoader |
13
|
|
|
*/ |
14
|
|
|
class Reader implements AnnotationReader { |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var string |
18
|
|
|
*/ |
19
|
|
|
private static $regex = '/^\@(beforenodecreate|afternodecreate|beforetermcreate|aftertermcreate|beforeusercreate|afterusercreate)(?:\s+(.+))?$/i'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var string[] |
23
|
|
|
*/ |
24
|
|
|
private static $classes = array( |
25
|
|
|
'afternodecreate' => 'Drupal\DrupalExtension\Hook\Call\AfterNodeCreate', |
26
|
|
|
'aftertermcreate' => 'Drupal\DrupalExtension\Hook\Call\AfterTermCreate', |
27
|
|
|
'afterusercreate' => 'Drupal\DrupalExtension\Hook\Call\AfterUserCreate', |
28
|
|
|
'beforenodecreate' => 'Drupal\DrupalExtension\Hook\Call\BeforeNodeCreate', |
29
|
|
|
'beforetermcreate' => 'Drupal\DrupalExtension\Hook\Call\BeforeTermCreate', |
30
|
|
|
'beforeusercreate' => 'Drupal\DrupalExtension\Hook\Call\BeforeUserCreate', |
31
|
|
|
); |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* {@inheritDoc} |
35
|
|
|
*/ |
36
|
|
|
public function readCallee($contextClass, ReflectionMethod $method, $docLine, $description) { |
37
|
|
|
|
38
|
|
|
if (!preg_match(self::$regex, $docLine, $match)) { |
39
|
|
|
return null; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
$type = strtolower($match[1]); |
43
|
|
|
$class = self::$classes[$type]; |
44
|
|
|
$pattern = isset($match[2]) ? $match[2] : null; |
45
|
|
|
$callable = array($contextClass, $method->getName()); |
|
|
|
|
46
|
|
|
|
47
|
|
|
return new $class($pattern, $callable, $description); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
} |
51
|
|
|
|