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\Resolver; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Annotations\Reader; |
15
|
|
|
use Gorghoa\StepArgumentInjectorBehatExtension\Annotation\StepInjectorArgument; |
16
|
|
|
use Gorghoa\StepArgumentInjectorBehatExtension\Argument\StepArgumentHolder; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @author Vincent Chalamon <[email protected]> |
20
|
|
|
* @author Rodrigue Villetard <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class ArgumentsResolverTest extends \PHPUnit_Framework_TestCase |
23
|
|
|
{ |
24
|
|
|
public function testResolve() |
25
|
|
|
{ |
26
|
|
|
$readerMock = $this->prophesize(Reader::class); |
27
|
|
|
$functionMock = $this->prophesize(\ReflectionMethod::class); |
28
|
|
|
$parameterMock = $this->prophesize(\ReflectionParameter::class); |
29
|
|
|
$annotationMock = $this->prophesize(StepInjectorArgument::class); |
30
|
|
|
|
31
|
|
|
$functionMock->getParameters()->willReturn([$parameterMock, $parameterMock])->shouldBeCalledTimes(2); |
32
|
|
|
$parameterMock->getName()->willReturn('lorem', 'foo', 'lorem', 'foo')->shouldBeCalledTimes(4); |
33
|
|
|
|
34
|
|
|
$holderMock1 = $this->prophesize(StepArgumentHolder::class); |
35
|
|
|
$holderMock2 = $this->prophesize(StepArgumentHolder::class); |
36
|
|
|
|
37
|
|
|
$readerMock->getMethodAnnotation($functionMock, StepInjectorArgument::class)->willReturn($annotationMock)->shouldBeCalledTimes(1); |
38
|
|
|
$readerMock->getMethodAnnotations($functionMock)->willReturn([$this->prophesize(\stdClass::class), $annotationMock])->shouldBeCalledTimes(1); |
39
|
|
|
$annotationMock->getArgument()->willReturn('lorem')->shouldBeCalledTimes(1); |
40
|
|
|
|
41
|
|
|
$holderMock1->doesHandleStepArgument($annotationMock)->willReturn(true)->shouldBeCalledTimes(1); |
42
|
|
|
$holderMock1->getStepArgumentValueFor($annotationMock)->willReturn(true)->shouldBeCalledTimes(1); |
43
|
|
|
|
44
|
|
|
$holderMock2->doesHandleStepArgument($annotationMock)->willReturn(false)->shouldBeCalledTimes(1); |
45
|
|
|
$holderMock2->getStepArgumentValueFor($annotationMock)->shouldNotBeCalled(); |
46
|
|
|
|
47
|
|
|
$resolver = new ArgumentsResolver([$holderMock1->reveal(), $holderMock2->reveal()], $readerMock->reveal()); |
48
|
|
|
$resolver->resolve($functionMock->reveal(), ['lorem' => 'pouet', 'foo' => 'bar']); |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|