Security update for permissions_by_term
[yaffs-website] / vendor / behat / behat / src / Behat / Behat / Output / ServiceContainer / Formatter / ProgressFormatterFactory.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\ServiceContainer\Formatter;
12
13 use Behat\Testwork\Exception\ServiceContainer\ExceptionExtension;
14 use Behat\Testwork\Output\ServiceContainer\Formatter\FormatterFactory;
15 use Behat\Testwork\Output\ServiceContainer\OutputExtension;
16 use Behat\Testwork\ServiceContainer\ServiceProcessor;
17 use Behat\Testwork\Translator\ServiceContainer\TranslatorExtension;
18 use Symfony\Component\DependencyInjection\ContainerBuilder;
19 use Symfony\Component\DependencyInjection\Definition;
20 use Symfony\Component\DependencyInjection\Reference;
21
22 /**
23  * Behat progress formatter factory.
24  *
25  * @author Konstantin Kudryashov <ever.zet@gmail.com>
26  */
27 class ProgressFormatterFactory implements FormatterFactory
28 {
29     /**
30      * @var ServiceProcessor
31      */
32     private $processor;
33
34     /*
35      * Available services
36      */
37     const ROOT_LISTENER_ID = 'output.node.listener.progress';
38     const RESULT_TO_STRING_CONVERTER_ID = 'output.node.printer.result_to_string';
39
40     /*
41      * Available extension points
42      */
43     const ROOT_LISTENER_WRAPPER_TAG = 'output.node.listener.progress.wrapper';
44
45     /**
46      * Initializes extension.
47      *
48      * @param null|ServiceProcessor $processor
49      */
50     public function __construct(ServiceProcessor $processor = null)
51     {
52         $this->processor = $processor ? : new ServiceProcessor();
53     }
54
55     /**
56      * {@inheritdoc}
57      */
58     public function buildFormatter(ContainerBuilder $container)
59     {
60         $this->loadRootNodeListener($container);
61         $this->loadCorePrinters($container);
62         $this->loadPrinterHelpers($container);
63         $this->loadFormatter($container);
64     }
65
66     /**
67      * {@inheritdoc}
68      */
69     public function processFormatter(ContainerBuilder $container)
70     {
71         $this->processListenerWrappers($container);
72     }
73
74     /**
75      * Loads progress formatter node event listener.
76      *
77      * @param ContainerBuilder $container
78      */
79     protected function loadRootNodeListener(ContainerBuilder $container)
80     {
81         $definition = new Definition('Behat\Behat\Output\Node\EventListener\AST\StepListener', array(
82             new Reference('output.node.printer.progress.step')
83         ));
84         $container->setDefinition(self::ROOT_LISTENER_ID, $definition);
85     }
86
87     /**
88      * Loads feature, scenario and step printers.
89      *
90      * @param ContainerBuilder $container
91      */
92     protected function loadCorePrinters(ContainerBuilder $container)
93     {
94         $definition = new Definition('Behat\Behat\Output\Node\Printer\CounterPrinter', array(
95             new Reference(self::RESULT_TO_STRING_CONVERTER_ID),
96             new Reference(TranslatorExtension::TRANSLATOR_ID),
97         ));
98         $container->setDefinition('output.node.printer.counter', $definition);
99
100         $definition = new Definition('Behat\Behat\Output\Node\Printer\ListPrinter', array(
101             new Reference(self::RESULT_TO_STRING_CONVERTER_ID),
102             new Reference(ExceptionExtension::PRESENTER_ID),
103             new Reference(TranslatorExtension::TRANSLATOR_ID),
104             '%paths.base%'
105         ));
106         $container->setDefinition('output.node.printer.list', $definition);
107
108         $definition = new Definition('Behat\Behat\Output\Node\Printer\Progress\ProgressStepPrinter', array(
109             new Reference(self::RESULT_TO_STRING_CONVERTER_ID)
110         ));
111         $container->setDefinition('output.node.printer.progress.step', $definition);
112
113         $definition = new Definition('Behat\Behat\Output\Node\Printer\Progress\ProgressStatisticsPrinter', array(
114             new Reference('output.node.printer.counter'),
115             new Reference('output.node.printer.list')
116         ));
117         $container->setDefinition('output.node.printer.progress.statistics', $definition);
118     }
119
120     /**
121      * Loads printer helpers.
122      *
123      * @param ContainerBuilder $container
124      */
125     protected function loadPrinterHelpers(ContainerBuilder $container)
126     {
127         $definition = new Definition('Behat\Behat\Output\Node\Printer\Helper\ResultToStringConverter');
128         $container->setDefinition(self::RESULT_TO_STRING_CONVERTER_ID, $definition);
129     }
130
131     /**
132      * Loads formatter itself.
133      *
134      * @param ContainerBuilder $container
135      */
136     protected function loadFormatter(ContainerBuilder $container)
137     {
138         $definition = new Definition('Behat\Behat\Output\Statistics\TotalStatistics');
139         $container->setDefinition('output.progress.statistics', $definition);
140
141         $definition = new Definition('Behat\Testwork\Output\NodeEventListeningFormatter', array(
142             'progress',
143             'Prints one character per step.',
144             array(
145                 'timer' => true
146             ),
147             $this->createOutputPrinterDefinition(),
148             new Definition('Behat\Testwork\Output\Node\EventListener\ChainEventListener', array(
149                     array(
150                         new Reference(self::ROOT_LISTENER_ID),
151                         new Definition('Behat\Behat\Output\Node\EventListener\Statistics\StatisticsListener', array(
152                             new Reference('output.progress.statistics'),
153                             new Reference('output.node.printer.progress.statistics')
154                         )),
155                         new Definition('Behat\Behat\Output\Node\EventListener\Statistics\ScenarioStatsListener', array(
156                             new Reference('output.progress.statistics')
157                         )),
158                         new Definition('Behat\Behat\Output\Node\EventListener\Statistics\StepStatsListener', array(
159                             new Reference('output.progress.statistics'),
160                             new Reference(ExceptionExtension::PRESENTER_ID)
161                         )),
162                         new Definition('Behat\Behat\Output\Node\EventListener\Statistics\HookStatsListener', array(
163                             new Reference('output.progress.statistics'),
164                             new Reference(ExceptionExtension::PRESENTER_ID)
165                         )),
166                     )
167                 )
168             )
169         ));
170         $definition->addTag(OutputExtension::FORMATTER_TAG, array('priority' => 100));
171         $container->setDefinition(OutputExtension::FORMATTER_TAG . '.progress', $definition);
172     }
173
174     /**
175      * Creates output printer definition.
176      *
177      * @return Definition
178      */
179     protected function createOutputPrinterDefinition()
180     {
181         return new Definition('Behat\Testwork\Output\Printer\StreamOutputPrinter', array(
182             new Definition('Behat\Behat\Output\Printer\ConsoleOutputFactory'),
183         ));
184     }
185
186     /**
187      * Processes all registered pretty formatter node listener wrappers.
188      *
189      * @param ContainerBuilder $container
190      */
191     protected function processListenerWrappers(ContainerBuilder $container)
192     {
193         $this->processor->processWrapperServices($container, self::ROOT_LISTENER_ID, self::ROOT_LISTENER_WRAPPER_TAG);
194     }
195 }