X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FOutput%2FNode%2FPrinter%2FPretty%2FPrettyPathPrinter.php;fp=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FBehat%2FOutput%2FNode%2FPrinter%2FPretty%2FPrettyPathPrinter.php;h=9ea0b684ac8128e9c81d62a61b85ede174e50325;hp=0000000000000000000000000000000000000000;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68 diff --git a/vendor/behat/behat/src/Behat/Behat/Output/Node/Printer/Pretty/PrettyPathPrinter.php b/vendor/behat/behat/src/Behat/Behat/Output/Node/Printer/Pretty/PrettyPathPrinter.php new file mode 100644 index 000000000..9ea0b684a --- /dev/null +++ b/vendor/behat/behat/src/Behat/Behat/Output/Node/Printer/Pretty/PrettyPathPrinter.php @@ -0,0 +1,137 @@ + + * + * 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\WidthCalculator; +use Behat\Behat\Tester\Result\DefinedStepResult; +use Behat\Behat\Tester\Result\StepResult; +use Behat\Gherkin\Node\FeatureNode; +use Behat\Gherkin\Node\ScenarioLikeInterface as Scenario; +use Behat\Gherkin\Node\StepNode; +use Behat\Testwork\Output\Formatter; +use Behat\Testwork\Output\Printer\OutputPrinter; + +/** + * Prints paths for scenarios, examples, backgrounds and steps. + * + * @author Konstantin Kudryashov + */ +final class PrettyPathPrinter +{ + /** + * @var WidthCalculator + */ + private $widthCalculator; + /** + * @var string + */ + private $basePath; + + /** + * Initializes printer. + * + * @param WidthCalculator $widthCalculator + * @param string $basePath + */ + public function __construct(WidthCalculator $widthCalculator, $basePath) + { + $this->widthCalculator = $widthCalculator; + $this->basePath = $basePath; + } + + /** + * Prints scenario path comment. + * + * @param Formatter $formatter + * @param FeatureNode $feature + * @param Scenario $scenario + * @param integer $indentation + */ + public function printScenarioPath(Formatter $formatter, FeatureNode $feature, Scenario $scenario, $indentation) + { + $printer = $formatter->getOutputPrinter(); + + if (!$formatter->getParameter('paths')) { + $printer->writeln(); + + return; + } + + $fileAndLine = sprintf('%s:%s', $this->relativizePaths($feature->getFile()), $scenario->getLine()); + $headerWidth = $this->widthCalculator->calculateScenarioHeaderWidth($scenario, $indentation); + $scenarioWidth = $this->widthCalculator->calculateScenarioWidth($scenario, $indentation, 2); + $spacing = str_repeat(' ', max(0, $scenarioWidth - $headerWidth)); + + $printer->writeln(sprintf('%s {+comment}# %s{-comment}', $spacing, $fileAndLine)); + } + + /** + * Prints step path comment. + * + * @param Formatter $formatter + * @param Scenario $scenario + * @param StepNode $step + * @param StepResult $result + * @param integer $indentation + */ + public function printStepPath( + Formatter $formatter, + Scenario $scenario, + StepNode $step, + StepResult $result, + $indentation + ) { + $printer = $formatter->getOutputPrinter(); + + if (!$result instanceof DefinedStepResult || !$result->getStepDefinition() || !$formatter->getParameter('paths')) { + $printer->writeln(); + + return; + } + + $textWidth = $this->widthCalculator->calculateStepWidth($step, $indentation); + $scenarioWidth = $this->widthCalculator->calculateScenarioWidth($scenario, $indentation - 2, 2); + + $this->printDefinedStepPath($printer, $result, $scenarioWidth, $textWidth); + } + + /** + * Prints defined step path. + * + * @param OutputPrinter $printer + * @param DefinedStepResult $result + * @param integer $scenarioWidth + * @param integer $stepWidth + */ + private function printDefinedStepPath(OutputPrinter $printer, DefinedStepResult $result, $scenarioWidth, $stepWidth) + { + $path = $result->getStepDefinition()->getPath(); + $spacing = str_repeat(' ', max(0, $scenarioWidth - $stepWidth)); + + $printer->writeln(sprintf('%s {+comment}# %s{-comment}', $spacing, $path)); + } + + /** + * Transforms path to relative. + * + * @param string $path + * + * @return string + */ + private function relativizePaths($path) + { + if (!$this->basePath) { + return $path; + } + + return str_replace($this->basePath . DIRECTORY_SEPARATOR, '', $path); + } +}