X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FTestwork%2FOutput%2FPrinter%2FFactory%2FConsoleOutputFactory.php;fp=vendor%2Fbehat%2Fbehat%2Fsrc%2FBehat%2FTestwork%2FOutput%2FPrinter%2FFactory%2FConsoleOutputFactory.php;h=e1d22ee185401044da99e66eef01306b212c10db;hp=0000000000000000000000000000000000000000;hb=1270d9129ce8f27c9b28b10518e32132c58e0aca;hpb=c27c0f0cdaa3f354b1fe54a56ae7e854be6e3f68 diff --git a/vendor/behat/behat/src/Behat/Testwork/Output/Printer/Factory/ConsoleOutputFactory.php b/vendor/behat/behat/src/Behat/Testwork/Output/Printer/Factory/ConsoleOutputFactory.php new file mode 100644 index 000000000..e1d22ee18 --- /dev/null +++ b/vendor/behat/behat/src/Behat/Testwork/Output/Printer/Factory/ConsoleOutputFactory.php @@ -0,0 +1,112 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Behat\Testwork\Output\Printer\Factory; + +use Behat\Testwork\Output\Exception\BadOutputPathException; +use Symfony\Component\Console\Formatter\OutputFormatter; +use Symfony\Component\Console\Formatter\OutputFormatterStyle; +use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Console\Output\StreamOutput; + +/** + * Creates an output stream for the console. + * + * @author Wouter J + * @author Konstantin Kudryashov + */ +class ConsoleOutputFactory extends OutputFactory +{ + /** + * Creates output formatter that is used to create a stream. + * + * @return OutputFormatter + */ + protected function createOutputFormatter() + { + return new OutputFormatter(); + } + + /** + * Configure output stream parameters. + * + * @param OutputInterface $output + */ + protected function configureOutputStream(OutputInterface $output) + { + $verbosity = $this->getOutputVerbosity() ? OutputInterface::VERBOSITY_VERBOSE : OutputInterface::VERBOSITY_NORMAL; + $output->setVerbosity($verbosity); + + if (null !== $this->isOutputDecorated()) { + $output->getFormatter()->setDecorated($this->isOutputDecorated()); + } + } + + /** + * Returns new output stream. + * + * Override this method & call flush() to write output in another stream + * + * @return resource + * + * @throws BadOutputPathException + */ + protected function createOutputStream() + { + if (null === $this->getOutputPath()) { + $stream = fopen('php://stdout', 'w'); + } elseif (!is_dir($this->getOutputPath())) { + $stream = fopen($this->getOutputPath(), 'w'); + } else { + throw new BadOutputPathException(sprintf( + 'Filename expected as `output_path` parameter, but got `%s`.', + $this->getOutputPath() + ), $this->getOutputPath()); + } + + return $stream; + } + + /** + * {@inheritdoc} + */ + public function createOutput($stream = null) + { + $stream = $stream ? : $this->createOutputStream(); + $format = $this->createOutputFormatter(); + + // set user-defined styles + foreach ($this->getOutputStyles() as $name => $options) { + $style = new OutputFormatterStyle(); + + if (isset($options[0])) { + $style->setForeground($options[0]); + } + if (isset($options[1])) { + $style->setBackground($options[1]); + } + if (isset($options[2])) { + $style->setOptions($options[2]); + } + + $format->setStyle($name, $style); + } + + $output = new StreamOutput( + $stream, + StreamOutput::VERBOSITY_NORMAL, + $this->isOutputDecorated(), + $format + ); + $this->configureOutputStream($output); + + return $output; + } +}