summaryrefslogtreecommitdiff
path: root/tests/Unit/Logger/EngelsystemLoggerTest.php
diff options
context:
space:
mode:
authorIgor Scheller <igor.scheller@igorshp.de>2019-07-16 02:59:33 +0200
committerIgor Scheller <igor.scheller@igorshp.de>2019-07-16 02:59:33 +0200
commitb9cb7d57fdea7246f536204fd0f267380434aa09 (patch)
tree82e3e5a7760ed0ac2c44fccc656090bcd5a8e10f /tests/Unit/Logger/EngelsystemLoggerTest.php
parent6ca0e8e81afed52fa211dd4bcb117cfec9ce3b29 (diff)
Basic coverage tests of logger classes for 100% unit tests coverage
Diffstat (limited to 'tests/Unit/Logger/EngelsystemLoggerTest.php')
-rw-r--r--tests/Unit/Logger/EngelsystemLoggerTest.php72
1 files changed, 72 insertions, 0 deletions
diff --git a/tests/Unit/Logger/EngelsystemLoggerTest.php b/tests/Unit/Logger/EngelsystemLoggerTest.php
new file mode 100644
index 00000000..0f4c8c32
--- /dev/null
+++ b/tests/Unit/Logger/EngelsystemLoggerTest.php
@@ -0,0 +1,72 @@
+<?php
+
+namespace Engelsystem\Test\Unit\Logger;
+
+use Engelsystem\Logger\EngelsystemLogger;
+use Engelsystem\Models\LogEntry;
+use Engelsystem\Test\Unit\ServiceProviderTest;
+use InvalidArgumentException;
+use PHPUnit\Framework\MockObject\MockObject;
+use Psr\Log\LogLevel;
+
+class EngelsystemLoggerTest extends ServiceProviderTest
+{
+ /**
+ * @covers \Engelsystem\Logger\EngelsystemLogger::__construct
+ * @covers \Engelsystem\Logger\EngelsystemLogger::log
+ */
+ public function testLog()
+ {
+ /** @var LogEntry|MockObject $logEntry */
+ $logEntry = $this->createMock(LogEntry::class);
+ $logEntry->expects($this->once())
+ ->method('create')
+ ->with(['level' => LogLevel::INFO, 'message' => 'I\'m an information!']);
+
+ $logger = new EngelsystemLogger($logEntry);
+
+ $logger->log(LogLevel::INFO, 'I\'m an information!');
+ }
+
+ /**
+ * @covers \Engelsystem\Logger\EngelsystemLogger::log
+ * @covers \Engelsystem\Logger\EngelsystemLogger::checkLevel
+ */
+ public function testCheckLevel()
+ {
+ /** @var LogEntry|MockObject $logEntry */
+ $logEntry = $this->createMock(LogEntry::class);
+ $logger = new EngelsystemLogger($logEntry);
+
+ $this->expectException(InvalidArgumentException::class);
+ $logger->log('FooBar', 'Random Stuff');
+ }
+
+ /**
+ * @covers \Engelsystem\Logger\EngelsystemLogger::interpolate
+ */
+ public function testInterpolate()
+ {
+ /** @var LogEntry|MockObject $logEntry */
+ $logEntry = $this->createMock(LogEntry::class);
+ $logEntry->expects($this->exactly(3))
+ ->method('create')
+ ->withConsecutive(
+ [['level' => LogLevel::DEBUG, 'message' => 'User: Foo']],
+ [['level' => LogLevel::NOTICE, 'message' => 'User: {user}']],
+ [['level' => LogLevel::NOTICE, 'message' => 'User: Bar']]
+ );
+
+ $logger = new EngelsystemLogger($logEntry);
+
+ $logger->log(LogLevel::DEBUG, 'User: {user}', ['user' => 'Foo']);
+ $logger->log(LogLevel::NOTICE, 'User: {user}', ['user' => ['name' => 'Lorem']]);
+ $logger->log(LogLevel::NOTICE, 'User: {user}', [
+ 'user' =>
+ new class
+ {
+ public function __toString() { return 'Bar'; }
+ }
+ ]);
+ }
+}