Skip to content
This repository was archived by the owner on Jul 29, 2022. It is now read-only.

Commit b83b775

Browse files
author
Rodrigue Villetard
committed
Decouple phpunit tests
1 parent ae55309 commit b83b775

File tree

7 files changed

+143
-190
lines changed

7 files changed

+143
-190
lines changed

argumentsExt/Argument/ArgumentOrganiser.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ public function organiseArguments(ReflectionFunctionAbstract $function, array $m
6363

6464
foreach ($annotations as $annotation) {
6565
if ($annotation instanceof StepInjectorArgument &&
66-
in_array($annotation->getArgument(), $paramsKeys)
66+
in_array($argument = $annotation->getArgument(), $paramsKeys)
6767
) {
6868
/* @var StepInjectorArgument $annotation */
6969
foreach ($this->stepArgumentHolders as $hooker) {
7070
if ($hooker->doesHandleStepArgument($annotation)) {
71-
$match[$annotation->getArgument()]
71+
72+
$match[$argument]
7273
= $match[strval(++$i)]
7374
= $hooker->getStepArgumentValueFor($annotation)
7475
;

argumentsExt/Resolver/ArgumentsResolver.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct($stepArgumentHolders, Reader $reader)
4949
*/
5050
public function resolve(\ReflectionMethod $function, array $arguments)
5151
{
52-
// No `@StepArgumentInjectorArgument` annotation found
52+
// No `@StepInjectorArgument` annotation found
5353
if (null === $this->reader->getMethodAnnotation($function, StepInjectorArgument::class)) {
5454
return $arguments;
5555
}
@@ -62,12 +62,12 @@ public function resolve(\ReflectionMethod $function, array $arguments)
6262
$annotations = $this->reader->getMethodAnnotations($function);
6363
foreach ($annotations as $annotation) {
6464
if ($annotation instanceof StepInjectorArgument &&
65-
in_array($annotation->getArgument(), $paramsKeys)
65+
in_array($argument = $annotation->getArgument(), $paramsKeys)
6666
) {
6767
/* @var StepArgumentInjectorArgument $annotation */
6868
foreach ($this->stepArgumentHolders as $hooker) {
6969
if ($hooker->doesHandleStepArgument($annotation)) {
70-
$arguments[$annotation->getArgument()] = $hooker->getStepArgumentValueFor($annotation);
70+
$arguments[$argument] = $hooker->getStepArgumentValueFor($annotation);
7171
}
7272
}
7373
}

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,8 @@
1414
<testsuite name="ScenarioStateBehatExtension Test Suite">
1515
<directory>tests</directory>
1616
</testsuite>
17+
<testsuite name="StepArgumentInjectorBehatExtension Test Suite">
18+
<directory>testsSAI</directory>
19+
</testsuite>
1720
</testsuites>
1821
</phpunit>

testsSAI/Annotation/ScenarioStateArgumentTest.php

Lines changed: 0 additions & 56 deletions
This file was deleted.
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the StepArgumentInjectorBehatExtension project.
5+
*
6+
* (c) Rodrigue Villetard <rodrigue.villetard@gmail.com>
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\StepInjectorArgument;
16+
use Prophecy\Prophecy\ObjectProphecy;
17+
use Behat\Testwork\Argument\ArgumentOrganiser as BehatArgumentOrganiser;
18+
19+
/**
20+
* @author Vincent Chalamon <vincentchalamon@gmail.com>
21+
* @author Rodrigue Villetard <rodrigue.villetard@gmail.com>
22+
*/
23+
class ArgumentOrganiserTest extends \PHPUnit_Framework_TestCase
24+
{
25+
/**
26+
* @var ArgumentOrganiser
27+
*/
28+
private $organiser;
29+
30+
/**
31+
* @var ObjectProphecy|ArgumentOrganiser
32+
*/
33+
private $organiserMock;
34+
35+
/**
36+
* @var ObjectProphecy
37+
*/
38+
private $initializerMock;
39+
40+
/**
41+
* @var ObjectProphecy|\ReflectionMethod
42+
*/
43+
private $functionMock;
44+
45+
/**
46+
* @var ObjectProphecy|Reader
47+
*/
48+
private $readerMock;
49+
50+
/**
51+
* @var StepArgumentHolder
52+
*/
53+
private $holderMock;
54+
55+
protected function setUp()
56+
{
57+
$this->organiserMock = $this->prophesize(BehatArgumentOrganiser::class);
58+
$this->functionMock = $this->prophesize(\ReflectionMethod::class);
59+
$this->readerMock = $this->prophesize(Reader::class);
60+
$this->holderMock = $this->prophesize(StepArgumentHolder::class);
61+
62+
$this->organiser = new ArgumentOrganiser(
63+
$this->organiserMock->reveal(),
64+
[$this->holderMock->reveal()],
65+
$this->readerMock->reveal()
66+
);
67+
}
68+
69+
/**
70+
* @return ObjectProphecy
71+
*/
72+
private function annotationMockFactory()
73+
{
74+
return $this->prophesize(StepInjectorArgument::class);
75+
}
76+
77+
public function testOrganiseArguments()
78+
{
79+
$this->functionMock->getParameters()->willReturn([
80+
(object) ['name' => 'scenarioBanana'], // argument with injector annotation and **a service hold** value
81+
(object) ['name' => 'gorilla'], // argument with injector annotation but **no service hold** value
82+
(object) ['name' => 'foo'], // argument not handled by this extension
83+
])->shouldBeCalledTimes(1);
84+
85+
$annot1 = $this->annotationMockFactory();
86+
$annot1->getArgument()->willReturn('scenarioBanana')->shouldBeCalledTimes(1);
87+
$annot1->reveal();
88+
89+
$annot2 = $this->annotationMockFactory();
90+
$annot2->getArgument()->willReturn('gorilla')->shouldBeCalledTimes(1);
91+
$annot2->reveal();
92+
93+
$this->readerMock->getMethodAnnotations($this->functionMock->reveal())->willReturn([
94+
$annot1,
95+
$annot2,
96+
])->shouldBeCalledTimes(1);
97+
98+
$this->holderMock->doesHandleStepArgument($annot1)->willReturn(true);
99+
$this->holderMock->doesHandleStepArgument($annot2)->willReturn(false);
100+
101+
$this->holderMock->getStepArgumentValueFor($annot1)->willReturn('yammyBanana')->shouldBeCalledTimes(1);
102+
$this->holderMock->getStepArgumentValueFor($annot2)->shouldNotBeCalled();
103+
104+
$this->holderMock->getStepArgumentValueFor($annot2);
105+
106+
$this->organiserMock->organiseArguments($this->functionMock->reveal(), [
107+
0 => 'scenarioBanana',
108+
1 => 'gorilla',
109+
'scenarioBanana' => 'yammyBanana',
110+
2 => 'yammyBanana',
111+
])->shouldBeCalledTimes(1);
112+
113+
$this->organiser->organiseArguments($this->functionMock->reveal(), ['scenarioBanana', 'gorilla']);
114+
}
115+
}

testsSAI/Argument/ScenarioStateArgumentOrganiserTest.php

Lines changed: 0 additions & 114 deletions
This file was deleted.

0 commit comments

Comments
 (0)