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 Doctrine\Common\Annotations\Reader; |
15
|
|
|
use Gorghoa\StepArgumentInjectorBehatExtension\Annotation\StepArgumentInjectorArgument; |
16
|
|
|
use Gorghoa\StepArgumentInjectorBehatExtension\Annotation\StepInjectorArgument; |
17
|
|
|
use Prophecy\Prophecy\ObjectProphecy; |
18
|
|
|
use Behat\Testwork\Argument\ArgumentOrganiser as BehatArgumentOrganiser; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Vincent Chalamon <[email protected]> |
22
|
|
|
* @author Rodrigue Villetard <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class ArgumentOrganiserTest extends \PHPUnit_Framework_TestCase |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var ArgumentOrganiser |
28
|
|
|
*/ |
29
|
|
|
private $organiser; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var ObjectProphecy|ArgumentOrganiser |
33
|
|
|
*/ |
34
|
|
|
private $organiserMock; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var ObjectProphecy |
38
|
|
|
*/ |
39
|
|
|
private $initializerMock; |
|
|
|
|
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var ObjectProphecy|\ReflectionMethod |
43
|
|
|
*/ |
44
|
|
|
private $functionMock; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @var ObjectProphecy|Reader |
48
|
|
|
*/ |
49
|
|
|
private $readerMock; |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @var StepArgumentHolder |
53
|
|
|
*/ |
54
|
|
|
private $holderMock; |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* @var ObjectProphecy|StepArgumentInjectorArgument |
58
|
|
|
*/ |
59
|
|
|
private $annotationMock; |
60
|
|
|
|
61
|
|
|
protected function setUp() |
62
|
|
|
{ |
63
|
|
|
$this->organiserMock = $this->prophesize(BehatArgumentOrganiser::class); |
64
|
|
|
$this->functionMock = $this->prophesize(\ReflectionMethod::class); |
65
|
|
|
$this->readerMock = $this->prophesize(Reader::class); |
66
|
|
|
$this->annotationMock = function () { return $this->prophesize(StepInjectorArgument::class); }; |
|
|
|
|
67
|
|
|
$this->holderMock = $this->prophesize(StepArgumentHolder::class); |
|
|
|
|
68
|
|
|
|
69
|
|
|
$this->organiser = new ArgumentOrganiser( |
70
|
|
|
$this->organiserMock->reveal(), |
71
|
|
|
[$this->holderMock->reveal()], |
72
|
|
|
$this->readerMock->reveal() |
73
|
|
|
); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testOrganiseArguments() |
77
|
|
|
{ |
78
|
|
|
$this->functionMock->getParameters()->willReturn([ |
79
|
|
|
(object) ['name' => 'scenarioBanana'], // argument with injector annotation and **a service hold** value |
80
|
|
|
(object) ['name' => 'gorilla'], // argument with injector annotation but **no service hold** value |
81
|
|
|
(object) ['name' => 'foo'], // argument not handled by this extension |
82
|
|
|
])->shouldBeCalledTimes(1); |
83
|
|
|
|
84
|
|
|
/* |
|
|
|
|
85
|
|
|
$this->annotationMock->getArgument() |
86
|
|
|
->willReturn('scenarioBanana', 'gorilla') |
87
|
|
|
->shouldBeCalled(); |
88
|
|
|
*/ |
89
|
|
|
|
90
|
|
|
$annot1 = ($this->annotationMock)(); |
91
|
|
|
$annot1->getArgument()->willReturn('scenarioBanana')->shouldBeCalledTimes(1); |
92
|
|
|
$annot1->reveal(); |
93
|
|
|
|
94
|
|
|
$annot2 = ($this->annotationMock)(); |
95
|
|
|
$annot2->getArgument()->willReturn('gorilla')->shouldBeCalledTimes(1); |
96
|
|
|
$annot2->reveal(); |
97
|
|
|
|
98
|
|
|
$this->readerMock->getMethodAnnotations($this->functionMock->reveal())->willReturn([ |
99
|
|
|
$annot1, |
100
|
|
|
$annot2, |
101
|
|
|
])->shouldBeCalledTimes(1); |
102
|
|
|
|
103
|
|
|
$this->holderMock->doesHandleStepArgument($annot1)->willReturn(true); |
|
|
|
|
104
|
|
|
$this->holderMock->doesHandleStepArgument($annot2)->willReturn(false); |
|
|
|
|
105
|
|
|
|
106
|
|
|
$this->holderMock->getStepArgumentValueFor($annot1)->willReturn('yammyBanana')->shouldBeCalledTimes(1); |
107
|
|
|
$this->holderMock->getStepArgumentValueFor($annot2)->shouldNotBeCalled(); |
108
|
|
|
|
109
|
|
|
$this->holderMock->getStepArgumentValueFor($annot2); |
110
|
|
|
|
111
|
|
|
$this->organiserMock->organiseArguments($this->functionMock->reveal(), [ |
|
|
|
|
112
|
|
|
0 => 'scenarioBanana', |
113
|
|
|
1 => 'gorilla', |
114
|
|
|
'scenarioBanana' => 'yammyBanana', |
115
|
|
|
2 => 'yammyBanana', |
116
|
|
|
])->shouldBeCalledTimes(1); |
117
|
|
|
|
118
|
|
|
$this->organiser->organiseArguments($this->functionMock->reveal(), ['scenarioBanana', 'gorilla']); |
119
|
|
|
} |
120
|
|
|
} |
121
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.