1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-06 21:26:43 +02:00

refactored the implementation of the NR handler and its test:

* the test now checks that if the extension is not loaded, an exception is thrown
* the test now mocks the new relic native functions
* moved some parameters as constants in the handler class
This commit is contained in:
odino
2013-07-24 10:14:35 +04:00
parent 394b0bf872
commit b422bb1c5b
2 changed files with 63 additions and 13 deletions

View File

@@ -15,18 +15,49 @@ use Monolog\TestCase;
use Monolog\Logger;
class NewRelicHandlerTest extends TestCase
{
public function testFallbackHandler()
{
/**
* @expectedException Monolog\Handler\MissingExtensionException
*/
public function testThehandlerThrowsAnExceptionIfTheNRExtensionIsNotLoaded()
{
$handler = new NewRelicHandler();
$fallbackHandler = new TestHandler();
$record = array(
'level' => Logger::DEBUG,
'extra' => array(),
);
$handler->handle($record);
$this->assertTrue($handler->isHandling($record));
$handler = new StubNewRelicHandlerWithoutExtension();
$handler->handle($this->getRecord());
}
public function testThehandlerCanHandleTheRecord()
{
$handler = new StubNewRelicHandler();
$handler->handle($this->getRecord());
}
public function testThehandlerCanAddParamsToTheNewRelicTrace()
{
$handler = new StubNewRelicHandler();
$handler->handle($this->getRecord(100, 'log message', array('a' => 'b')));
}
}
class StubNewRelicHandlerWithoutExtension extends NewRelicHandler
{
protected function isNewRelicEnabled()
{
return false;
}
}
class StubNewRelicHandler extends NewRelicHandler
{
protected function isNewRelicEnabled()
{
return true;
}
}
function newrelic_notice_error() {
return true;
}
function newrelic_add_custom_parameter() {
return true;
}