public function testArguments() { $step = new StepNode('Given', null); $this->assertEquals(0, count($step->getArguments())); $this->assertFalse($step->hasArguments()); $step->addArgument(new PyStringNode()); $this->assertEquals(1, count($step->getArguments())); $this->assertTrue($step->hasArguments()); $step->addArgument(new TableNode()); $this->assertEquals(2, count($step->getArguments())); $this->assertTrue($step->hasArguments()); $arguments = $step->getArguments(); $this->assertInstanceOf('Behat\\Gherkin\\Node\\PyStringNode', $arguments[0]); $this->assertInstanceOf('Behat\\Gherkin\\Node\\TableNode', $arguments[1]); }
/** * @param StepNode $step * * @return string */ private function getArguments(StepNode $step) { if (!$step->hasArguments()) { return; } return implode(array_map(function (ArgumentInterface $argument) { if (in_array($argument->getNodeType(), ['Table', 'ExampleTable'])) { return implode(array_map(function ($arguments) { return $this->indent(self::INDENTATION * 2 + 4) . trim($arguments) . "\n"; }, explode("\n", $argument->getTableAsString()))); } if ('PyString' === $argument->getNodeType()) { return $this->encapsulateAsPyString(implode(array_map(function ($arguments) { return rtrim($this->indent(self::INDENTATION * 2 + 2) . trim($arguments)) . "\n"; }, $argument->getStrings()))); } }, $step->getArguments())); }
protected function runStep(StepNode $stepNode) { $params = []; if ($stepNode->hasArguments()) { $args = $stepNode->getArguments(); $table = $args[0]; if ($table instanceof TableNode) { $params = [$table->getTableAsString()]; } } $meta = new Meta($stepNode->getText(), $params); $meta->setPrefix($stepNode->getKeyword()); $this->scenario->setMetaStep($meta); // enable metastep $stepText = $stepNode->getText(); $this->getScenario()->comment(null); // make metastep to be printed even if no steps foreach ($this->steps as $pattern => $context) { $matches = []; if (!preg_match($pattern, $stepText, $matches)) { continue; } array_shift($matches); if ($stepNode->hasArguments()) { $matches = array_merge($matches, $stepNode->getArguments()); } call_user_func_array($context, $matches); // execute the step break; } $this->scenario->setMetaStep(null); // disable metastep }