Pull merge.
[yaffs-website] / vendor / consolidation / log / tests / testLoggerVerbosityAndStyles.php
1 <?php
2 namespace Consolidation\Log;
3
4 use Psr\Log\LogLevel;
5 use Symfony\Component\Console\Output\BufferedOutput;
6 use Symfony\Component\Console\Output\OutputInterface;
7
8 use Consolidation\TestUtils\TestDataPermuter;
9
10 class LoggerVerbosityAndStyleTests extends \PHPUnit_Framework_TestCase
11 {
12   protected $output;
13   protected $logger;
14
15   function setup() {
16     $this->output = new BufferedOutput();
17     //$this->output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE);
18     $this->logger = new Logger($this->output);
19   }
20
21   public static function logTestValues()
22   {
23     /**
24      * Use TEST_ALL_LOG_LEVELS to ensure that output is the same
25      * in instances where the output does not vary by log level.
26      */
27     $TEST_ALL_LOG_LEVELS = [
28       OutputInterface::VERBOSITY_DEBUG,
29       OutputInterface::VERBOSITY_VERY_VERBOSE,
30       OutputInterface::VERBOSITY_VERBOSE,
31       OutputInterface::VERBOSITY_NORMAL
32     ];
33
34     // Tests that return the same value for multiple inputs
35     // may use the expandProviderDataArrays method, and list
36     // repeated scalars as array values.  All permutations of
37     // all array items will be calculated, and one test will
38     // be generated for each one.
39     return TestDataPermuter::expandProviderDataArrays([
40       [
41         '\Consolidation\Log\UnstyledLogOutputStyler',
42         $TEST_ALL_LOG_LEVELS,
43         LogLevel::ERROR,
44         'Do not enter - wrong way.',
45         ' [error] Do not enter - wrong way.',
46       ],
47       [
48         '\Consolidation\Log\UnstyledLogOutputStyler',
49         $TEST_ALL_LOG_LEVELS,
50         LogLevel::WARNING,
51         'Steep grade.',
52         ' [warning] Steep grade.',
53       ],
54       [
55         '\Consolidation\Log\UnstyledLogOutputStyler',
56         [
57           OutputInterface::VERBOSITY_DEBUG,
58           OutputInterface::VERBOSITY_VERY_VERBOSE,
59           OutputInterface::VERBOSITY_VERBOSE,
60         ],
61         LogLevel::NOTICE,
62         'No loitering.',
63         ' [notice] No loitering.',
64       ],
65       [
66         '\Consolidation\Log\UnstyledLogOutputStyler',
67         OutputInterface::VERBOSITY_NORMAL,
68         LogLevel::NOTICE,
69         'No loitering.',
70         '',
71       ],
72       [
73         '\Consolidation\Log\UnstyledLogOutputStyler',
74         OutputInterface::VERBOSITY_DEBUG,
75         LogLevel::INFO,
76         'Scenic route.',
77         ' [info] Scenic route.',
78       ],
79       [
80         '\Consolidation\Log\UnstyledLogOutputStyler',
81         OutputInterface::VERBOSITY_DEBUG,
82         LogLevel::DEBUG,
83         'Counter incremented.',
84         ' [debug] Counter incremented.',
85       ],
86       [
87         '\Consolidation\Log\UnstyledLogOutputStyler',
88         [
89           OutputInterface::VERBOSITY_VERY_VERBOSE,
90           OutputInterface::VERBOSITY_VERBOSE,
91           OutputInterface::VERBOSITY_NORMAL
92         ],
93         LogLevel::DEBUG,
94         'Counter incremented.',
95         '',
96       ],
97       [
98         '\Consolidation\Log\UnstyledLogOutputStyler',
99         $TEST_ALL_LOG_LEVELS,
100         ConsoleLogLevel::SUCCESS,
101         'It worked!',
102         ' [success] It worked!',
103       ],
104       [
105         '\Consolidation\Log\LogOutputStyler',
106         OutputInterface::VERBOSITY_NORMAL,
107         ConsoleLogLevel::SUCCESS,
108         'It worked!',
109         ' [success] It worked!',
110       ],
111       [
112         '\Consolidation\Log\SymfonyLogOutputStyler',
113         OutputInterface::VERBOSITY_DEBUG,
114         LogLevel::WARNING,
115         'Steep grade.',
116         "\n [WARNING] Steep grade.",
117       ],
118       [
119         '\Consolidation\Log\SymfonyLogOutputStyler',
120         OutputInterface::VERBOSITY_DEBUG,
121         LogLevel::NOTICE,
122         'No loitering.',
123         "\n ! [NOTE] No loitering.",
124       ],
125       [
126         '\Consolidation\Log\SymfonyLogOutputStyler',
127         OutputInterface::VERBOSITY_DEBUG,
128         LogLevel::INFO,
129         'Scenic route.',
130         "\n ! [NOTE] Scenic route.",
131       ],
132       [
133         '\Consolidation\Log\SymfonyLogOutputStyler',
134         OutputInterface::VERBOSITY_DEBUG,
135         LogLevel::DEBUG,
136         'Counter incremented.',
137         "\n ! [NOTE] Counter incremented.",
138       ],
139       [
140         '\Consolidation\Log\SymfonyLogOutputStyler',
141         OutputInterface::VERBOSITY_NORMAL,
142         ConsoleLogLevel::SUCCESS,
143         'It worked!',
144         "\n [OK] It worked!",
145       ],
146     ]);
147   }
148
149   /**
150    * This is our only test method. It accepts all of the
151    * permuted data from the data provider, and runs one
152    * test on each one.
153    *
154    * @dataProvider logTestValues
155    */
156   function testLogging($styleClass, $verbocity, $level, $message, $expected) {
157     $logStyler = new $styleClass;
158     $this->logger->setLogOutputStyler($logStyler);
159     $this->output->setVerbosity($verbocity);
160     $this->logger->log($level, $message);
161     $outputText = rtrim($this->output->fetch(), "\n\r\t ");
162     $this->assertEquals($expected, $outputText);
163   }
164 }