From c35c4ccbf39a5910530d6cf9b4f5dba45dbf82b0 Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Tue, 19 Sep 2017 20:40:48 +0200 Subject: [PATCH] Refactoring: Logger test cleanup --- .../Feature/Logger/EngelsystemLoggerTest.php | 72 +++++++++++-------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/tests/Feature/Logger/EngelsystemLoggerTest.php b/tests/Feature/Logger/EngelsystemLoggerTest.php index 3b6572f5..63a01318 100644 --- a/tests/Feature/Logger/EngelsystemLoggerTest.php +++ b/tests/Feature/Logger/EngelsystemLoggerTest.php @@ -28,23 +28,6 @@ class EngelsystemLoggerTest extends TestCase $this->assertInstanceOf('Psr\Log\LoggerInterface', $this->getLogger()); } - /** - * @dataProvider provideLogLevels - * @param string $level - */ - public function testAllLevels($level) - { - $logger = $this->getLogger(); - - LogEntries_clear_all(); - - $logger->log($level, 'First log message'); - $logger->{$level}('Second log message'); - - $entries = LogEntries(); - $this->assertCount(2, $entries); - } - /** * @return string[] */ @@ -62,6 +45,23 @@ class EngelsystemLoggerTest extends TestCase ]; } + /** + * @dataProvider provideLogLevels + * @param string $level + */ + public function testAllLevels($level) + { + $logger = $this->getLogger(); + + LogEntries_clear_all(); + + $logger->log($level, 'First log message'); + $logger->{$level}('Second log message'); + + $entries = LogEntries(); + $this->assertCount(2, $entries); + } + public function testContextReplacement() { $logger = $this->getLogger(); @@ -72,21 +72,35 @@ class EngelsystemLoggerTest extends TestCase $entry = $this->getLastEntry(); $this->assertEquals('My username is Foo', $entry['message']); $this->assertEquals(LogLevel::INFO, $entry['level']); + } - foreach ( - [ - ['Data and {context}', []], - ['Data and ', ['context' => null]], - ['Data and {context}', ['context' => new \stdClass()]], - ] as $data - ) { - list($result, $context) = $data; + /** + * @return string[] + */ + public function provideContextReplaceValues() + { + return [ + ['Data and {context}', [], 'Data and {context}'], + ['Data and {context}', ['context' => null], 'Data and '], + ['Data and {context}', ['context' => new \stdClass()], 'Data and {context}'], + ['Some user asked: {question}', ['question' => 'Foo?'], 'Some user asked: Foo?'], + ]; + } - $logger->log(LogLevel::INFO, 'Data and {context}', $context); + /** + * @dataProvider provideContextReplaceValues + * + * @param string $message + * @param string[] $context + * @param string $expected + */ + public function testContextReplaceValues($message, $context, $expected) + { + $logger = $this->getLogger(); + $logger->log(LogLevel::INFO, $message, $context); - $entry = $this->getLastEntry(); - $this->assertEquals($result, $entry['message']); - } + $entry = $this->getLastEntry(); + $this->assertEquals($expected, $entry['message']); } public function testContextToString()