/** * If steps are combined into one method they can be reproduced as meta-step. * We are using stack trace to analyze if steps were called from test, if not - they were called from meta-step. * * @param $step * @param $stack */ protected function addMetaStep($step, $stack) { if ($this->isTestFile($this->file) || $step['class'] == 'Codeception\\Scenario') { return; } $i = count($stack) - self::STACK_POSITION - 1; // get into test file and retrieve its actual call while (isset($stack[$i])) { $step = $stack[$i]; $i--; if (!isset($step['file']) or !isset($step['function'])) { continue; } if (!$this->isTestFile($step['file'])) { continue; } $this->metaStep = new Meta($step['function'], array_values($step['params'])); $this->metaStep->setTraceInfo($step['file'], $step['line']); // pageobjects or other classes should not be included with "I" if (!(new \ReflectionClass($step['class']))->isSubclassOf('Codeception\\Actor')) { $this->metaStep->setActor($step['class'] . ':'); } return; } }
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 }
/** * @param $metaStep * @param $substepsBuffer * @return string */ protected function renderSubsteps(Meta $metaStep, $substepsBuffer) { $metaTemplate = new \Text_Template($this->templatePath . 'substeps.html'); $metaTemplate->setVar(['metaStep' => $metaStep, 'error' => $metaStep->hasFailed() ? 'failedStep' : '', 'steps' => $substepsBuffer, 'id' => uniqid()]); return $metaTemplate->render(); }