1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the ScenarioStateBehatExtension 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\ScenarioStateBehatExtension\Resolver; |
13
|
|
|
|
14
|
|
|
use Doctrine\Common\Annotations\Reader; |
15
|
|
|
use Gorghoa\ScenarioStateBehatExtension\Annotation\ScenarioStateArgument; |
16
|
|
|
use Gorghoa\ScenarioStateBehatExtension\Context\Initializer\ScenarioStateInitializer; |
17
|
|
|
use Gorghoa\ScenarioStateBehatExtension\ScenarioStateInterface; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* @author Vincent Chalamon <[email protected]> |
21
|
|
|
*/ |
22
|
|
|
class ArgumentsResolverTest extends \PHPUnit_Framework_TestCase |
23
|
|
|
{ |
24
|
|
|
public function testResolve() |
25
|
|
|
{ |
26
|
|
|
$initializerMock = $this->prophesize(ScenarioStateInitializer::class); |
27
|
|
|
$storeMock = $this->prophesize(ScenarioStateInterface::class); |
28
|
|
|
$readerMock = $this->prophesize(Reader::class); |
29
|
|
|
$functionMock = $this->prophesize(\ReflectionMethod::class); |
30
|
|
|
$parameterMock = $this->prophesize(\ReflectionParameter::class); |
31
|
|
|
$annotationMock = $this->prophesize(ScenarioStateArgument::class); |
32
|
|
|
|
33
|
|
|
$functionMock->getParameters()->willReturn([$parameterMock, $parameterMock])->shouldBeCalledTimes(2); |
34
|
|
|
$parameterMock->getName()->willReturn('lorem', 'foo', 'lorem', 'lorem', 'foo', 'foo')->shouldBeCalledTimes(6); |
35
|
|
|
$initializerMock->getStore()->willReturn($storeMock)->shouldBeCalledTimes(1); |
36
|
|
|
$readerMock->getMethodAnnotation($functionMock, ScenarioStateArgument::class)->willReturn($annotationMock)->shouldBeCalledTimes(1); |
37
|
|
|
$readerMock->getMethodAnnotations($functionMock)->willReturn([$this->prophesize(\stdClass::class), $annotationMock])->shouldBeCalledTimes(1); |
38
|
|
|
$annotationMock->getArgument()->willReturn('lorem')->shouldBeCalledTimes(2); |
39
|
|
|
$annotationMock->getName()->willReturn('ipsum')->shouldBeCalledTimes(2); |
40
|
|
|
$storeMock->hasStateFragment('ipsum')->willReturn(true)->shouldBeCalledTimes(1); |
41
|
|
|
$storeMock->getStateFragment('ipsum')->willReturn('pouet')->shouldBeCalledTimes(1); |
42
|
|
|
|
43
|
|
|
$resolver = new ArgumentsResolver($initializerMock->reveal(), $readerMock->reveal()); |
44
|
|
|
$resolver->resolve($functionMock->reveal(), ['lorem' => 'pouet', 'foo' => 'bar']); |
45
|
|
|
} |
46
|
|
|
} |
47
|
|
|
|