2 namespace Consolidation\Log;
5 use Symfony\Component\Console\Output\BufferedOutput;
6 use Symfony\Component\Console\Output\OutputInterface;
8 use Consolidation\TestUtils\TestDataPermuter;
10 class LoggerVerbosityAndStyleTests extends \PHPUnit_Framework_TestCase
16 $this->output = new BufferedOutput();
17 //$this->output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE);
18 $this->logger = new Logger($this->output);
21 public static function logTestValues()
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.
27 $TEST_ALL_LOG_LEVELS = [
28 OutputInterface::VERBOSITY_DEBUG,
29 OutputInterface::VERBOSITY_VERY_VERBOSE,
30 OutputInterface::VERBOSITY_VERBOSE,
31 OutputInterface::VERBOSITY_NORMAL
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([
41 '\Consolidation\Log\UnstyledLogOutputStyler',
44 'Do not enter - wrong way.',
45 ' [error] Do not enter - wrong way.',
48 '\Consolidation\Log\UnstyledLogOutputStyler',
52 ' [warning] Steep grade.',
55 '\Consolidation\Log\UnstyledLogOutputStyler',
57 OutputInterface::VERBOSITY_DEBUG,
58 OutputInterface::VERBOSITY_VERY_VERBOSE,
59 OutputInterface::VERBOSITY_VERBOSE,
63 ' [notice] No loitering.',
66 '\Consolidation\Log\UnstyledLogOutputStyler',
67 OutputInterface::VERBOSITY_NORMAL,
73 '\Consolidation\Log\UnstyledLogOutputStyler',
74 OutputInterface::VERBOSITY_DEBUG,
77 ' [info] Scenic route.',
80 '\Consolidation\Log\UnstyledLogOutputStyler',
81 OutputInterface::VERBOSITY_DEBUG,
83 'Counter incremented.',
84 ' [debug] Counter incremented.',
87 '\Consolidation\Log\UnstyledLogOutputStyler',
89 OutputInterface::VERBOSITY_VERY_VERBOSE,
90 OutputInterface::VERBOSITY_VERBOSE,
91 OutputInterface::VERBOSITY_NORMAL
94 'Counter incremented.',
98 '\Consolidation\Log\UnstyledLogOutputStyler',
100 ConsoleLogLevel::SUCCESS,
102 ' [success] It worked!',
105 '\Consolidation\Log\LogOutputStyler',
106 OutputInterface::VERBOSITY_NORMAL,
107 ConsoleLogLevel::SUCCESS,
109 ' [success] It worked!',
112 '\Consolidation\Log\SymfonyLogOutputStyler',
113 OutputInterface::VERBOSITY_DEBUG,
116 "\n [WARNING] Steep grade.",
119 '\Consolidation\Log\SymfonyLogOutputStyler',
120 OutputInterface::VERBOSITY_DEBUG,
123 "\n ! [NOTE] No loitering.",
126 '\Consolidation\Log\SymfonyLogOutputStyler',
127 OutputInterface::VERBOSITY_DEBUG,
130 "\n ! [NOTE] Scenic route.",
133 '\Consolidation\Log\SymfonyLogOutputStyler',
134 OutputInterface::VERBOSITY_DEBUG,
136 'Counter incremented.',
137 "\n ! [NOTE] Counter incremented.",
140 '\Consolidation\Log\SymfonyLogOutputStyler',
141 OutputInterface::VERBOSITY_NORMAL,
142 ConsoleLogLevel::SUCCESS,
144 "\n [OK] It worked!",
150 * This is our only test method. It accepts all of the
151 * permuted data from the data provider, and runs one
154 * @dataProvider logTestValues
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);