/** * Retrieve the parameters from the context according to their name in the callback function * * @param TestSuite $context * @param bool $with_names * * @return array */ public function parameters($context, $with_names = true) { $parameters = $this->reflection->getParameters(); $call_parameters = []; foreach ($parameters as $i => $param) { $call_parameters[$i] =& $context->get_value($param->getName()); if ($with_names) { $call_parameters[$param->getName()] =& $call_parameters[$i]; } } return $call_parameters; }
/** * Render a failing test * * @param int $n * @param string $label * * @return void */ public function render($n, $label) { echo PHP_EOL . PHP_EOL; $red = chr(27) . '[31m'; $blue = chr(27) . '[34m'; $white = chr(27) . '[0m'; $completeLabel = ''; if ($label !== null) { $labels = $this->context->labels(); foreach ($labels as $i => $l) { if (!$l->isEmpty()) { $completeLabel .= ' ' . $l . ' -> ' . $this->context->get_value($i) . PHP_EOL; } } $completeLabel .= ' Then ' . $label . PHP_EOL; } echo <<<FAILURE {$n}) {$this->context->description()} Then { {$this->callback->code()} } {$red}Failure/Error: Then { {$this->callback->code()} } {$completeLabel} Then expression failed at {$this->callback->file()}:{$this->callback->line()} FAILURE; $parameters = $this->callback->parameters($this->context); foreach ($parameters as $i => $parameter) { if (is_int($i)) { continue; } echo PHP_EOL . " {$this->format_value($parameter)} <- {$i}"; } echo $blue; foreach ($this->stack as $error) { echo PHP_EOL . " # {$error['file']}:{$error['line']}:in `{$error['function']}'"; } echo $white; }