X-Git-Url: http://www.aleph1.co.uk/gitweb/?a=blobdiff_plain;ds=sidebyside;f=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FOutput%2FNode%2FPrinter%2FPretty%2FPrettyOutlinePrinter.php;fp=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FOutput%2FNode%2FPrinter%2FPretty%2FPrettyOutlinePrinter.php;h=8fbc03392211c74d833558ae7490d4d3113ef905;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hp=0000000000000000000000000000000000000000;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68;p=yaffs-website diff --git a/vendor/behat/behat/src/Behat/Behat/Output/Node/Printer/Pretty/PrettyOutlinePrinter.php b/vendor/behat/behat/src/Behat/Behat/Output/Node/Printer/Pretty/PrettyOutlinePrinter.php new file mode 100644 index 000000000..8fbc03392 --- /dev/null +++ b/vendor/behat/behat/src/Behat/Behat/Output/Node/Printer/Pretty/PrettyOutlinePrinter.php @@ -0,0 +1,140 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Behat\Behat\Output\Node\Printer\Pretty; + +use Behat\Behat\Output\Node\Printer\Helper\ResultToStringConverter; +use Behat\Behat\Output\Node\Printer\OutlinePrinter; +use Behat\Behat\Output\Node\Printer\ScenarioPrinter; +use Behat\Behat\Output\Node\Printer\StepPrinter; +use Behat\Behat\Tester\Result\UndefinedStepResult; +use Behat\Gherkin\Node\ExampleTableNode; +use Behat\Gherkin\Node\FeatureNode; +use Behat\Gherkin\Node\OutlineNode; +use Behat\Gherkin\Node\StepNode; +use Behat\Testwork\Output\Formatter; +use Behat\Testwork\Output\Printer\OutputPrinter; +use Behat\Testwork\Tester\Result\TestResult; + +/** + * Prints outline header with outline steps and table header. + * + * @author Konstantin Kudryashov + */ +final class PrettyOutlinePrinter implements OutlinePrinter +{ + /** + * @var ScenarioPrinter + */ + private $scenarioPrinter; + /** + * @var StepPrinter + */ + private $stepPrinter; + /** + * @var ResultToStringConverter + */ + private $resultConverter; + /** + * @var string + */ + private $indentText; + /** + * @var string + */ + private $subIndentText; + + /** + * @param ScenarioPrinter $scenarioPrinter + * @param StepPrinter $stepPrinter + * @param ResultToStringConverter $resultConverter + * @param integer $indentation + * @param integer $subIndentation + */ + public function __construct( + ScenarioPrinter $scenarioPrinter, + StepPrinter $stepPrinter, + ResultToStringConverter $resultConverter, + $indentation = 4, + $subIndentation = 2 + ) { + $this->scenarioPrinter = $scenarioPrinter; + $this->stepPrinter = $stepPrinter; + $this->resultConverter = $resultConverter; + $this->indentText = str_repeat(' ', intval($indentation)); + $this->subIndentText = $this->indentText . str_repeat(' ', intval($subIndentation)); + } + + /** + * {@inheritdoc} + */ + public function printHeader(Formatter $formatter, FeatureNode $feature, OutlineNode $outline) + { + $this->scenarioPrinter->printHeader($formatter, $feature, $outline); + + $this->printExamplesSteps($formatter, $outline, $outline->getSteps()); + $this->printExamplesTableHeader($formatter->getOutputPrinter(), $outline->getExampleTable()); + } + + /** + * {@inheritdoc} + */ + public function printFooter(Formatter $formatter, TestResult $result) + { + $formatter->getOutputPrinter()->writeln(); + } + + /** + * Prints outline steps. + * + * @param Formatter $formatter + * @param OutlineNode $outline + * @param StepNode[] $steps + */ + private function printExamplesSteps(Formatter $formatter, OutlineNode $outline, array $steps) + { + foreach ($steps as $step) { + $this->stepPrinter->printStep($formatter, $outline, $step, new UndefinedStepResult()); + } + + $formatter->getOutputPrinter()->writeln(); + } + + /** + * Prints examples table header. + * + * @param OutputPrinter $printer + * @param ExampleTableNode $table + */ + private function printExamplesTableHeader(OutputPrinter $printer, ExampleTableNode $table) + { + $printer->writeln(sprintf('%s{+keyword}%s:{-keyword}', $this->indentText, $table->getKeyword())); + + $rowNum = 0; + $wrapper = $this->getWrapperClosure(); + $row = $table->getRowAsStringWithWrappedValues($rowNum, $wrapper); + + $printer->writeln(sprintf('%s%s', $this->subIndentText, $row)); + } + + /** + * Creates wrapper-closure for the example header. + * + * @return callable + */ + private function getWrapperClosure() + { + $style = $this->resultConverter->convertResultCodeToString(TestResult::SKIPPED); + + return function ($col) use ($style) { + return sprintf('{+%s_param}%s{-%s_param}', $style, $col, $style); + }; + } +}