4 * This file is part of the Behat.
5 * (c) Konstantin Kudryashov <ever.zet@gmail.com>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
11 namespace Behat\Behat\Transformation\Transformation;
13 use Behat\Behat\Definition\Call\DefinitionCall;
14 use Behat\Behat\Transformation\Call\TransformationCall;
15 use Behat\Behat\Transformation\SimpleArgumentTransformation;
16 use Behat\Gherkin\Node\TableNode;
17 use Behat\Testwork\Call\CallCenter;
18 use Behat\Testwork\Call\RuntimeCallee;
22 * Table row transformation.
24 * @author Konstantin Kudryashov <ever.zet@gmail.com>
26 final class TableRowTransformation extends RuntimeCallee implements SimpleArgumentTransformation
28 const PATTERN_REGEX = '/^row\:[[:print:]]+$/';
38 static public function supportsPatternAndMethod($pattern, ReflectionMethod $method)
40 return 1 === preg_match(self::PATTERN_REGEX, $pattern);
44 * Initializes transformation.
46 * @param string $pattern
47 * @param callable $callable
48 * @param null|string $description
50 public function __construct($pattern, $callable, $description = null)
52 $this->pattern = $pattern;
54 parent::__construct($callable, $description);
60 public function supportsDefinitionAndArgument(DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
62 if (!$argumentValue instanceof TableNode) {
66 return $this->pattern === 'row:' . implode(',', $argumentValue->getRow(0));
72 public function transformArgument(CallCenter $callCenter, DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
75 foreach ($argumentValue as $row) {
76 $call = new TransformationCall(
77 $definitionCall->getEnvironment(),
78 $definitionCall->getCallee(),
83 $result = $callCenter->makeCall($call);
85 if ($result->hasException()) {
86 throw $result->getException();
89 $rows[] = $result->getReturn();
98 public function getPriority()
106 public function getPattern()
108 return $this->pattern;
114 public function __toString()
116 return 'TableRowTransform ' . $this->pattern;