This repository has been archived by the owner on Jul 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from vincentchalamon/master
[RFR] Supports ScenarioStateArgument annotation on Transform annotation
- Loading branch information
Showing
15 changed files
with
361 additions
and
355 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.