From 19bea4042e8d009f7e4b46c4c12373ebd224a562 Mon Sep 17 00:00:00 2001 From: adlawson Date: Sun, 6 Jul 2014 17:33:44 +0100 Subject: [PATCH] Add logger tests --- test/unit/Logger/PhpErrorLoggerTest.php | 110 ++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 test/unit/Logger/PhpErrorLoggerTest.php diff --git a/test/unit/Logger/PhpErrorLoggerTest.php b/test/unit/Logger/PhpErrorLoggerTest.php new file mode 100644 index 0000000..e1d32a0 --- /dev/null +++ b/test/unit/Logger/PhpErrorLoggerTest.php @@ -0,0 +1,110 @@ +logger = new PhpErrorLogger(); + } + + public function dataLog() + { + return [ + ['emergency', 'PHPUnit_Framework_Error'], + ['alert', 'PHPUnit_Framework_Error'], + ['critical', 'PHPUnit_Framework_Error'], + ['error', 'PHPUnit_Framework_Error'], + ['warning', 'PHPUnit_Framework_Error_Warning'], + ['notice', 'PHPUnit_Framework_Error_Notice'], + ['info', 'PHPUnit_Framework_Error_Notice'], + ['debug', 'PHPUnit_Framework_Error_Notice'] + ]; + } + + public function testInterface() + { + $this->assertInstanceOf('Psr\Log\LoggerInterface', $this->logger); + } + + /** + * @dataProvider dataLog + */ + public function testLog($level, $expectation) + { + $this->setExpectedException($expectation); + + $this->logger->log($level, 'foo', []); + } + + public function testLogReplacesPlaceholders() + { + try { + $this->logger->log('debug', 'foo {bar} baz', ['bar' => 'BAR']); + } catch (\PHPUnit_Framework_Error_Notice $e) { + return $this->assertRegexp('/foo BAR baz/', $e->getMessage()); + } + + $this->fail('A PHP Notice should have been triggered'); + } + + public function testEmergency() + { + $this->setExpectedException('PHPUnit_Framework_Error'); + + $this->logger->emergency('foo', []); + } + + public function testAlert() + { + $this->setExpectedException('PHPUnit_Framework_Error'); + + $this->logger->alert('foo', []); + } + + public function testCritical() + { + $this->setExpectedException('PHPUnit_Framework_Error'); + + $this->logger->critical('foo', []); + } + + public function testError() + { + $this->setExpectedException('PHPUnit_Framework_Error'); + + $this->logger->error('foo', []); + } + + public function testWarning() + { + $this->setExpectedException('PHPUnit_Framework_Error_Warning'); + + $this->logger->warning('foo', []); + } + + public function testNotice() + { + $this->setExpectedException('PHPUnit_Framework_Error_Notice'); + + $this->logger->notice('foo', []); + } + + public function testInfo() + { + $this->setExpectedException('PHPUnit_Framework_Error_Notice'); + + $this->logger->info('foo', []); + } + + public function testDebug() + { + $this->setExpectedException('PHPUnit_Framework_Error_Notice'); + + $this->logger->debug('foo', []); + } +}