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\Exception\NodeException;
17 use Behat\Gherkin\Node\TableNode;
18 use Behat\Testwork\Call\CallCenter;
19 use Behat\Testwork\Call\RuntimeCallee;
23 * Row-based table transformation.
25 * @author Konstantin Kudryashov <ever.zet@gmail.com>
27 final class RowBasedTableTransformation extends RuntimeCallee implements SimpleArgumentTransformation
29 const PATTERN_REGEX = '/^rowtable\:[[:print:]]+$/';
39 static public function supportsPatternAndMethod($pattern, ReflectionMethod $method)
41 return 1 === preg_match(self::PATTERN_REGEX, $pattern);
45 * Initializes transformation.
47 * @param string $pattern
48 * @param callable $callable
49 * @param null|string $description
51 public function __construct($pattern, $callable, $description = null)
53 $this->pattern = $pattern;
55 parent::__construct($callable, $description);
61 public function supportsDefinitionAndArgument(DefinitionCall $definitionCall, $argumentIndex, $value)
63 if (!$value instanceof TableNode) {
67 // What we're doing here is checking that we have a 2 column table.
68 // This bit checks we have two columns
71 } catch (NodeException $e) {
75 // And here we check we don't have a 3rd column
78 } catch (NodeException $e) {
79 // Once we know the table could be a row table, we check against the pattern.
80 return $this->pattern === 'rowtable:' . implode(',', $value->getColumn(0));
89 public function transformArgument(CallCenter $callCenter, DefinitionCall $definitionCall, $argumentIndex, $argumentValue)
91 $call = new TransformationCall(
92 $definitionCall->getEnvironment(),
93 $definitionCall->getCallee(),
98 $result = $callCenter->makeCall($call);
100 if ($result->hasException()) {
101 throw $result->getException();
104 return $result->getReturn();
110 public function getPriority()
118 public function getPattern()
120 return $this->pattern;
126 public function __toString()
128 return 'RowTableTransform ' . $this->pattern;