Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Output / Node / Printer / CounterPrinter.php
1 <?php
2
3 /*
4  * This file is part of the Behat.
5  * (c) Konstantin Kudryashov <ever.zet@gmail.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 namespace Behat\Behat\Output\Node\Printer;
12
13 use Behat\Behat\Output\Node\Printer\Helper\ResultToStringConverter;
14 use Behat\Testwork\Output\Printer\OutputPrinter;
15 use Symfony\Component\Translation\TranslatorInterface;
16
17 /**
18  * Behat counter printer.
19  *
20  * @author Konstantin Kudryashov <ever.zet@gmail.com>
21  */
22 final class CounterPrinter
23 {
24     /**
25      * @var ResultToStringConverter
26      */
27     private $resultConverter;
28     /**
29      * @var TranslatorInterface
30      */
31     private $translator;
32
33     /**
34      * Initializes printer.
35      *
36      * @param ResultToStringConverter $resultConverter
37      * @param TranslatorInterface     $translator
38      */
39     public function __construct(ResultToStringConverter $resultConverter, TranslatorInterface $translator)
40     {
41         $this->resultConverter = $resultConverter;
42         $this->translator = $translator;
43     }
44
45     /**
46      * Prints scenario and step counters.
47      *
48      * @param OutputPrinter $printer
49      * @param string        $intro
50      * @param array         $stats
51      */
52     public function printCounters(OutputPrinter $printer, $intro, array $stats)
53     {
54         $stats = array_filter($stats, function ($count) { return 0 !== $count; });
55
56         if (0 === count($stats)) {
57             $totalCount = 0;
58         } else {
59             $totalCount = array_sum($stats);
60         }
61
62         $detailedStats = array();
63         foreach ($stats as $resultCode => $count) {
64             $style = $this->resultConverter->convertResultCodeToString($resultCode);
65
66             $transId = $style . '_count';
67             $message = $this->translator->transChoice($transId, $count, array('%1%' => $count), 'output');
68
69             $detailedStats[] = sprintf('{+%s}%s{-%s}', $style, $message, $style);
70         }
71
72         $message = $this->translator->transChoice($intro, $totalCount, array('%1%' => $totalCount), 'output');
73         $printer->write($message);
74
75         if (count($detailedStats)) {
76             $printer->write(sprintf(' (%s)', implode(', ', $detailedStats)));
77         }
78
79         $printer->writeln();
80     }
81 }