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

Commit

Permalink
Merge pull request #26 from vincentchalamon/master
Browse files Browse the repository at this point in the history
[RFR] Supports ScenarioStateArgument annotation on Transform annotation
  • Loading branch information
vincentchalamon authored Jul 24, 2017
2 parents ecb8213 + 7316a89 commit 10de6c0
Show file tree
Hide file tree
Showing 15 changed files with 361 additions and 355 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ php:
- 5.5
- 5.6
- 7.0
- hhvm
- 7.1

matrix:
fast_finish: true
Expand All @@ -29,8 +29,8 @@ matrix:
- php: 7.0
- php: 7.0
env: PREFER_LOWEST="--prefer-lowest"
- php: hhvm
- php: hhvm
- php: 7.1
- php: 7.1
env: PREFER_LOWEST="--prefer-lowest"

env:
Expand Down
7 changes: 7 additions & 0 deletions features/scenario_state.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ Feature: Scenario shared state
"""
[Behat\Testwork\Argument\Exception\UnknownParameterValueException]
"""

Scenario: Scenario Outline should work properly
When I run "behat --no-colors features/bandar-log.feature"
Then it should pass with:
"""
2 scenarios (2 passed)
"""
5 changes: 2 additions & 3 deletions src/Argument/ScenarioStateArgumentOrganiser.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,13 @@ public function organiseArguments(ReflectionFunctionAbstract $function, array $m
return $element->name;
}, $function->getParameters());

$store = $this->store->getStore();

if (!($function instanceof \ReflectionMethod)) {
if (!$function instanceof \ReflectionMethod) {
return $this->baseOrganiser->organiseArguments($function, $match);
}

/** @var ScenarioStateArgument[] $annotations */
$annotations = $this->reader->getMethodAnnotations($function);
$store = $this->store->getStore();
foreach ($annotations as $annotation) {
if ($annotation instanceof ScenarioStateArgument &&
in_array($annotation->getArgument(), $paramsKeys) &&
Expand Down
85 changes: 85 additions & 0 deletions src/Call/Handler/RuntimeCallHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

/*
* This file is part of the ScenarioStateBehatExtension project.
*
* (c) Rodrigue Villetard <rodrigue.villetard@gmail.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Gorghoa\ScenarioStateBehatExtension\Call\Handler;

use Behat\Behat\Transformation\Call\TransformationCall;
use Behat\Testwork\Call\Call;
use Behat\Testwork\Call\Handler\CallHandler;
use Behat\Testwork\Environment\Call\EnvironmentCall;
use Behat\Testwork\Hook\Call\HookCall;
use Gorghoa\ScenarioStateBehatExtension\Resolver\ArgumentsResolver;

/**
* @author Vincent Chalamon <vincent@les-tilleuls.coop>
*/
final class RuntimeCallHandler implements CallHandler
{
/**
* @var CallHandler
*/
private $decorated;

/**
* @var ArgumentsResolver
*/
private $argumentsResolver;

/**
* @param CallHandler $decorated
* @param ArgumentsResolver $argumentsResolver
*/
public function __construct(CallHandler $decorated, ArgumentsResolver $argumentsResolver)
{
$this->decorated = $decorated;
$this->argumentsResolver = $argumentsResolver;
}

/**
* {@inheritdoc}
*/
public function supportsCall(Call $call)
{
return $this->decorated->supportsCall($call);
}

/**
* {@inheritdoc}
*/
public function handleCall(Call $call)
{
/** @var \ReflectionMethod $function */
$function = $call->getCallee()->getReflection();
$arguments = $call->getArguments();

if ($call instanceof HookCall) {
$scope = $call->getScope();

// Manage `scope` argument
foreach ($function->getParameters() as $parameter) {
if (null !== $parameter->getClass() && get_class($scope) === $parameter->getClass()->getName()) {
$arguments[$parameter->getName()] = $scope;
break;
}
}
}

$arguments = $this->argumentsResolver->resolve($function, $arguments);

if ($call instanceof TransformationCall) {
$call = new TransformationCall($call->getEnvironment(), $call->getDefinition(), $call->getCallee(), $arguments);
} elseif ($call instanceof HookCall) {
$call = new EnvironmentCall($call->getScope()->getEnvironment(), $call->getCallee(), $arguments);
}

return $this->decorated->handleCall($call);
}
}
117 changes: 0 additions & 117 deletions src/Hook/Dispatcher/ScenarioStateHookDispatcher.php

This file was deleted.

85 changes: 0 additions & 85 deletions src/Hook/Tester/ScenarioStateHookableScenarioTester.php

This file was deleted.

Loading

0 comments on commit 10de6c0

Please sign in to comment.