X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FTransformation%2FTransformation%2FTokenNameTransformation.php;fp=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FTransformation%2FTransformation%2FTokenNameTransformation.php;h=cd4f4ab0b36e252dec96aedd1692e7820bfebba2;hp=0000000000000000000000000000000000000000;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68 diff --git a/vendor/behat/behat/src/Behat/Behat/Transformation/Transformation/TokenNameTransformation.php b/vendor/behat/behat/src/Behat/Behat/Transformation/Transformation/TokenNameTransformation.php new file mode 100644 index 000000000..cd4f4ab0b --- /dev/null +++ b/vendor/behat/behat/src/Behat/Behat/Transformation/Transformation/TokenNameTransformation.php @@ -0,0 +1,109 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Behat\Behat\Transformation\Transformation; + +use Behat\Behat\Definition\Call\DefinitionCall; +use Behat\Behat\Transformation\Call\TransformationCall; +use Behat\Behat\Transformation\SimpleArgumentTransformation; +use Behat\Testwork\Call\CallCenter; +use Behat\Testwork\Call\RuntimeCallee; +use ReflectionMethod; + +/** + * Token name based transformation. + * + * @author Konstantin Kudryashov + */ +final class TokenNameTransformation extends RuntimeCallee implements SimpleArgumentTransformation +{ + const PATTERN_REGEX = '/^\:\w+$/'; + + /** + * @var string + */ + private $pattern; + + + /** + * {@inheritdoc} + */ + static public function supportsPatternAndMethod($pattern, ReflectionMethod $method) + { + return 1 === preg_match(self::PATTERN_REGEX, $pattern); + } + + /** + * Initializes transformation. + * + * @param string $pattern + * @param callable $callable + * @param null|string $description + */ + public function __construct($pattern, $callable, $description = null) + { + $this->pattern = $pattern; + + parent::__construct($callable, $description); + } + + /** + * {@inheritdoc} + */ + public function supportsDefinitionAndArgument(DefinitionCall $definitionCall, $argumentIndex, $argumentValue) + { + return ':' . $argumentIndex === $this->pattern; + } + + /** + * {@inheritdoc} + */ + public function transformArgument(CallCenter $callCenter, DefinitionCall $definitionCall, $argumentIndex, $argumentValue) + { + $call = new TransformationCall( + $definitionCall->getEnvironment(), + $definitionCall->getCallee(), + $this, + array($argumentValue) + ); + + $result = $callCenter->makeCall($call); + + if ($result->hasException()) { + throw $result->getException(); + } + + return $result->getReturn(); + } + + /** + * {@inheritdoc} + */ + public function getPriority() + { + return 50; + } + + /** + * {@inheritdoc} + */ + public function getPattern() + { + return $this->pattern; + } + + /** + * {@inheritdoc} + */ + public function __toString() + { + return 'TokenNameTransform ' . $this->pattern; + } +}