mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-01 10:50:21 +02:00
Tested the TestHandler (WTF)
This commit is contained in:
@@ -90,15 +90,18 @@ class TestHandler extends AbstractProcessingHandler
|
||||
return isset($this->recordsByLevel[Logger::DEBUG]);
|
||||
}
|
||||
|
||||
protected function hasRecord($record, $level = null)
|
||||
protected function hasRecord($record, $level)
|
||||
{
|
||||
if (null === $level) {
|
||||
$records = $this->records;
|
||||
} else {
|
||||
$records = $this->recordsByLevel[$level];
|
||||
if (!isset($this->recordsByLevel[$level])) {
|
||||
return false;
|
||||
}
|
||||
foreach ($records as $msg) {
|
||||
if ($msg['message'] === $record) {
|
||||
|
||||
if (is_array($record)) {
|
||||
$record = $record['message'];
|
||||
}
|
||||
|
||||
foreach ($this->recordsByLevel[$level] as $rec) {
|
||||
if ($rec['message'] === $record) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
54
tests/Monolog/Handler/TestHandlerTest.php
Normal file
54
tests/Monolog/Handler/TestHandlerTest.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Monolog package.
|
||||
*
|
||||
* (c) Jordi Boggiano <j.boggiano@seld.be>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Monolog\Handler;
|
||||
|
||||
use Monolog\TestCase;
|
||||
use Monolog\Logger;
|
||||
|
||||
/**
|
||||
* @covers Monolog\Handler\TestHandler
|
||||
*/
|
||||
class TestHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider methodProvider
|
||||
*/
|
||||
public function testHandler($method, $level)
|
||||
{
|
||||
$handler = new TestHandler;
|
||||
$record = $this->getRecord($level, 'test'.$method);
|
||||
$this->assertFalse($handler->{'has'.$method}($record));
|
||||
$this->assertFalse($handler->{'has'.$method.'Records'}());
|
||||
$handler->handle($record);
|
||||
|
||||
$this->assertFalse($handler->{'has'.$method}('bar'));
|
||||
$this->assertTrue($handler->{'has'.$method}($record));
|
||||
$this->assertTrue($handler->{'has'.$method}('test'.$method));
|
||||
$this->assertTrue($handler->{'has'.$method.'Records'}());
|
||||
|
||||
$records = $handler->getRecords();
|
||||
unset($records[0]['formatted']);
|
||||
$this->assertEquals(array($record), $records);
|
||||
}
|
||||
|
||||
public function methodProvider()
|
||||
{
|
||||
return array(
|
||||
array('Alert' , Logger::ALERT),
|
||||
array('Critical', Logger::CRITICAL),
|
||||
array('Error' , Logger::ERROR),
|
||||
array('Warning' , Logger::WARNING),
|
||||
array('Info' , Logger::INFO),
|
||||
array('Debug' , Logger::DEBUG),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user