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

Commit

Permalink
Decouple phpunit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigue Villetard committed Jul 27, 2017
1 parent ae55309 commit b83b775
Show file tree
Hide file tree
Showing 7 changed files with 143 additions and 190 deletions.
5 changes: 3 additions & 2 deletions argumentsExt/Argument/ArgumentOrganiser.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,13 @@ public function organiseArguments(ReflectionFunctionAbstract $function, array $m

foreach ($annotations as $annotation) {
if ($annotation instanceof StepInjectorArgument &&
in_array($annotation->getArgument(), $paramsKeys)
in_array($argument = $annotation->getArgument(), $paramsKeys)
) {
/* @var StepInjectorArgument $annotation */
foreach ($this->stepArgumentHolders as $hooker) {
if ($hooker->doesHandleStepArgument($annotation)) {
$match[$annotation->getArgument()]

$match[$argument]
= $match[strval(++$i)]
= $hooker->getStepArgumentValueFor($annotation)
;
Expand Down
6 changes: 3 additions & 3 deletions argumentsExt/Resolver/ArgumentsResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct($stepArgumentHolders, Reader $reader)
*/
public function resolve(\ReflectionMethod $function, array $arguments)
{
// No `@StepArgumentInjectorArgument` annotation found
// No `@StepInjectorArgument` annotation found
if (null === $this->reader->getMethodAnnotation($function, StepInjectorArgument::class)) {
return $arguments;
}
Expand All @@ -62,12 +62,12 @@ public function resolve(\ReflectionMethod $function, array $arguments)
$annotations = $this->reader->getMethodAnnotations($function);
foreach ($annotations as $annotation) {
if ($annotation instanceof StepInjectorArgument &&
in_array($annotation->getArgument(), $paramsKeys)
in_array($argument = $annotation->getArgument(), $paramsKeys)
) {
/* @var StepArgumentInjectorArgument $annotation */
foreach ($this->stepArgumentHolders as $hooker) {
if ($hooker->doesHandleStepArgument($annotation)) {
$arguments[$annotation->getArgument()] = $hooker->getStepArgumentValueFor($annotation);
$arguments[$argument] = $hooker->getStepArgumentValueFor($annotation);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@
<testsuite name="ScenarioStateBehatExtension Test Suite">
<directory>tests</directory>
</testsuite>
<testsuite name="StepArgumentInjectorBehatExtension Test Suite">
<directory>testsSAI</directory>
</testsuite>
</testsuites>
</phpunit>
56 changes: 0 additions & 56 deletions testsSAI/Annotation/ScenarioStateArgumentTest.php

This file was deleted.

115 changes: 115 additions & 0 deletions testsSAI/Argument/ArgumentOrganiserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

/*
* This file is part of the StepArgumentInjectorBehatExtension project.
*
* (c) Rodrigue Villetard <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Gorghoa\StepArgumentInjectorBehatExtension\Argument;

use Doctrine\Common\Annotations\Reader;
use Gorghoa\StepArgumentInjectorBehatExtension\Annotation\StepInjectorArgument;
use Prophecy\Prophecy\ObjectProphecy;
use Behat\Testwork\Argument\ArgumentOrganiser as BehatArgumentOrganiser;

/**
* @author Vincent Chalamon <[email protected]>
* @author Rodrigue Villetard <[email protected]>
*/
class ArgumentOrganiserTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ArgumentOrganiser
*/
private $organiser;

/**
* @var ObjectProphecy|ArgumentOrganiser
*/
private $organiserMock;

/**
* @var ObjectProphecy
*/
private $initializerMock;

/**
* @var ObjectProphecy|\ReflectionMethod
*/
private $functionMock;

/**
* @var ObjectProphecy|Reader
*/
private $readerMock;

/**
* @var StepArgumentHolder
*/
private $holderMock;

protected function setUp()
{
$this->organiserMock = $this->prophesize(BehatArgumentOrganiser::class);
$this->functionMock = $this->prophesize(\ReflectionMethod::class);
$this->readerMock = $this->prophesize(Reader::class);
$this->holderMock = $this->prophesize(StepArgumentHolder::class);

$this->organiser = new ArgumentOrganiser(
$this->organiserMock->reveal(),
[$this->holderMock->reveal()],
$this->readerMock->reveal()
);
}

/**
* @return ObjectProphecy
*/
private function annotationMockFactory()
{
return $this->prophesize(StepInjectorArgument::class);
}

public function testOrganiseArguments()
{
$this->functionMock->getParameters()->willReturn([
(object) ['name' => 'scenarioBanana'], // argument with injector annotation and **a service hold** value
(object) ['name' => 'gorilla'], // argument with injector annotation but **no service hold** value
(object) ['name' => 'foo'], // argument not handled by this extension
])->shouldBeCalledTimes(1);

$annot1 = $this->annotationMockFactory();
$annot1->getArgument()->willReturn('scenarioBanana')->shouldBeCalledTimes(1);
$annot1->reveal();

$annot2 = $this->annotationMockFactory();
$annot2->getArgument()->willReturn('gorilla')->shouldBeCalledTimes(1);
$annot2->reveal();

$this->readerMock->getMethodAnnotations($this->functionMock->reveal())->willReturn([
$annot1,
$annot2,
])->shouldBeCalledTimes(1);

$this->holderMock->doesHandleStepArgument($annot1)->willReturn(true);
$this->holderMock->doesHandleStepArgument($annot2)->willReturn(false);

$this->holderMock->getStepArgumentValueFor($annot1)->willReturn('yammyBanana')->shouldBeCalledTimes(1);
$this->holderMock->getStepArgumentValueFor($annot2)->shouldNotBeCalled();

$this->holderMock->getStepArgumentValueFor($annot2);

$this->organiserMock->organiseArguments($this->functionMock->reveal(), [
0 => 'scenarioBanana',
1 => 'gorilla',
'scenarioBanana' => 'yammyBanana',
2 => 'yammyBanana',
])->shouldBeCalledTimes(1);

$this->organiser->organiseArguments($this->functionMock->reveal(), ['scenarioBanana', 'gorilla']);
}
}
114 changes: 0 additions & 114 deletions testsSAI/Argument/ScenarioStateArgumentOrganiserTest.php

This file was deleted.

Loading

0 comments on commit b83b775

Please sign in to comment.