1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the StepArgumentInjectorBehatExtension project. |
5
|
|
|
* |
6
|
|
|
* (c) Rodrigue Villetard <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Gorghoa\StepArgumentInjectorBehatExtension\Argument; |
13
|
|
|
|
14
|
|
|
use Behat\Testwork\Argument\ArgumentOrganiser as BehatArgumentOrganiser; |
15
|
|
|
use Doctrine\Common\Annotations\Reader; |
16
|
|
|
use Gorghoa\StepArgumentInjectorBehatExtension\Annotation\StepArgumentInjectorArgument; |
17
|
|
|
use Gorghoa\StepArgumentInjectorBehatExtension\Annotation\StepInjectorArgument; |
18
|
|
|
// use Gorghoa\StepArgumentInjectorBehatExtension\Context\Initializer\StepArgumentInjectorInitializer; |
19
|
|
|
use ReflectionFunctionAbstract; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Rodrigue Villetard <[email protected]> |
23
|
|
|
* @author Vincent Chalamon <[email protected]> |
24
|
|
|
*/ |
25
|
|
|
final class ArgumentOrganiser implements BehatArgumentOrganiser |
26
|
|
|
{ |
27
|
|
|
/** |
28
|
|
|
* @var BehatArgumentOrganiser |
29
|
|
|
*/ |
30
|
|
|
private $baseOrganiser; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var StepArgumentInjectorInitializer |
34
|
|
|
*/ |
35
|
|
|
private $hookers; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var Reader |
39
|
|
|
*/ |
40
|
|
|
private $reader; |
41
|
|
|
|
42
|
|
|
public function __construct(BehatArgumentOrganiser $organiser, array $hookers, Reader $reader) |
43
|
|
|
{ |
44
|
|
|
$this->baseOrganiser = $organiser; |
45
|
|
|
$this->hookers = $hookers; |
|
|
|
|
46
|
|
|
$this->reader = $reader; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* {@inheritdoc} |
51
|
|
|
*/ |
52
|
|
|
public function organiseArguments(ReflectionFunctionAbstract $function, array $match) |
53
|
|
|
{ |
54
|
|
|
$i = array_slice(array_keys($match), -1, 1)[0]; |
55
|
|
|
$paramsKeys = array_map(function ($element) { |
56
|
|
|
return $element->name; |
57
|
|
|
}, $function->getParameters()); |
58
|
|
|
|
59
|
|
|
if (!$function instanceof \ReflectionMethod) { |
60
|
|
|
return $this->baseOrganiser->organiseArguments($function, $match); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** @var StepArgumentInjectorArgument[] $annotations */ |
64
|
|
|
$annotations = $this->reader->getMethodAnnotations($function); |
65
|
|
|
|
66
|
|
View Code Duplication |
foreach ($annotations as $annotation) { |
|
|
|
|
67
|
|
|
if ($annotation instanceof StepInjectorArgument && |
68
|
|
|
in_array($annotation->getArgument(), $paramsKeys) |
69
|
|
|
) { |
70
|
|
|
foreach ($this->hookers as $hooker) { |
71
|
|
|
if ($hooker->hasStepArgumentFor($annotation->getName())) { |
72
|
|
|
$match[$annotation->getArgument()] |
73
|
|
|
= $match[strval(++$i)] |
74
|
|
|
= $hooker->getStepArgumentFor($annotation->getName()) |
75
|
|
|
; |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return $this->baseOrganiser->organiseArguments($function, $match); |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..