mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-03 19:57:41 +02:00
Test suite and supporting handler for WhatFailureGroupHandler
This commit is contained in:
25
src/Monolog/Handler/ExceptionTestHandler.php
Normal file
25
src/Monolog/Handler/ExceptionTestHandler.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace Monolog\Handler;
|
||||
|
||||
use Monolog\Logger;
|
||||
|
||||
/**
|
||||
* Used for testing purposes.
|
||||
*
|
||||
* It records all records and gives you access to them for verification. It
|
||||
* throws an exception from handle and handleBatch to test the
|
||||
* WhatFailureGroupHandler Class.
|
||||
*
|
||||
* @author Craig D'Amelio <craig@damelio.ca>
|
||||
*/
|
||||
class ExceptionTestHandler extends TestHandler
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handle(array $record) {
|
||||
$return = parent::handle($record);
|
||||
throw new \Exception("ExceptionTestHandler::handle");
|
||||
}
|
||||
}
|
107
tests/Monolog/Handler/WhatFailureGroupHandlerTest.php
Normal file
107
tests/Monolog/Handler/WhatFailureGroupHandlerTest.php
Normal file
@@ -0,0 +1,107 @@
|
||||
<?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;
|
||||
|
||||
class WhatFailureGroupHandlerTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @covers Monolog\Handler\WhatFailureGroupHandler::__construct
|
||||
* @expectedException InvalidArgumentException
|
||||
*/
|
||||
public function testConstructorOnlyTakesHandler()
|
||||
{
|
||||
new WhatFailureGroupHandler(array(new TestHandler(), "foo"));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Monolog\Handler\WhatFailureGroupHandler::__construct
|
||||
* @covers Monolog\Handler\WhatFailureGroupHandler::handle
|
||||
*/
|
||||
public function testHandle()
|
||||
{
|
||||
$testHandlers = array(new TestHandler(), new TestHandler());
|
||||
$handler = new WhatFailureGroupHandler($testHandlers);
|
||||
$handler->handle($this->getRecord(Logger::DEBUG));
|
||||
$handler->handle($this->getRecord(Logger::INFO));
|
||||
foreach ($testHandlers as $test) {
|
||||
$this->assertTrue($test->hasDebugRecords());
|
||||
$this->assertTrue($test->hasInfoRecords());
|
||||
$this->assertTrue(count($test->getRecords()) === 2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Monolog\Handler\WhatFailureGroupHandler::handleBatch
|
||||
*/
|
||||
public function testHandleBatch()
|
||||
{
|
||||
$testHandlers = array(new TestHandler(), new TestHandler());
|
||||
$handler = new WhatFailureGroupHandler($testHandlers);
|
||||
$handler->handleBatch(array($this->getRecord(Logger::DEBUG), $this->getRecord(Logger::INFO)));
|
||||
foreach ($testHandlers as $test) {
|
||||
$this->assertTrue($test->hasDebugRecords());
|
||||
$this->assertTrue($test->hasInfoRecords());
|
||||
$this->assertTrue(count($test->getRecords()) === 2);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Monolog\Handler\WhatFailureGroupHandler::isHandling
|
||||
*/
|
||||
public function testIsHandling()
|
||||
{
|
||||
$testHandlers = array(new TestHandler(Logger::ERROR), new TestHandler(Logger::WARNING));
|
||||
$handler = new WhatFailureGroupHandler($testHandlers);
|
||||
$this->assertTrue($handler->isHandling($this->getRecord(Logger::ERROR)));
|
||||
$this->assertTrue($handler->isHandling($this->getRecord(Logger::WARNING)));
|
||||
$this->assertFalse($handler->isHandling($this->getRecord(Logger::DEBUG)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Monolog\Handler\WhatFailureGroupHandler::handle
|
||||
*/
|
||||
public function testHandleUsesProcessors()
|
||||
{
|
||||
$test = new TestHandler();
|
||||
$handler = new WhatFailureGroupHandler(array($test));
|
||||
$handler->pushProcessor(function ($record) {
|
||||
$record['extra']['foo'] = true;
|
||||
|
||||
return $record;
|
||||
});
|
||||
$handler->handle($this->getRecord(Logger::WARNING));
|
||||
$this->assertTrue($test->hasWarningRecords());
|
||||
$records = $test->getRecords();
|
||||
$this->assertTrue($records[0]['extra']['foo']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Monolog\Handler\WhatFailureGroupHandler::handle
|
||||
*/
|
||||
public function testHandleException() {
|
||||
$test = new TestHandler();
|
||||
$exception = new ExceptionTestHandler();
|
||||
$handler = new WhatFailureGroupHandler(array($exception, $test, $exception));
|
||||
$handler->pushProcessor(function ($record) {
|
||||
$record['extra']['foo'] = true;
|
||||
|
||||
return $record;
|
||||
});
|
||||
$handler->handle($this->getRecord(Logger::WARNING));
|
||||
$this->assertTrue($test->hasWarningRecords());
|
||||
$records = $test->getRecords();
|
||||
$this->assertTrue($records[0]['extra']['foo']);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user