parent
b2dda01962
commit
48d1fab5b9
@ -1,9 +1,14 @@ |
||||
# Doctrine Cache |
||||
|
||||
Master: [](http://travis-ci.org/doctrine/cache) [](https://coveralls.io/r/doctrine/cache?branch=master) |
||||
|
||||
[](https://packagist.org/packages/doctrine/cache) [](https://packagist.org/packages/doctrine/cache) |
||||
|
||||
Cache component extracted from the Doctrine Common project. |
||||
|
||||
## Changelog |
||||
|
||||
### v1.1 |
||||
### v1.2 |
||||
|
||||
* Added support for MongoDB as Cache Provider |
||||
* Fix namespace version reset |
||||
|
||||
@ -1,31 +0,0 @@ |
||||
<?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; |
||||
|
||||
use Monolog\Handler\TestHandler; |
||||
|
||||
class ErrorHandlerTest extends \PHPUnit_Framework_TestCase |
||||
{ |
||||
public function testHandleError() |
||||
{ |
||||
$logger = new Logger('test', array($handler = new TestHandler)); |
||||
$errHandler = new ErrorHandler($logger); |
||||
|
||||
$errHandler->registerErrorHandler(array(E_USER_NOTICE => Logger::EMERGENCY), false); |
||||
trigger_error('Foo', E_USER_ERROR); |
||||
$this->assertCount(1, $handler->getRecords()); |
||||
$this->assertTrue($handler->hasErrorRecords()); |
||||
trigger_error('Foo', E_USER_NOTICE); |
||||
$this->assertCount(2, $handler->getRecords()); |
||||
$this->assertTrue($handler->hasEmergencyRecords()); |
||||
} |
||||
} |
||||
@ -1,158 +0,0 @@ |
||||
<?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\Formatter; |
||||
|
||||
use Monolog\Logger; |
||||
|
||||
class ChromePHPFormatterTest extends \PHPUnit_Framework_TestCase |
||||
{ |
||||
/** |
||||
* @covers Monolog\Formatter\ChromePHPFormatter::format |
||||
*/ |
||||
public function testDefaultFormat() |
||||
{ |
||||
$formatter = new ChromePHPFormatter(); |
||||
$record = array( |
||||
'level' => Logger::ERROR, |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'context' => array('from' => 'logger'), |
||||
'datetime' => new \DateTime("@0"), |
||||
'extra' => array('ip' => '127.0.0.1'), |
||||
'message' => 'log', |
||||
); |
||||
|
||||
$message = $formatter->format($record); |
||||
|
||||
$this->assertEquals( |
||||
array( |
||||
'meh', |
||||
array( |
||||
'message' => 'log', |
||||
'context' => array('from' => 'logger'), |
||||
'extra' => array('ip' => '127.0.0.1'), |
||||
), |
||||
'unknown', |
||||
'error' |
||||
), |
||||
$message |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Formatter\ChromePHPFormatter::format |
||||
*/ |
||||
public function testFormatWithFileAndLine() |
||||
{ |
||||
$formatter = new ChromePHPFormatter(); |
||||
$record = array( |
||||
'level' => Logger::CRITICAL, |
||||
'level_name' => 'CRITICAL', |
||||
'channel' => 'meh', |
||||
'context' => array('from' => 'logger'), |
||||
'datetime' => new \DateTime("@0"), |
||||
'extra' => array('ip' => '127.0.0.1', 'file' => 'test', 'line' => 14), |
||||
'message' => 'log', |
||||
); |
||||
|
||||
$message = $formatter->format($record); |
||||
|
||||
$this->assertEquals( |
||||
array( |
||||
'meh', |
||||
array( |
||||
'message' => 'log', |
||||
'context' => array('from' => 'logger'), |
||||
'extra' => array('ip' => '127.0.0.1'), |
||||
), |
||||
'test : 14', |
||||
'error' |
||||
), |
||||
$message |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Formatter\ChromePHPFormatter::format |
||||
*/ |
||||
public function testFormatWithoutContext() |
||||
{ |
||||
$formatter = new ChromePHPFormatter(); |
||||
$record = array( |
||||
'level' => Logger::DEBUG, |
||||
'level_name' => 'DEBUG', |
||||
'channel' => 'meh', |
||||
'context' => array(), |
||||
'datetime' => new \DateTime("@0"), |
||||
'extra' => array(), |
||||
'message' => 'log', |
||||
); |
||||
|
||||
$message = $formatter->format($record); |
||||
|
||||
$this->assertEquals( |
||||
array( |
||||
'meh', |
||||
'log', |
||||
'unknown', |
||||
'log' |
||||
), |
||||
$message |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Formatter\ChromePHPFormatter::formatBatch |
||||
*/ |
||||
public function testBatchFormatThrowException() |
||||
{ |
||||
$formatter = new ChromePHPFormatter(); |
||||
$records = array( |
||||
array( |
||||
'level' => Logger::INFO, |
||||
'level_name' => 'INFO', |
||||
'channel' => 'meh', |
||||
'context' => array(), |
||||
'datetime' => new \DateTime("@0"), |
||||
'extra' => array(), |
||||
'message' => 'log', |
||||
), |
||||
array( |
||||
'level' => Logger::WARNING, |
||||
'level_name' => 'WARNING', |
||||
'channel' => 'foo', |
||||
'context' => array(), |
||||
'datetime' => new \DateTime("@0"), |
||||
'extra' => array(), |
||||
'message' => 'log2', |
||||
), |
||||
); |
||||
|
||||
$this->assertEquals( |
||||
array( |
||||
array( |
||||
'meh', |
||||
'log', |
||||
'unknown', |
||||
'info' |
||||
), |
||||
array( |
||||
'foo', |
||||
'log2', |
||||
'unknown', |
||||
'warn' |
||||
), |
||||
), |
||||
$formatter->formatBatch($records) |
||||
); |
||||
} |
||||
} |
||||
@ -1,158 +0,0 @@ |
||||
<?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\Formatter; |
||||
|
||||
use Monolog\Logger; |
||||
use Monolog\Formatter\GelfMessageFormatter; |
||||
|
||||
class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase |
||||
{ |
||||
public function setUp() |
||||
{ |
||||
if (!class_exists("Gelf\Message")) { |
||||
$this->markTestSkipped("mlehner/gelf-php not installed"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Formatter\GelfMessageFormatter::format |
||||
*/ |
||||
public function testDefaultFormatter() |
||||
{ |
||||
$formatter = new GelfMessageFormatter(); |
||||
$record = array( |
||||
'level' => Logger::ERROR, |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'context' => array(), |
||||
'datetime' => new \DateTime("@0"), |
||||
'extra' => array(), |
||||
'message' => 'log', |
||||
); |
||||
|
||||
$message = $formatter->format($record); |
||||
|
||||
$this->assertInstanceOf('Gelf\Message', $message); |
||||
$this->assertEquals(0, $message->getTimestamp()); |
||||
$this->assertEquals('log', $message->getShortMessage()); |
||||
$this->assertEquals('meh', $message->getFacility()); |
||||
$this->assertEquals(null, $message->getLine()); |
||||
$this->assertEquals(null, $message->getFile()); |
||||
$this->assertEquals(3, $message->getLevel()); |
||||
$this->assertNotEmpty($message->getHost()); |
||||
|
||||
$formatter = new GelfMessageFormatter('mysystem'); |
||||
|
||||
$message = $formatter->format($record); |
||||
|
||||
$this->assertInstanceOf('Gelf\Message', $message); |
||||
$this->assertEquals('mysystem', $message->getHost()); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Formatter\GelfMessageFormatter::format |
||||
*/ |
||||
public function testFormatWithFileAndLine() |
||||
{ |
||||
$formatter = new GelfMessageFormatter(); |
||||
$record = array( |
||||
'level' => Logger::ERROR, |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'context' => array('from' => 'logger'), |
||||
'datetime' => new \DateTime("@0"), |
||||
'extra' => array('file' => 'test', 'line' => 14), |
||||
'message' => 'log', |
||||
); |
||||
|
||||
$message = $formatter->format($record); |
||||
|
||||
$this->assertInstanceOf('Gelf\Message', $message); |
||||
$this->assertEquals('test', $message->getFile()); |
||||
$this->assertEquals(14, $message->getLine()); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Formatter\GelfMessageFormatter::format |
||||
*/ |
||||
public function testFormatWithContext() |
||||
{ |
||||
$formatter = new GelfMessageFormatter(); |
||||
$record = array( |
||||
'level' => Logger::ERROR, |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'context' => array('from' => 'logger'), |
||||
'datetime' => new \DateTime("@0"), |
||||
'extra' => array('key' => 'pair'), |
||||
'message' => 'log' |
||||
); |
||||
|
||||
$message = $formatter->format($record); |
||||
|
||||
$this->assertInstanceOf('Gelf\Message', $message); |
||||
|
||||
$message_array = $message->toArray(); |
||||
|
||||
$this->assertArrayHasKey('_ctxt_from', $message_array); |
||||
$this->assertEquals('logger', $message_array['_ctxt_from']); |
||||
|
||||
// Test with extraPrefix |
||||
$formatter = new GelfMessageFormatter(null, null, 'CTX'); |
||||
$message = $formatter->format($record); |
||||
|
||||
$this->assertInstanceOf('Gelf\Message', $message); |
||||
|
||||
$message_array = $message->toArray(); |
||||
|
||||
$this->assertArrayHasKey('_CTXfrom', $message_array); |
||||
$this->assertEquals('logger', $message_array['_CTXfrom']); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Formatter\GelfMessageFormatter::format |
||||
*/ |
||||
public function testFormatWithExtra() |
||||
{ |
||||
$formatter = new GelfMessageFormatter(); |
||||
$record = array( |
||||
'level' => Logger::ERROR, |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'context' => array('from' => 'logger'), |
||||
'datetime' => new \DateTime("@0"), |
||||
'extra' => array('key' => 'pair'), |
||||
'message' => 'log' |
||||
); |
||||
|
||||
$message = $formatter->format($record); |
||||
|
||||
$this->assertInstanceOf('Gelf\Message', $message); |
||||
|
||||
$message_array = $message->toArray(); |
||||
|
||||
$this->assertArrayHasKey('_key', $message_array); |
||||
$this->assertEquals('pair', $message_array['_key']); |
||||
|
||||
// Test with extraPrefix |
||||
$formatter = new GelfMessageFormatter(null, 'EXT'); |
||||
$message = $formatter->format($record); |
||||
|
||||
$this->assertInstanceOf('Gelf\Message', $message); |
||||
|
||||
$message_array = $message->toArray(); |
||||
|
||||
$this->assertArrayHasKey('_EXTkey', $message_array); |
||||
$this->assertEquals('pair', $message_array['_EXTkey']); |
||||
} |
||||
} |
||||
@ -1,41 +0,0 @@ |
||||
<?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\Formatter; |
||||
|
||||
use Monolog\Logger; |
||||
use Monolog\TestCase; |
||||
|
||||
class JsonFormatterTest extends TestCase |
||||
{ |
||||
/** |
||||
* @covers Monolog\Formatter\JsonFormatter::format |
||||
*/ |
||||
public function testFormat() |
||||
{ |
||||
$formatter = new JsonFormatter(); |
||||
$record = $this->getRecord(); |
||||
$this->assertEquals(json_encode($record), $formatter->format($record)); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Formatter\JsonFormatter::formatBatch |
||||
*/ |
||||
public function testFormatBatch() |
||||
{ |
||||
$formatter = new JsonFormatter(); |
||||
$records = array( |
||||
$this->getRecord(Logger::WARNING), |
||||
$this->getRecord(Logger::DEBUG), |
||||
); |
||||
$this->assertEquals(json_encode($records), $formatter->formatBatch($records)); |
||||
} |
||||
} |
||||
@ -1,164 +0,0 @@ |
||||
<?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\Formatter; |
||||
|
||||
/** |
||||
* @covers Monolog\Formatter\LineFormatter |
||||
*/ |
||||
class LineFormatterTest extends \PHPUnit_Framework_TestCase |
||||
{ |
||||
public function testDefFormatWithString() |
||||
{ |
||||
$formatter = new LineFormatter(null, 'Y-m-d'); |
||||
$message = $formatter->format(array( |
||||
'level_name' => 'WARNING', |
||||
'channel' => 'log', |
||||
'context' => array(), |
||||
'message' => 'foo', |
||||
'datetime' => new \DateTime, |
||||
'extra' => array(), |
||||
)); |
||||
$this->assertEquals('['.date('Y-m-d').'] log.WARNING: foo [] []'."\n", $message); |
||||
} |
||||
|
||||
public function testDefFormatWithArrayContext() |
||||
{ |
||||
$formatter = new LineFormatter(null, 'Y-m-d'); |
||||
$message = $formatter->format(array( |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'message' => 'foo', |
||||
'datetime' => new \DateTime, |
||||
'extra' => array(), |
||||
'context' => array( |
||||
'foo' => 'bar', |
||||
'baz' => 'qux', |
||||
) |
||||
)); |
||||
$this->assertEquals('['.date('Y-m-d').'] meh.ERROR: foo {"foo":"bar","baz":"qux"} []'."\n", $message); |
||||
} |
||||
|
||||
public function testDefFormatExtras() |
||||
{ |
||||
$formatter = new LineFormatter(null, 'Y-m-d'); |
||||
$message = $formatter->format(array( |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'context' => array(), |
||||
'datetime' => new \DateTime, |
||||
'extra' => array('ip' => '127.0.0.1'), |
||||
'message' => 'log', |
||||
)); |
||||
$this->assertEquals('['.date('Y-m-d').'] meh.ERROR: log [] {"ip":"127.0.0.1"}'."\n", $message); |
||||
} |
||||
|
||||
public function testFormatExtras() |
||||
{ |
||||
$formatter = new LineFormatter("[%datetime%] %channel%.%level_name%: %message% %context% %extra.file% %extra%\n", 'Y-m-d'); |
||||
$message = $formatter->format(array( |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'context' => array(), |
||||
'datetime' => new \DateTime, |
||||
'extra' => array('ip' => '127.0.0.1', 'file' => 'test'), |
||||
'message' => 'log', |
||||
)); |
||||
$this->assertEquals('['.date('Y-m-d').'] meh.ERROR: log [] test {"ip":"127.0.0.1"}'."\n", $message); |
||||
} |
||||
|
||||
public function testDefFormatWithObject() |
||||
{ |
||||
$formatter = new LineFormatter(null, 'Y-m-d'); |
||||
$message = $formatter->format(array( |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'context' => array(), |
||||
'datetime' => new \DateTime, |
||||
'extra' => array('foo' => new TestFoo, 'bar' => new TestBar, 'baz' => array(), 'res' => fopen('php://memory', 'rb')), |
||||
'message' => 'foobar', |
||||
)); |
||||
|
||||
$this->assertEquals('['.date('Y-m-d').'] meh.ERROR: foobar [] {"foo":"[object] (Monolog\\\\Formatter\\\\TestFoo: {\\"foo\\":\\"foo\\"})","bar":"[object] (Monolog\\\\Formatter\\\\TestBar: {})","baz":[],"res":"[resource]"}'."\n", $message); |
||||
} |
||||
|
||||
public function testDefFormatWithException() |
||||
{ |
||||
$formatter = new LineFormatter(null, 'Y-m-d'); |
||||
$message = $formatter->format(array( |
||||
'level_name' => 'CRITICAL', |
||||
'channel' => 'core', |
||||
'context' => array('exception' => new \RuntimeException('Foo')), |
||||
'datetime' => new \DateTime, |
||||
'extra' => array(), |
||||
'message' => 'foobar', |
||||
)); |
||||
|
||||
$path = str_replace('\\/', '/', json_encode(__FILE__)); |
||||
|
||||
$this->assertEquals('['.date('Y-m-d').'] core.CRITICAL: foobar {"exception":"[object] (RuntimeException: Foo at '.substr($path, 1, -1).':'.(__LINE__-8).')"} []'."\n", $message); |
||||
} |
||||
|
||||
public function testDefFormatWithPreviousException() |
||||
{ |
||||
$formatter = new LineFormatter(null, 'Y-m-d'); |
||||
$previous = new \LogicException('Wut?'); |
||||
$message = $formatter->format(array( |
||||
'level_name' => 'CRITICAL', |
||||
'channel' => 'core', |
||||
'context' => array('exception' => new \RuntimeException('Foo', 0, $previous)), |
||||
'datetime' => new \DateTime, |
||||
'extra' => array(), |
||||
'message' => 'foobar', |
||||
)); |
||||
|
||||
$path = str_replace('\\/', '/', json_encode(__FILE__)); |
||||
|
||||
$this->assertEquals('['.date('Y-m-d').'] core.CRITICAL: foobar {"exception":"[object] (RuntimeException: Foo at '.substr($path, 1, -1).':'.(__LINE__-8).', LogicException: Wut? at '.substr($path, 1, -1).':'.(__LINE__-12).')"} []'."\n", $message); |
||||
} |
||||
|
||||
public function testBatchFormat() |
||||
{ |
||||
$formatter = new LineFormatter(null, 'Y-m-d'); |
||||
$message = $formatter->formatBatch(array( |
||||
array( |
||||
'level_name' => 'CRITICAL', |
||||
'channel' => 'test', |
||||
'message' => 'bar', |
||||
'context' => array(), |
||||
'datetime' => new \DateTime, |
||||
'extra' => array(), |
||||
), |
||||
array( |
||||
'level_name' => 'WARNING', |
||||
'channel' => 'log', |
||||
'message' => 'foo', |
||||
'context' => array(), |
||||
'datetime' => new \DateTime, |
||||
'extra' => array(), |
||||
), |
||||
)); |
||||
$this->assertEquals('['.date('Y-m-d').'] test.CRITICAL: bar [] []'."\n".'['.date('Y-m-d').'] log.WARNING: foo [] []'."\n", $message); |
||||
} |
||||
} |
||||
|
||||
class TestFoo |
||||
{ |
||||
public $foo = 'foo'; |
||||
} |
||||
|
||||
class TestBar |
||||
{ |
||||
public function __toString() |
||||
{ |
||||
return 'bar'; |
||||
} |
||||
} |
||||
@ -1,160 +0,0 @@ |
||||
<?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\Formatter; |
||||
|
||||
use Monolog\Logger; |
||||
use Monolog\Formatter\LogstashFormatter; |
||||
|
||||
class LogstashFormatterTest extends \PHPUnit_Framework_TestCase |
||||
{ |
||||
|
||||
/** |
||||
* @covers Monolog\Formatter\LogstashFormatter::format |
||||
*/ |
||||
public function testDefaultFormatter() |
||||
{ |
||||
$formatter = new LogstashFormatter('test', 'hostname'); |
||||
$record = array( |
||||
'level' => Logger::ERROR, |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'context' => array(), |
||||
'datetime' => new \DateTime("@0"), |
||||
'extra' => array(), |
||||
'message' => 'log', |
||||
); |
||||
|
||||
$message = json_decode($formatter->format($record), true); |
||||
|
||||
$this->assertEquals("1970-01-01T00:00:00+00:00", $message['@timestamp']); |
||||
$this->assertEquals('log', $message['@message']); |
||||
$this->assertEquals('meh', $message['@fields']['channel']); |
||||
$this->assertContains('meh', $message['@tags']); |
||||
$this->assertEquals(Logger::ERROR, $message['@fields']['level']); |
||||
$this->assertEquals('test', $message['@type']); |
||||
$this->assertEquals('hostname', $message['@source']); |
||||
|
||||
$formatter = new LogstashFormatter('mysystem'); |
||||
|
||||
$message = json_decode($formatter->format($record), true); |
||||
|
||||
$this->assertEquals('mysystem', $message['@type']); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Formatter\LogstashFormatter::format |
||||
*/ |
||||
public function testFormatWithFileAndLine() |
||||
{ |
||||
$formatter = new LogstashFormatter('test'); |
||||
$record = array( |
||||
'level' => Logger::ERROR, |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'context' => array('from' => 'logger'), |
||||
'datetime' => new \DateTime("@0"), |
||||
'extra' => array('file' => 'test', 'line' => 14), |
||||
'message' => 'log', |
||||
); |
||||
|
||||
$message = json_decode($formatter->format($record), true); |
||||
|
||||
$this->assertEquals('test', $message['@fields']['file']); |
||||
$this->assertEquals(14, $message['@fields']['line']); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Formatter\LogstashFormatter::format |
||||
*/ |
||||
public function testFormatWithContext() |
||||
{ |
||||
$formatter = new LogstashFormatter('test'); |
||||
$record = array( |
||||
'level' => Logger::ERROR, |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'context' => array('from' => 'logger'), |
||||
'datetime' => new \DateTime("@0"), |
||||
'extra' => array('key' => 'pair'), |
||||
'message' => 'log' |
||||
); |
||||
|
||||
$message = json_decode($formatter->format($record), true); |
||||
|
||||
$message_array = $message['@fields']; |
||||
|
||||
$this->assertArrayHasKey('ctxt_from', $message_array); |
||||
$this->assertEquals('logger', $message_array['ctxt_from']); |
||||
|
||||
// Test with extraPrefix |
||||
$formatter = new LogstashFormatter('test', null, null, 'CTX'); |
||||
$message = json_decode($formatter->format($record), true); |
||||
|
||||
$message_array = $message['@fields']; |
||||
|
||||
$this->assertArrayHasKey('CTXfrom', $message_array); |
||||
$this->assertEquals('logger', $message_array['CTXfrom']); |
||||
|
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Formatter\LogstashFormatter::format |
||||
*/ |
||||
public function testFormatWithExtra() |
||||
{ |
||||
$formatter = new LogstashFormatter('test'); |
||||
$record = array( |
||||
'level' => Logger::ERROR, |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'context' => array('from' => 'logger'), |
||||
'datetime' => new \DateTime("@0"), |
||||
'extra' => array('key' => 'pair'), |
||||
'message' => 'log' |
||||
); |
||||
|
||||
$message = json_decode($formatter->format($record), true); |
||||
|
||||
$message_array = $message['@fields']; |
||||
|
||||
$this->assertArrayHasKey('key', $message_array); |
||||
$this->assertEquals('pair', $message_array['key']); |
||||
|
||||
// Test with extraPrefix |
||||
$formatter = new LogstashFormatter('test', null, 'EXT'); |
||||
$message = json_decode($formatter->format($record), true); |
||||
|
||||
$message_array = $message['@fields']; |
||||
|
||||
$this->assertArrayHasKey('EXTkey', $message_array); |
||||
$this->assertEquals('pair', $message_array['EXTkey']); |
||||
} |
||||
|
||||
public function testFormatWithApplicationName() |
||||
{ |
||||
$formatter = new LogstashFormatter('app', 'test'); |
||||
$record = array( |
||||
'level' => Logger::ERROR, |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'context' => array('from' => 'logger'), |
||||
'datetime' => new \DateTime("@0"), |
||||
'extra' => array('key' => 'pair'), |
||||
'message' => 'log' |
||||
); |
||||
|
||||
$message = json_decode($formatter->format($record), true); |
||||
|
||||
$this->assertArrayHasKey('@type', $message); |
||||
$this->assertEquals('app', $message['@type']); |
||||
} |
||||
} |
||||
@ -1,182 +0,0 @@ |
||||
<?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\Formatter; |
||||
|
||||
/** |
||||
* @covers Monolog\Formatter\NormalizerFormatter |
||||
*/ |
||||
class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase |
||||
{ |
||||
public function testFormat() |
||||
{ |
||||
$formatter = new NormalizerFormatter('Y-m-d'); |
||||
$formatted = $formatter->format(array( |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'message' => 'foo', |
||||
'datetime' => new \DateTime, |
||||
'extra' => array('foo' => new TestFooNorm, 'bar' => new TestBarNorm, 'baz' => array(), 'res' => fopen('php://memory', 'rb')), |
||||
'context' => array( |
||||
'foo' => 'bar', |
||||
'baz' => 'qux', |
||||
), |
||||
)); |
||||
|
||||
$this->assertEquals(array( |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'message' => 'foo', |
||||
'datetime' => date('Y-m-d'), |
||||
'extra' => array( |
||||
'foo' => '[object] (Monolog\\Formatter\\TestFooNorm: {"foo":"foo"})', |
||||
'bar' => '[object] (Monolog\\Formatter\\TestBarNorm: {})', |
||||
'baz' => array(), |
||||
'res' => '[resource]', |
||||
), |
||||
'context' => array( |
||||
'foo' => 'bar', |
||||
'baz' => 'qux', |
||||
) |
||||
), $formatted); |
||||
} |
||||
|
||||
public function testFormatExceptions() |
||||
{ |
||||
$formatter = new NormalizerFormatter('Y-m-d'); |
||||
$e = new \LogicException('bar'); |
||||
$e2 = new \RuntimeException('foo', 0, $e); |
||||
$formatted = $formatter->format(array( |
||||
'exception' => $e2, |
||||
)); |
||||
|
||||
$this->assertGreaterThan(5, count($formatted['exception']['trace'])); |
||||
$this->assertTrue(isset($formatted['exception']['previous'])); |
||||
unset($formatted['exception']['trace'], $formatted['exception']['previous']); |
||||
|
||||
$this->assertEquals(array( |
||||
'exception' => array( |
||||
'class' => get_class($e2), |
||||
'message' => $e2->getMessage(), |
||||
'file' => $e2->getFile().':'.$e2->getLine(), |
||||
) |
||||
), $formatted); |
||||
} |
||||
|
||||
public function testBatchFormat() |
||||
{ |
||||
$formatter = new NormalizerFormatter('Y-m-d'); |
||||
$formatted = $formatter->formatBatch(array( |
||||
array( |
||||
'level_name' => 'CRITICAL', |
||||
'channel' => 'test', |
||||
'message' => 'bar', |
||||
'context' => array(), |
||||
'datetime' => new \DateTime, |
||||
'extra' => array(), |
||||
), |
||||
array( |
||||
'level_name' => 'WARNING', |
||||
'channel' => 'log', |
||||
'message' => 'foo', |
||||
'context' => array(), |
||||
'datetime' => new \DateTime, |
||||
'extra' => array(), |
||||
), |
||||
)); |
||||
$this->assertEquals(array( |
||||
array( |
||||
'level_name' => 'CRITICAL', |
||||
'channel' => 'test', |
||||
'message' => 'bar', |
||||
'context' => array(), |
||||
'datetime' => date('Y-m-d'), |
||||
'extra' => array(), |
||||
), |
||||
array( |
||||
'level_name' => 'WARNING', |
||||
'channel' => 'log', |
||||
'message' => 'foo', |
||||
'context' => array(), |
||||
'datetime' => date('Y-m-d'), |
||||
'extra' => array(), |
||||
), |
||||
), $formatted); |
||||
} |
||||
|
||||
/** |
||||
* Test issue #137 |
||||
*/ |
||||
public function testIgnoresRecursiveObjectReferences() |
||||
{ |
||||
// set up the recursion |
||||
$foo = new \stdClass(); |
||||
$bar = new \stdClass(); |
||||
|
||||
$foo->bar = $bar; |
||||
$bar->foo = $foo; |
||||
|
||||
// set an error handler to assert that the error is not raised anymore |
||||
$that = $this; |
||||
set_error_handler(function ($level, $message, $file, $line, $context) use ($that) { |
||||
if (error_reporting() & $level) { |
||||
restore_error_handler(); |
||||
$that->fail("$message should not be raised"); |
||||
} |
||||
}); |
||||
|
||||
$formatter = new NormalizerFormatter(); |
||||
$reflMethod = new \ReflectionMethod($formatter, 'toJson'); |
||||
$reflMethod->setAccessible(true); |
||||
$res = $reflMethod->invoke($formatter, array($foo, $bar), true); |
||||
|
||||
restore_error_handler(); |
||||
|
||||
$this->assertEquals(@json_encode(array($foo, $bar)), $res); |
||||
} |
||||
|
||||
public function testIgnoresInvalidTypes() |
||||
{ |
||||
// set up the recursion |
||||
$resource = fopen(__FILE__, 'r'); |
||||
|
||||
// set an error handler to assert that the error is not raised anymore |
||||
$that = $this; |
||||
set_error_handler(function ($level, $message, $file, $line, $context) use ($that) { |
||||
if (error_reporting() & $level) { |
||||
restore_error_handler(); |
||||
$that->fail("$message should not be raised"); |
||||
} |
||||
}); |
||||
|
||||
$formatter = new NormalizerFormatter(); |
||||
$reflMethod = new \ReflectionMethod($formatter, 'toJson'); |
||||
$reflMethod->setAccessible(true); |
||||
$res = $reflMethod->invoke($formatter, array($resource), true); |
||||
|
||||
restore_error_handler(); |
||||
|
||||
$this->assertEquals(@json_encode(array($resource)), $res); |
||||
} |
||||
} |
||||
|
||||
class TestFooNorm |
||||
{ |
||||
public $foo = 'foo'; |
||||
} |
||||
|
||||
class TestBarNorm |
||||
{ |
||||
public function __toString() |
||||
{ |
||||
return 'bar'; |
||||
} |
||||
} |
||||
@ -1,111 +0,0 @@ |
||||
<?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\Formatter; |
||||
|
||||
use Monolog\Logger; |
||||
|
||||
class WildfireFormatterTest extends \PHPUnit_Framework_TestCase |
||||
{ |
||||
/** |
||||
* @covers Monolog\Formatter\WildfireFormatter::format |
||||
*/ |
||||
public function testDefaultFormat() |
||||
{ |
||||
$wildfire = new WildfireFormatter(); |
||||
$record = array( |
||||
'level' => Logger::ERROR, |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'context' => array('from' => 'logger'), |
||||
'datetime' => new \DateTime("@0"), |
||||
'extra' => array('ip' => '127.0.0.1'), |
||||
'message' => 'log', |
||||
); |
||||
|
||||
$message = $wildfire->format($record); |
||||
|
||||
$this->assertEquals( |
||||
'125|[{"Type":"ERROR","File":"","Line":"","Label":"meh"},' |
||||
.'{"message":"log","context":{"from":"logger"},"extra":{"ip":"127.0.0.1"}}]|', |
||||
$message |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Formatter\WildfireFormatter::format |
||||
*/ |
||||
public function testFormatWithFileAndLine() |
||||
{ |
||||
$wildfire = new WildfireFormatter(); |
||||
$record = array( |
||||
'level' => Logger::ERROR, |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'context' => array('from' => 'logger'), |
||||
'datetime' => new \DateTime("@0"), |
||||
'extra' => array('ip' => '127.0.0.1', 'file' => 'test', 'line' => 14), |
||||
'message' => 'log', |
||||
); |
||||
|
||||
$message = $wildfire->format($record); |
||||
|
||||
$this->assertEquals( |
||||
'129|[{"Type":"ERROR","File":"test","Line":14,"Label":"meh"},' |
||||
.'{"message":"log","context":{"from":"logger"},"extra":{"ip":"127.0.0.1"}}]|', |
||||
$message |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Formatter\WildfireFormatter::format |
||||
*/ |
||||
public function testFormatWithoutContext() |
||||
{ |
||||
$wildfire = new WildfireFormatter(); |
||||
$record = array( |
||||
'level' => Logger::ERROR, |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'context' => array(), |
||||
'datetime' => new \DateTime("@0"), |
||||
'extra' => array(), |
||||
'message' => 'log', |
||||
); |
||||
|
||||
$message = $wildfire->format($record); |
||||
|
||||
$this->assertEquals( |
||||
'58|[{"Type":"ERROR","File":"","Line":"","Label":"meh"},"log"]|', |
||||
$message |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Formatter\WildfireFormatter::formatBatch |
||||
* @expectedException BadMethodCallException |
||||
*/ |
||||
public function testBatchFormatThrowException() |
||||
{ |
||||
$wildfire = new WildfireFormatter(); |
||||
$record = array( |
||||
'level' => Logger::ERROR, |
||||
'level_name' => 'ERROR', |
||||
'channel' => 'meh', |
||||
'context' => array(), |
||||
'datetime' => new \DateTime("@0"), |
||||
'extra' => array(), |
||||
'message' => 'log', |
||||
); |
||||
|
||||
$wildfire->formatBatch(array($record)); |
||||
} |
||||
} |
||||
@ -1,32 +0,0 @@ |
||||
<?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. |
||||
*/ |
||||
|
||||
spl_autoload_register(function($class) { |
||||
$file = __DIR__.'/../../../../src/'.strtr($class, '\\', '/').'.php'; |
||||
if (file_exists($file)) { |
||||
require $file; |
||||
|
||||
return true; |
||||
} |
||||
}); |
||||
|
||||
use Monolog\Logger; |
||||
use Monolog\Handler\FirePHPHandler; |
||||
use Monolog\Handler\ChromePHPHandler; |
||||
|
||||
$logger = new Logger('firephp'); |
||||
$logger->pushHandler(new FirePHPHandler); |
||||
$logger->pushHandler(new ChromePHPHandler()); |
||||
|
||||
$logger->addDebug('Debug'); |
||||
$logger->addInfo('Info'); |
||||
$logger->addWarning('Warning'); |
||||
$logger->addError('Error'); |
||||
@ -1,104 +0,0 @@ |
||||
<?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; |
||||
use Monolog\Formatter\LineFormatter; |
||||
use Monolog\Processor\WebProcessor; |
||||
|
||||
class AbstractHandlerTest extends TestCase |
||||
{ |
||||
/** |
||||
* @covers Monolog\Handler\AbstractHandler::__construct |
||||
* @covers Monolog\Handler\AbstractHandler::getLevel |
||||
* @covers Monolog\Handler\AbstractHandler::setLevel |
||||
* @covers Monolog\Handler\AbstractHandler::getBubble |
||||
* @covers Monolog\Handler\AbstractHandler::setBubble |
||||
* @covers Monolog\Handler\AbstractHandler::getFormatter |
||||
* @covers Monolog\Handler\AbstractHandler::setFormatter |
||||
*/ |
||||
public function testConstructAndGetSet() |
||||
{ |
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler', array(Logger::WARNING, false)); |
||||
$this->assertEquals(Logger::WARNING, $handler->getLevel()); |
||||
$this->assertEquals(false, $handler->getBubble()); |
||||
|
||||
$handler->setLevel(Logger::ERROR); |
||||
$handler->setBubble(true); |
||||
$handler->setFormatter($formatter = new LineFormatter); |
||||
$this->assertEquals(Logger::ERROR, $handler->getLevel()); |
||||
$this->assertEquals(true, $handler->getBubble()); |
||||
$this->assertSame($formatter, $handler->getFormatter()); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\AbstractHandler::handleBatch |
||||
*/ |
||||
public function testHandleBatch() |
||||
{ |
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler'); |
||||
$handler->expects($this->exactly(2)) |
||||
->method('handle'); |
||||
$handler->handleBatch(array($this->getRecord(), $this->getRecord())); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\AbstractHandler::isHandling |
||||
*/ |
||||
public function testIsHandling() |
||||
{ |
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler', array(Logger::WARNING, false)); |
||||
$this->assertTrue($handler->isHandling($this->getRecord())); |
||||
$this->assertFalse($handler->isHandling($this->getRecord(Logger::DEBUG))); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\AbstractHandler::getFormatter |
||||
* @covers Monolog\Handler\AbstractHandler::getDefaultFormatter |
||||
*/ |
||||
public function testGetFormatterInitializesDefault() |
||||
{ |
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler'); |
||||
$this->assertInstanceOf('Monolog\Formatter\LineFormatter', $handler->getFormatter()); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\AbstractHandler::pushProcessor |
||||
* @covers Monolog\Handler\AbstractHandler::popProcessor |
||||
* @expectedException LogicException |
||||
*/ |
||||
public function testPushPopProcessor() |
||||
{ |
||||
$logger = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler'); |
||||
$processor1 = new WebProcessor; |
||||
$processor2 = new WebProcessor; |
||||
|
||||
$logger->pushProcessor($processor1); |
||||
$logger->pushProcessor($processor2); |
||||
|
||||
$this->assertEquals($processor2, $logger->popProcessor()); |
||||
$this->assertEquals($processor1, $logger->popProcessor()); |
||||
$logger->popProcessor(); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\AbstractHandler::pushProcessor |
||||
* @expectedException InvalidArgumentException |
||||
*/ |
||||
public function testPushProcessorWithNonCallable() |
||||
{ |
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractHandler'); |
||||
|
||||
$handler->pushProcessor(new \stdClass()); |
||||
} |
||||
} |
||||
@ -1,79 +0,0 @@ |
||||
<?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; |
||||
use Monolog\Processor\WebProcessor; |
||||
|
||||
class AbstractProcessingHandlerTest extends TestCase |
||||
{ |
||||
/** |
||||
* @covers Monolog\Handler\AbstractProcessingHandler::handle |
||||
*/ |
||||
public function testHandleLowerLevelMessage() |
||||
{ |
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler', array(Logger::WARNING, true)); |
||||
$this->assertFalse($handler->handle($this->getRecord(Logger::DEBUG))); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\AbstractProcessingHandler::handle |
||||
*/ |
||||
public function testHandleBubbling() |
||||
{ |
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler', array(Logger::DEBUG, true)); |
||||
$this->assertFalse($handler->handle($this->getRecord())); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\AbstractProcessingHandler::handle |
||||
*/ |
||||
public function testHandleNotBubbling() |
||||
{ |
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler', array(Logger::DEBUG, false)); |
||||
$this->assertTrue($handler->handle($this->getRecord())); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\AbstractProcessingHandler::handle |
||||
*/ |
||||
public function testHandleIsFalseWhenNotHandled() |
||||
{ |
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler', array(Logger::WARNING, false)); |
||||
$this->assertTrue($handler->handle($this->getRecord())); |
||||
$this->assertFalse($handler->handle($this->getRecord(Logger::DEBUG))); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\AbstractProcessingHandler::processRecord |
||||
*/ |
||||
public function testProcessRecord() |
||||
{ |
||||
$handler = $this->getMockForAbstractClass('Monolog\Handler\AbstractProcessingHandler'); |
||||
$handler->pushProcessor(new WebProcessor(array( |
||||
'REQUEST_URI' => '', |
||||
'REQUEST_METHOD' => '', |
||||
'REMOTE_ADDR' => '', |
||||
'SERVER_NAME' => '', |
||||
))); |
||||
$handledRecord = null; |
||||
$handler->expects($this->once()) |
||||
->method('write') |
||||
->will($this->returnCallback(function($record) use (&$handledRecord) { |
||||
$handledRecord = $record; |
||||
})) |
||||
; |
||||
$handler->handle($this->getRecord()); |
||||
$this->assertEquals(5, count($handledRecord['extra'])); |
||||
} |
||||
} |
||||
@ -1,38 +0,0 @@ |
||||
<?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; |
||||
|
||||
class AmqpExchangeMock extends \AMQPExchange |
||||
{ |
||||
protected $messages = array(); |
||||
|
||||
public function __construct() |
||||
{ |
||||
} |
||||
|
||||
public function publish($message, $routing_key, $params = 0, $attributes = array()) |
||||
{ |
||||
$this->messages[] = array($message, $routing_key, $params, $attributes); |
||||
|
||||
return true; |
||||
} |
||||
|
||||
public function getMessages() |
||||
{ |
||||
return $this->messages; |
||||
} |
||||
|
||||
public function setName($name) |
||||
{ |
||||
return true; |
||||
} |
||||
} |
||||
@ -1,74 +0,0 @@ |
||||
<?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\RotatingFileHandler |
||||
*/ |
||||
class AmqpHandlerTest extends TestCase |
||||
{ |
||||
public function setUp() |
||||
{ |
||||
if (!class_exists('AMQPConnection') || !class_exists('AMQPExchange')) { |
||||
$this->markTestSkipped("amqp-php not installed"); |
||||
} |
||||
|
||||
if (!class_exists('AMQPChannel')) { |
||||
$this->markTestSkipped("Please update AMQP to version >= 1.0"); |
||||
} |
||||
} |
||||
|
||||
public function testHandle() |
||||
{ |
||||
$exchange = $this->getExchange(); |
||||
|
||||
$handler = new AmqpHandler($exchange, 'log'); |
||||
|
||||
$record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34)); |
||||
|
||||
$expected = array( |
||||
array( |
||||
'message' => 'test', |
||||
'context' => array( |
||||
'data' => array(), |
||||
'foo' => 34, |
||||
), |
||||
'level' => 300, |
||||
'level_name' => 'WARNING', |
||||
'channel' => 'test', |
||||
'extra' => array(), |
||||
), |
||||
'warn.test', |
||||
0, |
||||
array( |
||||
'delivery_mode' => 2, |
||||
'Content-type' => 'application/json' |
||||
) |
||||
); |
||||
|
||||
$handler->handle($record); |
||||
|
||||
$messages = $exchange->getMessages(); |
||||
$this->assertCount(1, $messages); |
||||
$messages[0][0] = json_decode($messages[0][0], true); |
||||
unset($messages[0][0]['datetime']); |
||||
$this->assertEquals($expected, $messages[0]); |
||||
} |
||||
|
||||
protected function getExchange() |
||||
{ |
||||
return new AmqpExchangeMock(); |
||||
} |
||||
} |
||||
@ -1,149 +0,0 @@ |
||||
<?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 BufferHandlerTest extends TestCase |
||||
{ |
||||
/** |
||||
* @covers Monolog\Handler\BufferHandler::__construct |
||||
* @covers Monolog\Handler\BufferHandler::handle |
||||
* @covers Monolog\Handler\BufferHandler::close |
||||
*/ |
||||
public function testHandleBuffers() |
||||
{ |
||||
$test = new TestHandler(); |
||||
$handler = new BufferHandler($test); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->handle($this->getRecord(Logger::INFO)); |
||||
$this->assertFalse($test->hasDebugRecords()); |
||||
$this->assertFalse($test->hasInfoRecords()); |
||||
$handler->close(); |
||||
$this->assertTrue($test->hasInfoRecords()); |
||||
$this->assertTrue(count($test->getRecords()) === 2); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\BufferHandler::close |
||||
* @covers Monolog\Handler\BufferHandler::flush |
||||
*/ |
||||
public function testDestructPropagatesRecords() |
||||
{ |
||||
$test = new TestHandler(); |
||||
$handler = new BufferHandler($test); |
||||
$handler->handle($this->getRecord(Logger::WARNING)); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->__destruct(); |
||||
$this->assertTrue($test->hasWarningRecords()); |
||||
$this->assertTrue($test->hasDebugRecords()); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\BufferHandler::handle |
||||
*/ |
||||
public function testHandleBufferLimit() |
||||
{ |
||||
$test = new TestHandler(); |
||||
$handler = new BufferHandler($test, 2); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->handle($this->getRecord(Logger::INFO)); |
||||
$handler->handle($this->getRecord(Logger::WARNING)); |
||||
$handler->close(); |
||||
$this->assertTrue($test->hasWarningRecords()); |
||||
$this->assertTrue($test->hasInfoRecords()); |
||||
$this->assertFalse($test->hasDebugRecords()); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\BufferHandler::handle |
||||
*/ |
||||
public function testHandleBufferLimitWithFlushOnOverflow() |
||||
{ |
||||
$test = new TestHandler(); |
||||
$handler = new BufferHandler($test, 3, Logger::DEBUG, true, true); |
||||
|
||||
// send two records |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$this->assertFalse($test->hasDebugRecords()); |
||||
$this->assertCount(0, $test->getRecords()); |
||||
|
||||
// overflow |
||||
$handler->handle($this->getRecord(Logger::INFO)); |
||||
$this->assertTrue($test->hasDebugRecords()); |
||||
$this->assertCount(3, $test->getRecords()); |
||||
|
||||
// should buffer again |
||||
$handler->handle($this->getRecord(Logger::WARNING)); |
||||
$this->assertCount(3, $test->getRecords()); |
||||
|
||||
$handler->close(); |
||||
$this->assertCount(5, $test->getRecords()); |
||||
$this->assertTrue($test->hasWarningRecords()); |
||||
$this->assertTrue($test->hasInfoRecords()); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\BufferHandler::handle |
||||
*/ |
||||
public function testHandleLevel() |
||||
{ |
||||
$test = new TestHandler(); |
||||
$handler = new BufferHandler($test, 0, Logger::INFO); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->handle($this->getRecord(Logger::INFO)); |
||||
$handler->handle($this->getRecord(Logger::WARNING)); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->close(); |
||||
$this->assertTrue($test->hasWarningRecords()); |
||||
$this->assertTrue($test->hasInfoRecords()); |
||||
$this->assertFalse($test->hasDebugRecords()); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\BufferHandler::flush |
||||
*/ |
||||
public function testFlush() |
||||
{ |
||||
$test = new TestHandler(); |
||||
$handler = new BufferHandler($test, 0); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->handle($this->getRecord(Logger::INFO)); |
||||
$handler->flush(); |
||||
$this->assertTrue($test->hasInfoRecords()); |
||||
$this->assertTrue($test->hasDebugRecords()); |
||||
$this->assertFalse($test->hasWarningRecords()); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\BufferHandler::handle |
||||
*/ |
||||
public function testHandleUsesProcessors() |
||||
{ |
||||
$test = new TestHandler(); |
||||
$handler = new BufferHandler($test); |
||||
$handler->pushProcessor(function ($record) { |
||||
$record['extra']['foo'] = true; |
||||
|
||||
return $record; |
||||
}); |
||||
$handler->handle($this->getRecord(Logger::WARNING)); |
||||
$handler->flush(); |
||||
$this->assertTrue($test->hasWarningRecords()); |
||||
$records = $test->getRecords(); |
||||
$this->assertTrue($records[0]['extra']['foo']); |
||||
} |
||||
} |
||||
@ -1,139 +0,0 @@ |
||||
<?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\ChromePHPHandler |
||||
*/ |
||||
class ChromePHPHandlerTest extends TestCase |
||||
{ |
||||
protected function setUp() |
||||
{ |
||||
TestChromePHPHandler::reset(); |
||||
} |
||||
|
||||
public function testHeaders() |
||||
{ |
||||
$handler = new TestChromePHPHandler(); |
||||
$handler->setFormatter($this->getIdentityFormatter()); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->handle($this->getRecord(Logger::WARNING)); |
||||
|
||||
$expected = array( |
||||
'X-ChromeLogger-Data' => base64_encode(utf8_encode(json_encode(array( |
||||
'version' => ChromePHPHandler::VERSION, |
||||
'columns' => array('label', 'log', 'backtrace', 'type'), |
||||
'rows' => array( |
||||
'test', |
||||
'test', |
||||
), |
||||
'request_uri' => '', |
||||
)))) |
||||
); |
||||
|
||||
$this->assertEquals($expected, $handler->getHeaders()); |
||||
} |
||||
|
||||
public function testHeadersOverflow() |
||||
{ |
||||
$handler = new TestChromePHPHandler(); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->handle($this->getRecord(Logger::WARNING, str_repeat('a', 150*1024))); |
||||
|
||||
// overflow chrome headers limit |
||||
$handler->handle($this->getRecord(Logger::WARNING, str_repeat('a', 100*1024))); |
||||
|
||||
$expected = array( |
||||
'X-ChromeLogger-Data' => base64_encode(utf8_encode(json_encode(array( |
||||
'version' => ChromePHPHandler::VERSION, |
||||
'columns' => array('label', 'log', 'backtrace', 'type'), |
||||
'rows' => array( |
||||
array( |
||||
'test', |
||||
'test', |
||||
'unknown', |
||||
'log', |
||||
), |
||||
array( |
||||
'test', |
||||
str_repeat('a', 150*1024), |
||||
'unknown', |
||||
'warn', |
||||
), |
||||
array( |
||||
'monolog', |
||||
'Incomplete logs, chrome header size limit reached', |
||||
'unknown', |
||||
'warn', |
||||
), |
||||
), |
||||
'request_uri' => '', |
||||
)))) |
||||
); |
||||
|
||||
$this->assertEquals($expected, $handler->getHeaders()); |
||||
} |
||||
|
||||
public function testConcurrentHandlers() |
||||
{ |
||||
$handler = new TestChromePHPHandler(); |
||||
$handler->setFormatter($this->getIdentityFormatter()); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->handle($this->getRecord(Logger::WARNING)); |
||||
|
||||
$handler2 = new TestChromePHPHandler(); |
||||
$handler2->setFormatter($this->getIdentityFormatter()); |
||||
$handler2->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler2->handle($this->getRecord(Logger::WARNING)); |
||||
|
||||
$expected = array( |
||||
'X-ChromeLogger-Data' => base64_encode(utf8_encode(json_encode(array( |
||||
'version' => ChromePHPHandler::VERSION, |
||||
'columns' => array('label', 'log', 'backtrace', 'type'), |
||||
'rows' => array( |
||||
'test', |
||||
'test', |
||||
'test', |
||||
'test', |
||||
), |
||||
'request_uri' => '', |
||||
)))) |
||||
); |
||||
|
||||
$this->assertEquals($expected, $handler2->getHeaders()); |
||||
} |
||||
} |
||||
|
||||
class TestChromePHPHandler extends ChromePHPHandler |
||||
{ |
||||
protected $headers = array(); |
||||
|
||||
public static function reset() |
||||
{ |
||||
self::$initialized = false; |
||||
self::$overflowed = false; |
||||
self::$json['rows'] = array(); |
||||
} |
||||
|
||||
protected function sendHeader($header, $content) |
||||
{ |
||||
$this->headers[$header] = $content; |
||||
} |
||||
|
||||
public function getHeaders() |
||||
{ |
||||
return $this->headers; |
||||
} |
||||
} |
||||
@ -1,41 +0,0 @@ |
||||
<?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 CouchDBHandlerTest extends TestCase |
||||
{ |
||||
public function testHandle() |
||||
{ |
||||
$record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34)); |
||||
|
||||
$expected = array( |
||||
'message' => 'test', |
||||
'context' => array('data' => '[object] (stdClass: {})', 'foo' => 34), |
||||
'level' => Logger::WARNING, |
||||
'level_name' => 'WARNING', |
||||
'channel' => 'test', |
||||
'datetime' => $record['datetime']->format('Y-m-d H:i:s'), |
||||
'extra' => array(), |
||||
); |
||||
|
||||
$handler = new CouchDBHandler(); |
||||
|
||||
try { |
||||
$handler->handle($record); |
||||
} catch (\RuntimeException $e) { |
||||
$this->markTestSkipped('Could not connect to couchdb server on http://localhost:5984'); |
||||
} |
||||
} |
||||
} |
||||
@ -1,52 +0,0 @@ |
||||
<?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 DoctrineCouchDBHandlerTest extends TestCase |
||||
{ |
||||
protected function setup() |
||||
{ |
||||
if (!class_exists('Doctrine\CouchDB\CouchDBClient')) { |
||||
$this->markTestSkipped('The "doctrine/couchdb" package is not installed'); |
||||
} |
||||
} |
||||
|
||||
public function testHandle() |
||||
{ |
||||
$client = $this->getMockBuilder('Doctrine\\CouchDB\\CouchDBClient') |
||||
->setMethods(array('postDocument')) |
||||
->disableOriginalConstructor() |
||||
->getMock(); |
||||
|
||||
$record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34)); |
||||
|
||||
$expected = array( |
||||
'message' => 'test', |
||||
'context' => array('data' => '[object] (stdClass: {})', 'foo' => 34), |
||||
'level' => Logger::WARNING, |
||||
'level_name' => 'WARNING', |
||||
'channel' => 'test', |
||||
'datetime' => $record['datetime']->format('Y-m-d H:i:s'), |
||||
'extra' => array(), |
||||
); |
||||
|
||||
$client->expects($this->once()) |
||||
->method('postDocument') |
||||
->with($expected); |
||||
|
||||
$handler = new DoctrineCouchDBHandler($client); |
||||
$handler->handle($record); |
||||
} |
||||
} |
||||
@ -1,189 +0,0 @@ |
||||
<?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; |
||||
use Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy; |
||||
use Monolog\Handler\FingersCrossed\ChannelLevelActivationStrategy; |
||||
|
||||
class FingersCrossedHandlerTest extends TestCase |
||||
{ |
||||
/** |
||||
* @covers Monolog\Handler\FingersCrossedHandler::__construct |
||||
* @covers Monolog\Handler\FingersCrossedHandler::handle |
||||
*/ |
||||
public function testHandleBuffers() |
||||
{ |
||||
$test = new TestHandler(); |
||||
$handler = new FingersCrossedHandler($test); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->handle($this->getRecord(Logger::INFO)); |
||||
$this->assertFalse($test->hasDebugRecords()); |
||||
$this->assertFalse($test->hasInfoRecords()); |
||||
$handler->handle($this->getRecord(Logger::WARNING)); |
||||
$this->assertTrue($test->hasInfoRecords()); |
||||
$this->assertTrue(count($test->getRecords()) === 3); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\FingersCrossedHandler::handle |
||||
*/ |
||||
public function testHandleStopsBufferingAfterTrigger() |
||||
{ |
||||
$test = new TestHandler(); |
||||
$handler = new FingersCrossedHandler($test); |
||||
$handler->handle($this->getRecord(Logger::WARNING)); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$this->assertTrue($test->hasWarningRecords()); |
||||
$this->assertTrue($test->hasDebugRecords()); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\FingersCrossedHandler::handle |
||||
* @covers Monolog\Handler\FingersCrossedHandler::reset |
||||
*/ |
||||
public function testHandleRestartBufferingAfterReset() |
||||
{ |
||||
$test = new TestHandler(); |
||||
$handler = new FingersCrossedHandler($test); |
||||
$handler->handle($this->getRecord(Logger::WARNING)); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->reset(); |
||||
$handler->handle($this->getRecord(Logger::INFO)); |
||||
$this->assertTrue($test->hasWarningRecords()); |
||||
$this->assertTrue($test->hasDebugRecords()); |
||||
$this->assertFalse($test->hasInfoRecords()); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\FingersCrossedHandler::handle |
||||
*/ |
||||
public function testHandleRestartBufferingAfterBeingTriggeredWhenStopBufferingIsDisabled() |
||||
{ |
||||
$test = new TestHandler(); |
||||
$handler = new FingersCrossedHandler($test, Logger::WARNING, 0, false, false); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->handle($this->getRecord(Logger::WARNING)); |
||||
$handler->handle($this->getRecord(Logger::INFO)); |
||||
$this->assertTrue($test->hasWarningRecords()); |
||||
$this->assertTrue($test->hasDebugRecords()); |
||||
$this->assertFalse($test->hasInfoRecords()); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\FingersCrossedHandler::handle |
||||
*/ |
||||
public function testHandleBufferLimit() |
||||
{ |
||||
$test = new TestHandler(); |
||||
$handler = new FingersCrossedHandler($test, Logger::WARNING, 2); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->handle($this->getRecord(Logger::INFO)); |
||||
$handler->handle($this->getRecord(Logger::WARNING)); |
||||
$this->assertTrue($test->hasWarningRecords()); |
||||
$this->assertTrue($test->hasInfoRecords()); |
||||
$this->assertFalse($test->hasDebugRecords()); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\FingersCrossedHandler::handle |
||||
*/ |
||||
public function testHandleWithCallback() |
||||
{ |
||||
$test = new TestHandler(); |
||||
$handler = new FingersCrossedHandler(function($record, $handler) use ($test) { |
||||
return $test; |
||||
}); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->handle($this->getRecord(Logger::INFO)); |
||||
$this->assertFalse($test->hasDebugRecords()); |
||||
$this->assertFalse($test->hasInfoRecords()); |
||||
$handler->handle($this->getRecord(Logger::WARNING)); |
||||
$this->assertTrue($test->hasInfoRecords()); |
||||
$this->assertTrue(count($test->getRecords()) === 3); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\FingersCrossedHandler::handle |
||||
* @expectedException RuntimeException |
||||
*/ |
||||
public function testHandleWithBadCallbackThrowsException() |
||||
{ |
||||
$handler = new FingersCrossedHandler(function($record, $handler) { |
||||
return 'foo'; |
||||
}); |
||||
$handler->handle($this->getRecord(Logger::WARNING)); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\FingersCrossedHandler::isHandling |
||||
*/ |
||||
public function testIsHandlingAlways() |
||||
{ |
||||
$test = new TestHandler(); |
||||
$handler = new FingersCrossedHandler($test, Logger::ERROR); |
||||
$this->assertTrue($handler->isHandling($this->getRecord(Logger::DEBUG))); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\FingersCrossedHandler::__construct |
||||
* @covers Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy::__construct |
||||
* @covers Monolog\Handler\FingersCrossed\ErrorLevelActivationStrategy::isHandlerActivated |
||||
*/ |
||||
public function testErrorLevelActivationStrategy() |
||||
{ |
||||
$test = new TestHandler(); |
||||
$handler = new FingersCrossedHandler($test, new ErrorLevelActivationStrategy(Logger::WARNING)); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$this->assertFalse($test->hasDebugRecords()); |
||||
$handler->handle($this->getRecord(Logger::WARNING)); |
||||
$this->assertTrue($test->hasDebugRecords()); |
||||
$this->assertTrue($test->hasWarningRecords()); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\FingersCrossed\ChannelLevelActivationStrategy::__construct |
||||
* @covers Monolog\Handler\FingersCrossed\ChannelLevelActivationStrategy::isHandlerActivated |
||||
*/ |
||||
public function testChannelLevelActivationStrategy() |
||||
{ |
||||
$test = new TestHandler(); |
||||
$handler = new FingersCrossedHandler($test, new ChannelLevelActivationStrategy(Logger::ERROR, array('othertest' => Logger::DEBUG))); |
||||
$handler->handle($this->getRecord(Logger::WARNING)); |
||||
$this->assertFalse($test->hasWarningRecords()); |
||||
$record = $this->getRecord(Logger::DEBUG); |
||||
$record['channel'] = 'othertest'; |
||||
$handler->handle($record); |
||||
$this->assertTrue($test->hasDebugRecords()); |
||||
$this->assertTrue($test->hasWarningRecords()); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\FingersCrossedHandler::handle |
||||
*/ |
||||
public function testHandleUsesProcessors() |
||||
{ |
||||
$test = new TestHandler(); |
||||
$handler = new FingersCrossedHandler($test, Logger::INFO); |
||||
$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']); |
||||
} |
||||
} |
||||
@ -1,94 +0,0 @@ |
||||
<?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\FirePHPHandler |
||||
*/ |
||||
class FirePHPHandlerTest extends TestCase |
||||
{ |
||||
public function setUp() |
||||
{ |
||||
TestFirePHPHandler::reset(); |
||||
} |
||||
|
||||
public function testHeaders() |
||||
{ |
||||
$handler = new TestFirePHPHandler; |
||||
$handler->setFormatter($this->getIdentityFormatter()); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->handle($this->getRecord(Logger::WARNING)); |
||||
|
||||
$expected = array( |
||||
'X-Wf-Protocol-1' => 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2', |
||||
'X-Wf-1-Structure-1' => 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1', |
||||
'X-Wf-1-Plugin-1' => 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3', |
||||
'X-Wf-1-1-1-1' => 'test', |
||||
'X-Wf-1-1-1-2' => 'test', |
||||
); |
||||
|
||||
$this->assertEquals($expected, $handler->getHeaders()); |
||||
} |
||||
|
||||
public function testConcurrentHandlers() |
||||
{ |
||||
$handler = new TestFirePHPHandler; |
||||
$handler->setFormatter($this->getIdentityFormatter()); |
||||
$handler->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler->handle($this->getRecord(Logger::WARNING)); |
||||
|
||||
$handler2 = new TestFirePHPHandler; |
||||
$handler2->setFormatter($this->getIdentityFormatter()); |
||||
$handler2->handle($this->getRecord(Logger::DEBUG)); |
||||
$handler2->handle($this->getRecord(Logger::WARNING)); |
||||
|
||||
$expected = array( |
||||
'X-Wf-Protocol-1' => 'http://meta.wildfirehq.org/Protocol/JsonStream/0.2', |
||||
'X-Wf-1-Structure-1' => 'http://meta.firephp.org/Wildfire/Structure/FirePHP/FirebugConsole/0.1', |
||||
'X-Wf-1-Plugin-1' => 'http://meta.firephp.org/Wildfire/Plugin/FirePHP/Library-FirePHPCore/0.3', |
||||
'X-Wf-1-1-1-1' => 'test', |
||||
'X-Wf-1-1-1-2' => 'test', |
||||
); |
||||
|
||||
$expected2 = array( |
||||
'X-Wf-1-1-1-3' => 'test', |
||||
'X-Wf-1-1-1-4' => 'test', |
||||
); |
||||
|
||||
$this->assertEquals($expected, $handler->getHeaders()); |
||||
$this->assertEquals($expected2, $handler2->getHeaders()); |
||||
} |
||||
} |
||||
|
||||
class TestFirePHPHandler extends FirePHPHandler |
||||
{ |
||||
protected $headers = array(); |
||||
|
||||
public static function reset() |
||||
{ |
||||
self::$initialized = false; |
||||
self::$messageIndex = 1; |
||||
} |
||||
|
||||
protected function sendHeader($header, $content) |
||||
{ |
||||
$this->headers[$header] = $content; |
||||
} |
||||
|
||||
public function getHeaders() |
||||
{ |
||||
return $this->headers; |
||||
} |
||||
} |
||||
@ -1,94 +0,0 @@ |
||||
<?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; |
||||
use Monolog\Formatter\GelfMessageFormatter; |
||||
|
||||
class GelfHandlerTest extends TestCase |
||||
{ |
||||
public function setUp() |
||||
{ |
||||
if (!class_exists("Gelf\MessagePublisher") || !class_exists("Gelf\Message")) { |
||||
$this->markTestSkipped("mlehner/gelf-php not installed"); |
||||
} |
||||
|
||||
require_once __DIR__ . '/GelfMocks.php'; |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\GelfHandler::__construct |
||||
*/ |
||||
public function testConstruct() |
||||
{ |
||||
$handler = new GelfHandler($this->getMessagePublisher()); |
||||
$this->assertInstanceOf('Monolog\Handler\GelfHandler', $handler); |
||||
} |
||||
|
||||
protected function getHandler($messagePublisher) |
||||
{ |
||||
$handler = new GelfHandler($messagePublisher); |
||||
|
||||
return $handler; |
||||
} |
||||
|
||||
protected function getMessagePublisher() |
||||
{ |
||||
return new MockMessagePublisher('localhost'); |
||||
} |
||||
|
||||
public function testDebug() |
||||
{ |
||||
$messagePublisher = $this->getMessagePublisher(); |
||||
$handler = $this->getHandler($messagePublisher); |
||||
|
||||
$record = $this->getRecord(Logger::DEBUG, "A test debug message"); |
||||
$handler->handle($record); |
||||
|
||||
$this->assertEquals(7, $messagePublisher->lastMessage->getLevel()); |
||||
$this->assertEquals('test', $messagePublisher->lastMessage->getFacility()); |
||||
$this->assertEquals($record['message'], $messagePublisher->lastMessage->getShortMessage()); |
||||
$this->assertEquals(null, $messagePublisher->lastMessage->getFullMessage()); |
||||
} |
||||
|
||||
public function testWarning() |
||||
{ |
||||
$messagePublisher = $this->getMessagePublisher(); |
||||
$handler = $this->getHandler($messagePublisher); |
||||
|
||||
$record = $this->getRecord(Logger::WARNING, "A test warning message"); |
||||
$handler->handle($record); |
||||
|
||||
$this->assertEquals(4, $messagePublisher->lastMessage->getLevel()); |
||||
$this->assertEquals('test', $messagePublisher->lastMessage->getFacility()); |
||||
$this->assertEquals($record['message'], $messagePublisher->lastMessage->getShortMessage()); |
||||
$this->assertEquals(null, $messagePublisher->lastMessage->getFullMessage()); |
||||
} |
||||
|
||||
public function testInjectedGelfMessageFormatter() |
||||
{ |
||||
$messagePublisher = $this->getMessagePublisher(); |
||||
$handler = $this->getHandler($messagePublisher); |
||||
|
||||
$handler->setFormatter(new GelfMessageFormatter('mysystem', 'EXT', 'CTX')); |
||||
|
||||
$record = $this->getRecord(Logger::WARNING, "A test warning message"); |
||||
$record['extra']['blarg'] = 'yep'; |
||||
$record['context']['from'] = 'logger'; |
||||
$handler->handle($record); |
||||
|
||||
$this->assertEquals('mysystem', $messagePublisher->lastMessage->getHost()); |
||||
$this->assertArrayHasKey('_EXTblarg', $messagePublisher->lastMessage->toArray()); |
||||
$this->assertArrayHasKey('_CTXfrom', $messagePublisher->lastMessage->toArray()); |
||||
} |
||||
} |
||||
@ -1,25 +0,0 @@ |
||||
<?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 Gelf\MessagePublisher; |
||||
use Gelf\Message; |
||||
|
||||
class MockMessagePublisher extends MessagePublisher |
||||
{ |
||||
public function publish(Message $message) |
||||
{ |
||||
$this->lastMessage = $message; |
||||
} |
||||
|
||||
public $lastMessage = null; |
||||
} |
||||
@ -1,89 +0,0 @@ |
||||
<?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 GroupHandlerTest extends TestCase |
||||
{ |
||||
/** |
||||
* @covers Monolog\Handler\GroupHandler::__construct |
||||
* @expectedException InvalidArgumentException |
||||
*/ |
||||
public function testConstructorOnlyTakesHandler() |
||||
{ |
||||
new GroupHandler(array(new TestHandler(), "foo")); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\GroupHandler::__construct |
||||
* @covers Monolog\Handler\GroupHandler::handle |
||||
*/ |
||||
public function testHandle() |
||||
{ |
||||
$testHandlers = array(new TestHandler(), new TestHandler()); |
||||
$handler = new GroupHandler($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\GroupHandler::handleBatch |
||||
*/ |
||||
public function testHandleBatch() |
||||
{ |
||||
$testHandlers = array(new TestHandler(), new TestHandler()); |
||||
$handler = new GroupHandler($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\GroupHandler::isHandling |
||||
*/ |
||||
public function testIsHandling() |
||||
{ |
||||
$testHandlers = array(new TestHandler(Logger::ERROR), new TestHandler(Logger::WARNING)); |
||||
$handler = new GroupHandler($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\GroupHandler::handle |
||||
*/ |
||||
public function testHandleUsesProcessors() |
||||
{ |
||||
$test = new TestHandler(); |
||||
$handler = new GroupHandler(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']); |
||||
} |
||||
} |
||||
@ -1,110 +0,0 @@ |
||||
<?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; |
||||
|
||||
/** |
||||
* @author Rafael Dohms <rafael@doh.ms> |
||||
* @see https://www.hipchat.com/docs/api |
||||
*/ |
||||
class HipChatHandlerTest extends TestCase |
||||
{ |
||||
|
||||
private $res; |
||||
private $handler; |
||||
|
||||
public function testWriteHeader() |
||||
{ |
||||
$this->createHandler(); |
||||
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1')); |
||||
fseek($this->res, 0); |
||||
$content = fread($this->res, 1024); |
||||
|
||||
$this->assertRegexp('/POST \/v1\/rooms\/message\?format=json&auth_token=.* HTTP\/1.1\\r\\nHost: api.hipchat.com\\r\\nContent-Type: application\/x-www-form-urlencoded\\r\\nContent-Length: \d{2,4}\\r\\n\\r\\n/', $content); |
||||
|
||||
return $content; |
||||
} |
||||
|
||||
/** |
||||
* @depends testWriteHeader |
||||
*/ |
||||
public function testWriteContent($content) |
||||
{ |
||||
$this->assertRegexp('/from=Monolog&room_id=room1¬ify=0&message=test1&message_format=text&color=red$/', $content); |
||||
} |
||||
|
||||
public function testWriteWithComplexMessage() |
||||
{ |
||||
$this->createHandler(); |
||||
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'Backup of database "example" finished in 16 minutes.')); |
||||
fseek($this->res, 0); |
||||
$content = fread($this->res, 1024); |
||||
|
||||
$this->assertRegexp('/message=Backup\+of\+database\+%22example%22\+finished\+in\+16\+minutes\./', $content); |
||||
} |
||||
|
||||
/** |
||||
* @dataProvider provideLevelColors |
||||
*/ |
||||
public function testWriteWithErrorLevelsAndColors($level, $expectedColor) |
||||
{ |
||||
$this->createHandler(); |
||||
$this->handler->handle($this->getRecord($level, 'Backup of database "example" finished in 16 minutes.')); |
||||
fseek($this->res, 0); |
||||
$content = fread($this->res, 1024); |
||||
|
||||
$this->assertRegexp('/color='.$expectedColor.'/', $content); |
||||
} |
||||
|
||||
public function provideLevelColors() |
||||
{ |
||||
return array( |
||||
array(Logger::DEBUG, 'gray'), |
||||
array(Logger::INFO, 'green'), |
||||
array(Logger::WARNING, 'yellow'), |
||||
array(Logger::ERROR, 'red'), |
||||
array(Logger::CRITICAL, 'red'), |
||||
array(Logger::ALERT, 'red'), |
||||
array(Logger::EMERGENCY,'red'), |
||||
array(Logger::NOTICE, 'green'), |
||||
); |
||||
} |
||||
|
||||
private function createHandler($token = 'myToken', $room = 'room1', $name = 'Monolog', $notify = false) |
||||
{ |
||||
$constructorArgs = array($token, $room, $name, $notify, Logger::DEBUG); |
||||
$this->res = fopen('php://memory', 'a'); |
||||
$this->handler = $this->getMock( |
||||
'\Monolog\Handler\HipChatHandler', |
||||
array('fsockopen', 'streamSetTimeout', 'closeSocket'), |
||||
$constructorArgs |
||||
); |
||||
|
||||
$reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString'); |
||||
$reflectionProperty->setAccessible(true); |
||||
$reflectionProperty->setValue($this->handler, 'localhost:1234'); |
||||
|
||||
$this->handler->expects($this->any()) |
||||
->method('fsockopen') |
||||
->will($this->returnValue($this->res)); |
||||
$this->handler->expects($this->any()) |
||||
->method('streamSetTimeout') |
||||
->will($this->returnValue(true)); |
||||
$this->handler->expects($this->any()) |
||||
->method('closeSocket') |
||||
->will($this->returnValue(true)); |
||||
|
||||
$this->handler->setFormatter($this->getIdentityFormatter()); |
||||
} |
||||
} |
||||
@ -1,75 +0,0 @@ |
||||
<?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\Logger; |
||||
use Monolog\TestCase; |
||||
|
||||
class MailHandlerTest extends TestCase |
||||
{ |
||||
/** |
||||
* @covers Monolog\Handler\MailHandler::handleBatch |
||||
*/ |
||||
public function testHandleBatch() |
||||
{ |
||||
$formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface'); |
||||
$formatter->expects($this->once()) |
||||
->method('formatBatch'); // Each record is formatted |
||||
|
||||
$handler = $this->getMockForAbstractClass('Monolog\\Handler\\MailHandler'); |
||||
$handler->expects($this->once()) |
||||
->method('send'); |
||||
$handler->expects($this->never()) |
||||
->method('write'); // write is for individual records |
||||
|
||||
$handler->setFormatter($formatter); |
||||
|
||||
$handler->handleBatch($this->getMultipleRecords()); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\MailHandler::handleBatch |
||||
*/ |
||||
public function testHandleBatchNotSendsMailIfMessagesAreBelowLevel() |
||||
{ |
||||
$records = array( |
||||
$this->getRecord(Logger::DEBUG, 'debug message 1'), |
||||
$this->getRecord(Logger::DEBUG, 'debug message 2'), |
||||
$this->getRecord(Logger::INFO, 'information'), |
||||
); |
||||
|
||||
$handler = $this->getMockForAbstractClass('Monolog\\Handler\\MailHandler'); |
||||
$handler->expects($this->never()) |
||||
->method('send'); |
||||
$handler->setLevel(Logger::ERROR); |
||||
|
||||
$handler->handleBatch($records); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\MailHandler::write |
||||
*/ |
||||
public function testHandle() |
||||
{ |
||||
$handler = $this->getMockForAbstractClass('Monolog\\Handler\\MailHandler'); |
||||
|
||||
$record = $this->getRecord(); |
||||
$records = array($record); |
||||
$records[0]['formatted'] = '['.$record['datetime']->format('Y-m-d H:i:s').'] test.WARNING: test [] []'."\n"; |
||||
|
||||
$handler->expects($this->once()) |
||||
->method('send') |
||||
->with($records[0]['formatted'], $records); |
||||
|
||||
$handler->handle($record); |
||||
} |
||||
} |
||||
@ -1,26 +0,0 @@ |
||||
<?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 Raven_Client; |
||||
|
||||
class MockRavenClient extends Raven_Client |
||||
{ |
||||
public function capture($data, $stack, $vars = null) |
||||
{ |
||||
$this->lastData = $data; |
||||
$this->lastStack = $stack; |
||||
} |
||||
|
||||
public $lastData; |
||||
public $lastStack; |
||||
} |
||||
@ -1,63 +0,0 @@ |
||||
<?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 MongoDBHandlerTest extends TestCase |
||||
{ |
||||
/** |
||||
* @expectedException InvalidArgumentException |
||||
*/ |
||||
public function testConstructorShouldThrowExceptionForInvalidMongo() |
||||
{ |
||||
new MongoDBHandler(new \stdClass(), 'DB', 'Collection'); |
||||
} |
||||
|
||||
public function testHandle() |
||||
{ |
||||
$mongo = $this->getMock('Mongo', array('selectCollection')); |
||||
$collection = $this->getMock('stdClass', array('save')); |
||||
|
||||
$mongo->expects($this->once()) |
||||
->method('selectCollection') |
||||
->with('DB', 'Collection') |
||||
->will($this->returnValue($collection)); |
||||
|
||||
$record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34)); |
||||
|
||||
$expected = array( |
||||
'message' => 'test', |
||||
'context' => array('data' => '[object] (stdClass: {})', 'foo' => 34), |
||||
'level' => Logger::WARNING, |
||||
'level_name' => 'WARNING', |
||||
'channel' => 'test', |
||||
'datetime' => $record['datetime']->format('Y-m-d H:i:s'), |
||||
'extra' => array(), |
||||
); |
||||
|
||||
$collection->expects($this->once()) |
||||
->method('save') |
||||
->with($expected); |
||||
|
||||
$handler = new MongoDBHandler($mongo, 'DB', 'Collection'); |
||||
$handler->handle($record); |
||||
} |
||||
} |
||||
|
||||
if (!class_exists('Mongo')) { |
||||
class Mongo |
||||
{ |
||||
public function selectCollection() {} |
||||
} |
||||
} |
||||
@ -1,43 +0,0 @@ |
||||
<?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; |
||||
|
||||
class NativeMailerHandlerTest extends TestCase |
||||
{ |
||||
/** |
||||
* @expectedException InvalidArgumentException |
||||
*/ |
||||
public function testConstructorHeaderInjection() |
||||
{ |
||||
$mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', "receiver@example.org\r\nFrom: faked@attacker.org"); |
||||
} |
||||
|
||||
/** |
||||
* @expectedException InvalidArgumentException |
||||
*/ |
||||
public function testSetterHeaderInjection() |
||||
{ |
||||
$mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org'); |
||||
$mailer->addHeader("Content-Type: text/html\r\nFrom: faked@attacker.org"); |
||||
} |
||||
|
||||
/** |
||||
* @expectedException InvalidArgumentException |
||||
*/ |
||||
public function testSetterArrayHeaderInjection() |
||||
{ |
||||
$mailer = new NativeMailerHandler('spammer@example.org', 'dear victim', 'receiver@example.org'); |
||||
$mailer->addHeader(array("Content-Type: text/html\r\nFrom: faked@attacker.org")); |
||||
} |
||||
} |
||||
@ -1,65 +0,0 @@ |
||||
<?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 NewRelicHandlerTest extends TestCase |
||||
{ |
||||
/** |
||||
* @expectedException Monolog\Handler\MissingExtensionException |
||||
*/ |
||||
public function testThehandlerThrowsAnExceptionIfTheNRExtensionIsNotLoaded() |
||||
{ |
||||
$handler = new StubNewRelicHandlerWithoutExtension(); |
||||
$handler->handle($this->getRecord(Logger::ERROR)); |
||||
} |
||||
|
||||
public function testThehandlerCanHandleTheRecord() |
||||
{ |
||||
$handler = new StubNewRelicHandler(); |
||||
$handler->handle($this->getRecord(Logger::ERROR)); |
||||
} |
||||
|
||||
public function testThehandlerCanAddParamsToTheNewRelicTrace() |
||||
{ |
||||
$handler = new StubNewRelicHandler(); |
||||
$handler->handle($this->getRecord(Logger::ERROR, '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; |
||||
} |
||||
@ -1,33 +0,0 @@ |
||||
<?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\NullHandler::handle |
||||
*/ |
||||
class NullHandlerTest extends TestCase |
||||
{ |
||||
public function testHandle() |
||||
{ |
||||
$handler = new NullHandler(); |
||||
$this->assertTrue($handler->handle($this->getRecord())); |
||||
} |
||||
|
||||
public function testHandleLowerLevelRecord() |
||||
{ |
||||
$handler = new NullHandler(Logger::WARNING); |
||||
$this->assertFalse($handler->handle($this->getRecord(Logger::DEBUG))); |
||||
} |
||||
} |
||||
@ -1,142 +0,0 @@ |
||||
<?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; |
||||
|
||||
/** |
||||
* Almost all examples (expected header, titles, messages) taken from |
||||
* https://www.pushover.net/api |
||||
* @author Sebastian Göttschkes <sebastian.goettschkes@googlemail.com> |
||||
* @see https://www.pushover.net/api |
||||
*/ |
||||
class PushoverHandlerTest extends TestCase |
||||
{ |
||||
|
||||
private $res; |
||||
private $handler; |
||||
|
||||
public function testWriteHeader() |
||||
{ |
||||
$this->createHandler(); |
||||
$this->handler->setHighPriorityLevel(Logger::EMERGENCY); // skip priority notifications |
||||
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1')); |
||||
fseek($this->res, 0); |
||||
$content = fread($this->res, 1024); |
||||
|
||||
$this->assertRegexp('/POST \/1\/messages.json HTTP\/1.1\\r\\nHost: api.pushover.net\\r\\nContent-Type: application\/x-www-form-urlencoded\\r\\nContent-Length: \d{2,4}\\r\\n\\r\\n/', $content); |
||||
|
||||
return $content; |
||||
} |
||||
|
||||
/** |
||||
* @depends testWriteHeader |
||||
*/ |
||||
public function testWriteContent($content) |
||||
{ |
||||
$this->assertRegexp('/token=myToken&user=myUser&message=test1&title=Monolog×tamp=\d{10}$/', $content); |
||||
} |
||||
|
||||
public function testWriteWithComplexTitle() |
||||
{ |
||||
$this->createHandler('myToken', 'myUser', 'Backup finished - SQL1', Logger::EMERGENCY); |
||||
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1')); |
||||
fseek($this->res, 0); |
||||
$content = fread($this->res, 1024); |
||||
|
||||
$this->assertRegexp('/title=Backup\+finished\+-\+SQL1/', $content); |
||||
} |
||||
|
||||
public function testWriteWithComplexMessage() |
||||
{ |
||||
$this->createHandler(); |
||||
$this->handler->setHighPriorityLevel(Logger::EMERGENCY); // skip priority notifications |
||||
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'Backup of database "example" finished in 16 minutes.')); |
||||
fseek($this->res, 0); |
||||
$content = fread($this->res, 1024); |
||||
|
||||
$this->assertRegexp('/message=Backup\+of\+database\+%22example%22\+finished\+in\+16\+minutes\./', $content); |
||||
} |
||||
|
||||
public function testWriteWithTooLongMessage() |
||||
{ |
||||
$message = str_pad('test', 520, 'a'); |
||||
$this->createHandler(); |
||||
$this->handler->setHighPriorityLevel(Logger::EMERGENCY); // skip priority notifications |
||||
$this->handler->handle($this->getRecord(Logger::CRITICAL, $message)); |
||||
fseek($this->res, 0); |
||||
$content = fread($this->res, 1024); |
||||
|
||||
$expectedMessage = substr($message, 0, 505); |
||||
|
||||
$this->assertRegexp('/message=' . $expectedMessage . '&title/', $content); |
||||
} |
||||
|
||||
public function testWriteWithHighPriority() |
||||
{ |
||||
$this->createHandler(); |
||||
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1')); |
||||
fseek($this->res, 0); |
||||
$content = fread($this->res, 1024); |
||||
|
||||
$this->assertRegexp('/token=myToken&user=myUser&message=test1&title=Monolog×tamp=\d{10}&priority=1$/', $content); |
||||
} |
||||
|
||||
public function testWriteWithEmergencyPriority() |
||||
{ |
||||
$this->createHandler(); |
||||
$this->handler->handle($this->getRecord(Logger::EMERGENCY, 'test1')); |
||||
fseek($this->res, 0); |
||||
$content = fread($this->res, 1024); |
||||
|
||||
$this->assertRegexp('/token=myToken&user=myUser&message=test1&title=Monolog×tamp=\d{10}&priority=2$/', $content); |
||||
} |
||||
|
||||
public function testWriteToMultipleUsers() |
||||
{ |
||||
$this->createHandler('myToken', array('userA', 'userB')); |
||||
$this->handler->handle($this->getRecord(Logger::EMERGENCY, 'test1')); |
||||
fseek($this->res, 0); |
||||
$content = fread($this->res, 1024); |
||||
|
||||
$this->assertRegexp('/token=myToken&user=userA&message=test1&title=Monolog×tamp=\d{10}&priority=2POST/', $content); |
||||
$this->assertRegexp('/token=myToken&user=userB&message=test1&title=Monolog×tamp=\d{10}&priority=2$/', $content); |
||||
} |
||||
|
||||
private function createHandler($token = 'myToken', $user = 'myUser', $title = 'Monolog') |
||||
{ |
||||
$constructorArgs = array($token, $user, $title); |
||||
$this->res = fopen('php://memory', 'a'); |
||||
$this->handler = $this->getMock( |
||||
'\Monolog\Handler\PushoverHandler', |
||||
array('fsockopen', 'streamSetTimeout', 'closeSocket'), |
||||
$constructorArgs |
||||
); |
||||
|
||||
$reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString'); |
||||
$reflectionProperty->setAccessible(true); |
||||
$reflectionProperty->setValue($this->handler, 'localhost:1234'); |
||||
|
||||
$this->handler->expects($this->any()) |
||||
->method('fsockopen') |
||||
->will($this->returnValue($this->res)); |
||||
$this->handler->expects($this->any()) |
||||
->method('streamSetTimeout') |
||||
->will($this->returnValue(true)); |
||||
$this->handler->expects($this->any()) |
||||
->method('closeSocket') |
||||
->will($this->returnValue(true)); |
||||
|
||||
$this->handler->setFormatter($this->getIdentityFormatter()); |
||||
} |
||||
} |
||||
@ -1,135 +0,0 @@ |
||||
<?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; |
||||
use Monolog\Formatter\LineFormatter; |
||||
use Monolog\Handler\RavenHandler; |
||||
|
||||
class RavenHandlerTest extends TestCase |
||||
{ |
||||
public function setUp() |
||||
{ |
||||
if (!class_exists("Raven_Client")) { |
||||
$this->markTestSkipped("raven/raven not installed"); |
||||
} |
||||
|
||||
require_once __DIR__ . '/MockRavenClient.php'; |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\RavenHandler::__construct |
||||
*/ |
||||
public function testConstruct() |
||||
{ |
||||
$handler = new RavenHandler($this->getRavenClient()); |
||||
$this->assertInstanceOf('Monolog\Handler\RavenHandler', $handler); |
||||
} |
||||
|
||||
protected function getHandler($ravenClient) |
||||
{ |
||||
$handler = new RavenHandler($ravenClient); |
||||
|
||||
return $handler; |
||||
} |
||||
|
||||
protected function getRavenClient() |
||||
{ |
||||
$dsn = 'http://43f6017361224d098402974103bfc53d:a6a0538fc2934ba2bed32e08741b2cd3@marca.python.live.cheggnet.com:9000/1'; |
||||
|
||||
return new MockRavenClient($dsn); |
||||
} |
||||
|
||||
public function testDebug() |
||||
{ |
||||
$ravenClient = $this->getRavenClient(); |
||||
$handler = $this->getHandler($ravenClient); |
||||
|
||||
$record = $this->getRecord(Logger::DEBUG, "A test debug message"); |
||||
$handler->handle($record); |
||||
|
||||
$this->assertEquals($ravenClient::DEBUG, $ravenClient->lastData['level']); |
||||
$this->assertContains($record['message'], $ravenClient->lastData['message']); |
||||
} |
||||
|
||||
public function testWarning() |
||||
{ |
||||
$ravenClient = $this->getRavenClient(); |
||||
$handler = $this->getHandler($ravenClient); |
||||
|
||||
$record = $this->getRecord(Logger::WARNING, "A test warning message"); |
||||
$handler->handle($record); |
||||
|
||||
$this->assertEquals($ravenClient::WARNING, $ravenClient->lastData['level']); |
||||
$this->assertContains($record['message'], $ravenClient->lastData['message']); |
||||
} |
||||
|
||||
public function testException() |
||||
{ |
||||
$ravenClient = $this->getRavenClient(); |
||||
$handler = $this->getHandler($ravenClient); |
||||
|
||||
try { |
||||
$this->methodThatThrowsAnException(); |
||||
} catch (\Exception $e) { |
||||
$record = $this->getRecord(Logger::ERROR, $e->getMessage(), array('exception' => $e)); |
||||
$handler->handle($record); |
||||
} |
||||
|
||||
$this->assertEquals($record['message'], $ravenClient->lastData['message']); |
||||
} |
||||
|
||||
public function testHandleBatch() |
||||
{ |
||||
$records = $this->getMultipleRecords(); |
||||
|
||||
$logFormatter = $this->getMock('Monolog\\Formatter\\FormatterInterface'); |
||||
$logFormatter->expects($this->once())->method('formatBatch'); |
||||
|
||||
$formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface'); |
||||
$formatter->expects($this->once())->method('format'); |
||||
|
||||
$handler = $this->getHandler($this->getRavenClient()); |
||||
$handler->setBatchFormatter($logFormatter); |
||||
$handler->setFormatter($formatter); |
||||
$handler->handleBatch($records); |
||||
} |
||||
|
||||
public function testHandleBatchDoNothingIfRecordsAreBelowLevel() |
||||
{ |
||||
$records = array( |
||||
$this->getRecord(Logger::DEBUG, 'debug message 1'), |
||||
$this->getRecord(Logger::DEBUG, 'debug message 2'), |
||||
$this->getRecord(Logger::INFO, 'information'), |
||||
); |
||||
|
||||
$handler = $this->getMock('Monolog\Handler\RavenHandler', null, array($this->getRavenClient())); |
||||
$handler->expects($this->never())->method('handle'); |
||||
$handler->setLevel(Logger::ERROR); |
||||
$handler->handleBatch($records); |
||||
} |
||||
|
||||
public function testGetSetBatchFormatter() |
||||
{ |
||||
$ravenClient = $this->getRavenClient(); |
||||
$handler = $this->getHandler($ravenClient); |
||||
|
||||
$handler->setBatchFormatter($formatter = new LineFormatter()); |
||||
$this->assertSame($formatter, $handler->getBatchFormatter()); |
||||
} |
||||
|
||||
private function methodThatThrowsAnException() |
||||
{ |
||||
throw new \Exception('This is an exception'); |
||||
} |
||||
} |
||||
@ -1,71 +0,0 @@ |
||||
<?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; |
||||
use Monolog\Formatter\LineFormatter; |
||||
|
||||
class RedisHandlerTest extends TestCase |
||||
{ |
||||
/** |
||||
* @expectedException InvalidArgumentException |
||||
*/ |
||||
public function testConstructorShouldThrowExceptionForInvalidRedis() |
||||
{ |
||||
new RedisHandler(new \stdClass(), 'key'); |
||||
} |
||||
|
||||
public function testConstructorShouldWorkWithPredis() |
||||
{ |
||||
$redis = $this->getMock('Predis\Client'); |
||||
$this->assertInstanceof('Monolog\Handler\RedisHandler', new RedisHandler($redis, 'key')); |
||||
} |
||||
|
||||
public function testConstructorShouldWorkWithRedis() |
||||
{ |
||||
$redis = $this->getMock('Redis'); |
||||
$this->assertInstanceof('Monolog\Handler\RedisHandler', new RedisHandler($redis, 'key')); |
||||
} |
||||
|
||||
public function testPredisHandle() |
||||
{ |
||||
$redis = $this->getMock('Predis\Client', array('rpush')); |
||||
|
||||
// Predis\Client uses rpush |
||||
$redis->expects($this->once()) |
||||
->method('rpush') |
||||
->with('key', 'test'); |
||||
|
||||
$record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34)); |
||||
|
||||
$handler = new RedisHandler($redis, 'key'); |
||||
$handler->setFormatter(new LineFormatter("%message%")); |
||||
$handler->handle($record); |
||||
} |
||||
|
||||
public function testRedisHandle() |
||||
{ |
||||
$redis = $this->getMock('Redis', array('rpush')); |
||||
|
||||
// Redis uses rPush |
||||
$redis->expects($this->once()) |
||||
->method('rPush') |
||||
->with('key', 'test'); |
||||
|
||||
$record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34)); |
||||
|
||||
$handler = new RedisHandler($redis, 'key'); |
||||
$handler->setFormatter(new LineFormatter("%message%")); |
||||
$handler->handle($record); |
||||
} |
||||
} |
||||
@ -1,99 +0,0 @@ |
||||
<?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; |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\RotatingFileHandler |
||||
*/ |
||||
class RotatingFileHandlerTest extends TestCase |
||||
{ |
||||
public function setUp() |
||||
{ |
||||
$dir = __DIR__.'/Fixtures'; |
||||
chmod($dir, 0777); |
||||
if (!is_writable($dir)) { |
||||
$this->markTestSkipped($dir.' must be writeable to test the RotatingFileHandler.'); |
||||
} |
||||
} |
||||
|
||||
public function testRotationCreatesNewFile() |
||||
{ |
||||
touch(__DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400).'.rot'); |
||||
|
||||
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot'); |
||||
$handler->setFormatter($this->getIdentityFormatter()); |
||||
$handler->handle($this->getRecord()); |
||||
|
||||
$log = __DIR__.'/Fixtures/foo-'.date('Y-m-d').'.rot'; |
||||
$this->assertTrue(file_exists($log)); |
||||
$this->assertEquals('test', file_get_contents($log)); |
||||
} |
||||
|
||||
/** |
||||
* @dataProvider rotationTests |
||||
*/ |
||||
public function testRotation($createFile) |
||||
{ |
||||
touch($old1 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400).'.rot'); |
||||
touch($old2 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400 * 2).'.rot'); |
||||
touch($old3 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400 * 3).'.rot'); |
||||
touch($old4 = __DIR__.'/Fixtures/foo-'.date('Y-m-d', time() - 86400 * 4).'.rot'); |
||||
|
||||
$log = __DIR__.'/Fixtures/foo-'.date('Y-m-d').'.rot'; |
||||
|
||||
if ($createFile) { |
||||
touch($log); |
||||
} |
||||
|
||||
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot', 2); |
||||
$handler->setFormatter($this->getIdentityFormatter()); |
||||
$handler->handle($this->getRecord()); |
||||
|
||||
$handler->close(); |
||||
|
||||
$this->assertTrue(file_exists($log)); |
||||
$this->assertTrue(file_exists($old1)); |
||||
$this->assertEquals($createFile, file_exists($old2)); |
||||
$this->assertEquals($createFile, file_exists($old3)); |
||||
$this->assertEquals($createFile, file_exists($old4)); |
||||
$this->assertEquals('test', file_get_contents($log)); |
||||
} |
||||
|
||||
public function rotationTests() |
||||
{ |
||||
return array( |
||||
'Rotation is triggered when the file of the current day is not present' |
||||
=> array(true), |
||||
'Rotation is not triggered when the file is already present' |
||||
=> array(false), |
||||
); |
||||
} |
||||
|
||||
public function testReuseCurrentFile() |
||||
{ |
||||
$log = __DIR__.'/Fixtures/foo-'.date('Y-m-d').'.rot'; |
||||
file_put_contents($log, "foo"); |
||||
$handler = new RotatingFileHandler(__DIR__.'/Fixtures/foo.rot'); |
||||
$handler->setFormatter($this->getIdentityFormatter()); |
||||
$handler->handle($this->getRecord()); |
||||
$this->assertEquals('footest', file_get_contents($log)); |
||||
} |
||||
|
||||
public function tearDown() |
||||
{ |
||||
foreach (glob(__DIR__.'/Fixtures/*.rot') as $file) { |
||||
unlink($file); |
||||
} |
||||
} |
||||
} |
||||
@ -1,283 +0,0 @@ |
||||
<?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; |
||||
|
||||
/** |
||||
* @author Pablo de Leon Belloc <pablolb@gmail.com> |
||||
*/ |
||||
class SocketHandlerTest extends TestCase |
||||
{ |
||||
/** |
||||
* @var Monolog\Handler\SocketHandler |
||||
*/ |
||||
private $handler; |
||||
|
||||
/** |
||||
* @var resource |
||||
*/ |
||||
private $res; |
||||
|
||||
/** |
||||
* @expectedException UnexpectedValueException |
||||
*/ |
||||
public function testInvalidHostname() |
||||
{ |
||||
$this->createHandler('garbage://here'); |
||||
$this->writeRecord('data'); |
||||
} |
||||
|
||||
/** |
||||
* @expectedException \InvalidArgumentException |
||||
*/ |
||||
public function testBadConnectionTimeout() |
||||
{ |
||||
$this->createHandler('localhost:1234'); |
||||
$this->handler->setConnectionTimeout(-1); |
||||
} |
||||
|
||||
public function testSetConnectionTimeout() |
||||
{ |
||||
$this->createHandler('localhost:1234'); |
||||
$this->handler->setConnectionTimeout(10.1); |
||||
$this->assertEquals(10.1, $this->handler->getConnectionTimeout()); |
||||
} |
||||
|
||||
/** |
||||
* @expectedException \InvalidArgumentException |
||||
*/ |
||||
public function testBadTimeout() |
||||
{ |
||||
$this->createHandler('localhost:1234'); |
||||
$this->handler->setTimeout(-1); |
||||
} |
||||
|
||||
public function testSetTimeout() |
||||
{ |
||||
$this->createHandler('localhost:1234'); |
||||
$this->handler->setTimeout(10.25); |
||||
$this->assertEquals(10.25, $this->handler->getTimeout()); |
||||
} |
||||
|
||||
public function testSetConnectionString() |
||||
{ |
||||
$this->createHandler('tcp://localhost:9090'); |
||||
$this->assertEquals('tcp://localhost:9090', $this->handler->getConnectionString()); |
||||
} |
||||
|
||||
/** |
||||
* @expectedException UnexpectedValueException |
||||
*/ |
||||
public function testExceptionIsThrownOnFsockopenError() |
||||
{ |
||||
$this->setMockHandler(array('fsockopen')); |
||||
$this->handler->expects($this->once()) |
||||
->method('fsockopen') |
||||
->will($this->returnValue(false)); |
||||
$this->writeRecord('Hello world'); |
||||
} |
||||
|
||||
/** |
||||
* @expectedException UnexpectedValueException |
||||
*/ |
||||
public function testExceptionIsThrownOnPfsockopenError() |
||||
{ |
||||
$this->setMockHandler(array('pfsockopen')); |
||||
$this->handler->expects($this->once()) |
||||
->method('pfsockopen') |
||||
->will($this->returnValue(false)); |
||||
$this->handler->setPersistent(true); |
||||
$this->writeRecord('Hello world'); |
||||
} |
||||
|
||||
/** |
||||
* @expectedException UnexpectedValueException |
||||
*/ |
||||
public function testExceptionIsThrownIfCannotSetTimeout() |
||||
{ |
||||
$this->setMockHandler(array('streamSetTimeout')); |
||||
$this->handler->expects($this->once()) |
||||
->method('streamSetTimeout') |
||||
->will($this->returnValue(false)); |
||||
$this->writeRecord('Hello world'); |
||||
} |
||||
|
||||
/** |
||||
* @expectedException RuntimeException |
||||
*/ |
||||
public function testWriteFailsOnIfFwriteReturnsFalse() |
||||
{ |
||||
$this->setMockHandler(array('fwrite')); |
||||
|
||||
$callback = function($arg) { |
||||
$map = array( |
||||
'Hello world' => 6, |
||||
'world' => false, |
||||
); |
||||
|
||||
return $map[$arg]; |
||||
}; |
||||
|
||||
$this->handler->expects($this->exactly(2)) |
||||
->method('fwrite') |
||||
->will($this->returnCallback($callback)); |
||||
|
||||
$this->writeRecord('Hello world'); |
||||
} |
||||
|
||||
/** |
||||
* @expectedException RuntimeException |
||||
*/ |
||||
public function testWriteFailsIfStreamTimesOut() |
||||
{ |
||||
$this->setMockHandler(array('fwrite', 'streamGetMetadata')); |
||||
|
||||
$callback = function($arg) { |
||||
$map = array( |
||||
'Hello world' => 6, |
||||
'world' => 5, |
||||
); |
||||
|
||||
return $map[$arg]; |
||||
}; |
||||
|
||||
$this->handler->expects($this->exactly(1)) |
||||
->method('fwrite') |
||||
->will($this->returnCallback($callback)); |
||||
$this->handler->expects($this->exactly(1)) |
||||
->method('streamGetMetadata') |
||||
->will($this->returnValue(array('timed_out' => true))); |
||||
|
||||
$this->writeRecord('Hello world'); |
||||
} |
||||
|
||||
/** |
||||
* @expectedException RuntimeException |
||||
*/ |
||||
public function testWriteFailsOnIncompleteWrite() |
||||
{ |
||||
$this->setMockHandler(array('fwrite', 'streamGetMetadata')); |
||||
|
||||
$res = $this->res; |
||||
$callback = function($string) use ($res) { |
||||
fclose($res); |
||||
|
||||
return strlen('Hello'); |
||||
}; |
||||
|
||||
$this->handler->expects($this->exactly(1)) |
||||
->method('fwrite') |
||||
->will($this->returnCallback($callback)); |
||||
$this->handler->expects($this->exactly(1)) |
||||
->method('streamGetMetadata') |
||||
->will($this->returnValue(array('timed_out' => false))); |
||||
|
||||
$this->writeRecord('Hello world'); |
||||
} |
||||
|
||||
public function testWriteWithMemoryFile() |
||||
{ |
||||
$this->setMockHandler(); |
||||
$this->writeRecord('test1'); |
||||
$this->writeRecord('test2'); |
||||
$this->writeRecord('test3'); |
||||
fseek($this->res, 0); |
||||
$this->assertEquals('test1test2test3', fread($this->res, 1024)); |
||||
} |
||||
|
||||
public function testWriteWithMock() |
||||
{ |
||||
$this->setMockHandler(array('fwrite')); |
||||
|
||||
$callback = function($arg) { |
||||
$map = array( |
||||
'Hello world' => 6, |
||||
'world' => 5, |
||||
); |
||||
|
||||
return $map[$arg]; |
||||
}; |
||||
|
||||
$this->handler->expects($this->exactly(2)) |
||||
->method('fwrite') |
||||
->will($this->returnCallback($callback)); |
||||
|
||||
$this->writeRecord('Hello world'); |
||||
} |
||||
|
||||
public function testClose() |
||||
{ |
||||
$this->setMockHandler(); |
||||
$this->writeRecord('Hello world'); |
||||
$this->assertInternalType('resource', $this->res); |
||||
$this->handler->close(); |
||||
$this->assertFalse(is_resource($this->res), "Expected resource to be closed after closing handler"); |
||||
} |
||||
|
||||
public function testCloseDoesNotClosePersistentSocket() |
||||
{ |
||||
$this->setMockHandler(); |
||||
$this->handler->setPersistent(true); |
||||
$this->writeRecord('Hello world'); |
||||
$this->assertTrue(is_resource($this->res)); |
||||
$this->handler->close(); |
||||
$this->assertTrue(is_resource($this->res)); |
||||
} |
||||
|
||||
private function createHandler($connectionString) |
||||
{ |
||||
$this->handler = new SocketHandler($connectionString); |
||||
$this->handler->setFormatter($this->getIdentityFormatter()); |
||||
} |
||||
|
||||
private function writeRecord($string) |
||||
{ |
||||
$this->handler->handle($this->getRecord(Logger::WARNING, $string)); |
||||
} |
||||
|
||||
private function setMockHandler(array $methods = array()) |
||||
{ |
||||
$this->res = fopen('php://memory', 'a'); |
||||
|
||||
$defaultMethods = array('fsockopen', 'pfsockopen', 'streamSetTimeout'); |
||||
$newMethods = array_diff($methods, $defaultMethods); |
||||
|
||||
$finalMethods = array_merge($defaultMethods, $newMethods); |
||||
|
||||
$this->handler = $this->getMock( |
||||
'\Monolog\Handler\SocketHandler', $finalMethods, array('localhost:1234') |
||||
); |
||||
|
||||
if (!in_array('fsockopen', $methods)) { |
||||
$this->handler->expects($this->any()) |
||||
->method('fsockopen') |
||||
->will($this->returnValue($this->res)); |
||||
} |
||||
|
||||
if (!in_array('pfsockopen', $methods)) { |
||||
$this->handler->expects($this->any()) |
||||
->method('pfsockopen') |
||||
->will($this->returnValue($this->res)); |
||||
} |
||||
|
||||
if (!in_array('streamSetTimeout', $methods)) { |
||||
$this->handler->expects($this->any()) |
||||
->method('streamSetTimeout') |
||||
->will($this->returnValue(true)); |
||||
} |
||||
|
||||
$this->handler->setFormatter($this->getIdentityFormatter()); |
||||
} |
||||
|
||||
} |
||||
@ -1,88 +0,0 @@ |
||||
<?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 StreamHandlerTest extends TestCase |
||||
{ |
||||
/** |
||||
* @covers Monolog\Handler\StreamHandler::__construct |
||||
* @covers Monolog\Handler\StreamHandler::write |
||||
*/ |
||||
public function testWrite() |
||||
{ |
||||
$handle = fopen('php://memory', 'a+'); |
||||
$handler = new StreamHandler($handle); |
||||
$handler->setFormatter($this->getIdentityFormatter()); |
||||
$handler->handle($this->getRecord(Logger::WARNING, 'test')); |
||||
$handler->handle($this->getRecord(Logger::WARNING, 'test2')); |
||||
$handler->handle($this->getRecord(Logger::WARNING, 'test3')); |
||||
fseek($handle, 0); |
||||
$this->assertEquals('testtest2test3', fread($handle, 100)); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\StreamHandler::close |
||||
*/ |
||||
public function testClose() |
||||
{ |
||||
$handle = fopen('php://memory', 'a+'); |
||||
$handler = new StreamHandler($handle); |
||||
$this->assertTrue(is_resource($handle)); |
||||
$handler->close(); |
||||
$this->assertFalse(is_resource($handle)); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\StreamHandler::write |
||||
*/ |
||||
public function testWriteCreatesTheStreamResource() |
||||
{ |
||||
$handler = new StreamHandler('php://memory'); |
||||
$handler->handle($this->getRecord()); |
||||
} |
||||
|
||||
/** |
||||
* @expectedException LogicException |
||||
* @covers Monolog\Handler\StreamHandler::__construct |
||||
* @covers Monolog\Handler\StreamHandler::write |
||||
*/ |
||||
public function testWriteMissingResource() |
||||
{ |
||||
$handler = new StreamHandler(null); |
||||
$handler->handle($this->getRecord()); |
||||
} |
||||
|
||||
/** |
||||
* @expectedException UnexpectedValueException |
||||
* @covers Monolog\Handler\StreamHandler::__construct |
||||
* @covers Monolog\Handler\StreamHandler::write |
||||
*/ |
||||
public function testWriteInvalidResource() |
||||
{ |
||||
$handler = new StreamHandler('bogus://url'); |
||||
$handler->handle($this->getRecord()); |
||||
} |
||||
|
||||
/** |
||||
* @expectedException UnexpectedValueException |
||||
* @covers Monolog\Handler\StreamHandler::__construct |
||||
* @covers Monolog\Handler\StreamHandler::write |
||||
*/ |
||||
public function testWriteNonExistingResource() |
||||
{ |
||||
$handler = new StreamHandler('/foo/bar/baz/'.rand(0, 10000)); |
||||
$handler->handle($this->getRecord()); |
||||
} |
||||
} |
||||
@ -1,43 +0,0 @@ |
||||
<?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\Logger; |
||||
|
||||
class SyslogHandlerTest extends \PHPUnit_Framework_TestCase |
||||
{ |
||||
/** |
||||
* @covers Monolog\Handler\SyslogHandler::__construct |
||||
*/ |
||||
public function testConstruct() |
||||
{ |
||||
$handler = new SyslogHandler('test'); |
||||
$this->assertInstanceOf('Monolog\Handler\SyslogHandler', $handler); |
||||
|
||||
$handler = new SyslogHandler('test', LOG_USER); |
||||
$this->assertInstanceOf('Monolog\Handler\SyslogHandler', $handler); |
||||
|
||||
$handler = new SyslogHandler('test', 'user'); |
||||
$this->assertInstanceOf('Monolog\Handler\SyslogHandler', $handler); |
||||
|
||||
$handler = new SyslogHandler('test', LOG_USER, Logger::DEBUG, true, LOG_PERROR); |
||||
$this->assertInstanceOf('Monolog\Handler\SyslogHandler', $handler); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\SyslogHandler::__construct |
||||
*/ |
||||
public function testConstructInvalidFacility() |
||||
{ |
||||
$this->setExpectedException('UnexpectedValueException'); |
||||
$handler = new SyslogHandler('test', 'unknown'); |
||||
} |
||||
} |
||||
@ -1,56 +0,0 @@ |
||||
<?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('Emergency', Logger::EMERGENCY), |
||||
array('Alert' , Logger::ALERT), |
||||
array('Critical' , Logger::CRITICAL), |
||||
array('Error' , Logger::ERROR), |
||||
array('Warning' , Logger::WARNING), |
||||
array('Info' , Logger::INFO), |
||||
array('Notice' , Logger::NOTICE), |
||||
array('Debug' , Logger::DEBUG), |
||||
); |
||||
} |
||||
} |
||||
@ -1,69 +0,0 @@ |
||||
<?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; |
||||
|
||||
class ZendMonitorHandlerTest extends TestCase |
||||
{ |
||||
protected $zendMonitorHandler; |
||||
|
||||
public function setUp() |
||||
{ |
||||
if (!function_exists('zend_monitor_custom_event')) { |
||||
$this->markTestSkipped('ZendServer is not installed'); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\ZendMonitorHandler::write |
||||
*/ |
||||
public function testWrite() |
||||
{ |
||||
$record = $this->getRecord(); |
||||
$formatterResult = array( |
||||
'message' => $record['message'] |
||||
); |
||||
|
||||
$zendMonitor = $this->getMockBuilder('Monolog\Handler\ZendMonitorHandler') |
||||
->setMethods(array('writeZendMonitorCustomEvent', 'getDefaultFormatter')) |
||||
->getMock(); |
||||
|
||||
$formatterMock = $this->getMockBuilder('Monolog\Formatter\NormalizerFormatter') |
||||
->disableOriginalConstructor() |
||||
->getMock(); |
||||
|
||||
$formatterMock->expects($this->once()) |
||||
->method('format') |
||||
->will($this->returnValue($formatterResult)); |
||||
|
||||
$zendMonitor->expects($this->once()) |
||||
->method('getDefaultFormatter') |
||||
->will($this->returnValue($formatterMock)); |
||||
|
||||
$levelMap = $zendMonitor->getLevelMap(); |
||||
|
||||
$zendMonitor->expects($this->once()) |
||||
->method('writeZendMonitorCustomEvent') |
||||
->with($levelMap[$record['level']], $record['message'], $formatterResult); |
||||
|
||||
$zendMonitor->handle($record); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Handler\ZendMonitorHandler::getDefaultFormatter |
||||
*/ |
||||
public function testGetDefaultFormatterReturnsNormalizerFormatter() |
||||
{ |
||||
$zendMonitor = new ZendMonitorHandler(); |
||||
$this->assertInstanceOf('Monolog\Formatter\NormalizerFormatter', $zendMonitor->getDefaultFormatter()); |
||||
} |
||||
} |
||||
@ -1,409 +0,0 @@ |
||||
<?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; |
||||
|
||||
use Monolog\Processor\WebProcessor; |
||||
use Monolog\Handler\TestHandler; |
||||
|
||||
class LoggerTest extends \PHPUnit_Framework_TestCase |
||||
{ |
||||
/** |
||||
* @covers Monolog\Logger::getName |
||||
*/ |
||||
public function testGetName() |
||||
{ |
||||
$logger = new Logger('foo'); |
||||
$this->assertEquals('foo', $logger->getName()); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Logger::getLevelName |
||||
*/ |
||||
public function testGetLevelName() |
||||
{ |
||||
$this->assertEquals('ERROR', Logger::getLevelName(Logger::ERROR)); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Logger::getLevelName |
||||
* @expectedException InvalidArgumentException |
||||
*/ |
||||
public function testGetLevelNameThrows() |
||||
{ |
||||
Logger::getLevelName(5); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Logger::__construct |
||||
*/ |
||||
public function testChannel() |
||||
{ |
||||
$logger = new Logger('foo'); |
||||
$handler = new TestHandler; |
||||
$logger->pushHandler($handler); |
||||
$logger->addWarning('test'); |
||||
list($record) = $handler->getRecords(); |
||||
$this->assertEquals('foo', $record['channel']); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Logger::addRecord |
||||
*/ |
||||
public function testLog() |
||||
{ |
||||
$logger = new Logger(__METHOD__); |
||||
|
||||
$handler = $this->getMock('Monolog\Handler\NullHandler', array('handle')); |
||||
$handler->expects($this->once()) |
||||
->method('handle'); |
||||
$logger->pushHandler($handler); |
||||
|
||||
$this->assertTrue($logger->addWarning('test')); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Logger::addRecord |
||||
*/ |
||||
public function testLogNotHandled() |
||||
{ |
||||
$logger = new Logger(__METHOD__); |
||||
|
||||
$handler = $this->getMock('Monolog\Handler\NullHandler', array('handle'), array(Logger::ERROR)); |
||||
$handler->expects($this->never()) |
||||
->method('handle'); |
||||
$logger->pushHandler($handler); |
||||
|
||||
$this->assertFalse($logger->addWarning('test')); |
||||
} |
||||
|
||||
public function testHandlersInCtor() |
||||
{ |
||||
$handler1 = new TestHandler; |
||||
$handler2 = new TestHandler; |
||||
$logger = new Logger(__METHOD__, array($handler1, $handler2)); |
||||
|
||||
$this->assertEquals($handler1, $logger->popHandler()); |
||||
$this->assertEquals($handler2, $logger->popHandler()); |
||||
} |
||||
|
||||
public function testProcessorsInCtor() |
||||
{ |
||||
$processor1 = new WebProcessor; |
||||
$processor2 = new WebProcessor; |
||||
$logger = new Logger(__METHOD__, array(), array($processor1, $processor2)); |
||||
|
||||
$this->assertEquals($processor1, $logger->popProcessor()); |
||||
$this->assertEquals($processor2, $logger->popProcessor()); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Logger::pushHandler |
||||
* @covers Monolog\Logger::popHandler |
||||
* @expectedException LogicException |
||||
*/ |
||||
public function testPushPopHandler() |
||||
{ |
||||
$logger = new Logger(__METHOD__); |
||||
$handler1 = new TestHandler; |
||||
$handler2 = new TestHandler; |
||||
|
||||
$logger->pushHandler($handler1); |
||||
$logger->pushHandler($handler2); |
||||
|
||||
$this->assertEquals($handler2, $logger->popHandler()); |
||||
$this->assertEquals($handler1, $logger->popHandler()); |
||||
$logger->popHandler(); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Logger::pushProcessor |
||||
* @covers Monolog\Logger::popProcessor |
||||
* @expectedException LogicException |
||||
*/ |
||||
public function testPushPopProcessor() |
||||
{ |
||||
$logger = new Logger(__METHOD__); |
||||
$processor1 = new WebProcessor; |
||||
$processor2 = new WebProcessor; |
||||
|
||||
$logger->pushProcessor($processor1); |
||||
$logger->pushProcessor($processor2); |
||||
|
||||
$this->assertEquals($processor2, $logger->popProcessor()); |
||||
$this->assertEquals($processor1, $logger->popProcessor()); |
||||
$logger->popProcessor(); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Logger::pushProcessor |
||||
* @expectedException InvalidArgumentException |
||||
*/ |
||||
public function testPushProcessorWithNonCallable() |
||||
{ |
||||
$logger = new Logger(__METHOD__); |
||||
|
||||
$logger->pushProcessor(new \stdClass()); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Logger::addRecord |
||||
*/ |
||||
public function testProcessorsAreExecuted() |
||||
{ |
||||
$logger = new Logger(__METHOD__); |
||||
$handler = new TestHandler; |
||||
$logger->pushHandler($handler); |
||||
$logger->pushProcessor(function($record) { |
||||
$record['extra']['win'] = true; |
||||
|
||||
return $record; |
||||
}); |
||||
$logger->addError('test'); |
||||
list($record) = $handler->getRecords(); |
||||
$this->assertTrue($record['extra']['win']); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Logger::addRecord |
||||
*/ |
||||
public function testProcessorsAreCalledOnlyOnce() |
||||
{ |
||||
$logger = new Logger(__METHOD__); |
||||
$handler = $this->getMock('Monolog\Handler\HandlerInterface'); |
||||
$handler->expects($this->any()) |
||||
->method('isHandling') |
||||
->will($this->returnValue(true)) |
||||
; |
||||
$handler->expects($this->any()) |
||||
->method('handle') |
||||
->will($this->returnValue(true)) |
||||
; |
||||
$logger->pushHandler($handler); |
||||
|
||||
$processor = $this->getMockBuilder('Monolog\Processor\WebProcessor') |
||||
->disableOriginalConstructor() |
||||
->setMethods(array('__invoke')) |
||||
->getMock() |
||||
; |
||||
$processor->expects($this->once()) |
||||
->method('__invoke') |
||||
->will($this->returnArgument(0)) |
||||
; |
||||
$logger->pushProcessor($processor); |
||||
|
||||
$logger->addError('test'); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Logger::addRecord |
||||
*/ |
||||
public function testProcessorsNotCalledWhenNotHandled() |
||||
{ |
||||
$logger = new Logger(__METHOD__); |
||||
$handler = $this->getMock('Monolog\Handler\HandlerInterface'); |
||||
$handler->expects($this->once()) |
||||
->method('isHandling') |
||||
->will($this->returnValue(false)) |
||||
; |
||||
$logger->pushHandler($handler); |
||||
$that = $this; |
||||
$logger->pushProcessor(function($record) use ($that) { |
||||
$that->fail('The processor should not be called'); |
||||
}); |
||||
$logger->addAlert('test'); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Logger::addRecord |
||||
*/ |
||||
public function testHandlersNotCalledBeforeFirstHandling() |
||||
{ |
||||
$logger = new Logger(__METHOD__); |
||||
|
||||
$handler1 = $this->getMock('Monolog\Handler\HandlerInterface'); |
||||
$handler1->expects($this->never()) |
||||
->method('isHandling') |
||||
->will($this->returnValue(false)) |
||||
; |
||||
$handler1->expects($this->once()) |
||||
->method('handle') |
||||
->will($this->returnValue(false)) |
||||
; |
||||
$logger->pushHandler($handler1); |
||||
|
||||
$handler2 = $this->getMock('Monolog\Handler\HandlerInterface'); |
||||
$handler2->expects($this->once()) |
||||
->method('isHandling') |
||||
->will($this->returnValue(true)) |
||||
; |
||||
$handler2->expects($this->once()) |
||||
->method('handle') |
||||
->will($this->returnValue(false)) |
||||
; |
||||
$logger->pushHandler($handler2); |
||||
|
||||
$handler3 = $this->getMock('Monolog\Handler\HandlerInterface'); |
||||
$handler3->expects($this->once()) |
||||
->method('isHandling') |
||||
->will($this->returnValue(false)) |
||||
; |
||||
$handler3->expects($this->never()) |
||||
->method('handle') |
||||
; |
||||
$logger->pushHandler($handler3); |
||||
|
||||
$logger->debug('test'); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Logger::addRecord |
||||
*/ |
||||
public function testBubblingWhenTheHandlerReturnsFalse() |
||||
{ |
||||
$logger = new Logger(__METHOD__); |
||||
|
||||
$handler1 = $this->getMock('Monolog\Handler\HandlerInterface'); |
||||
$handler1->expects($this->any()) |
||||
->method('isHandling') |
||||
->will($this->returnValue(true)) |
||||
; |
||||
$handler1->expects($this->once()) |
||||
->method('handle') |
||||
->will($this->returnValue(false)) |
||||
; |
||||
$logger->pushHandler($handler1); |
||||
|
||||
$handler2 = $this->getMock('Monolog\Handler\HandlerInterface'); |
||||
$handler2->expects($this->any()) |
||||
->method('isHandling') |
||||
->will($this->returnValue(true)) |
||||
; |
||||
$handler2->expects($this->once()) |
||||
->method('handle') |
||||
->will($this->returnValue(false)) |
||||
; |
||||
$logger->pushHandler($handler2); |
||||
|
||||
$logger->debug('test'); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Logger::addRecord |
||||
*/ |
||||
public function testNotBubblingWhenTheHandlerReturnsTrue() |
||||
{ |
||||
$logger = new Logger(__METHOD__); |
||||
|
||||
$handler1 = $this->getMock('Monolog\Handler\HandlerInterface'); |
||||
$handler1->expects($this->any()) |
||||
->method('isHandling') |
||||
->will($this->returnValue(true)) |
||||
; |
||||
$handler1->expects($this->never()) |
||||
->method('handle') |
||||
; |
||||
$logger->pushHandler($handler1); |
||||
|
||||
$handler2 = $this->getMock('Monolog\Handler\HandlerInterface'); |
||||
$handler2->expects($this->any()) |
||||
->method('isHandling') |
||||
->will($this->returnValue(true)) |
||||
; |
||||
$handler2->expects($this->once()) |
||||
->method('handle') |
||||
->will($this->returnValue(true)) |
||||
; |
||||
$logger->pushHandler($handler2); |
||||
|
||||
$logger->debug('test'); |
||||
} |
||||
|
||||
/** |
||||
* @covers Monolog\Logger::isHandling |
||||
*/ |
||||
public function testIsHandling() |
||||
{ |
||||
$logger = new Logger(__METHOD__); |
||||
|
||||
$handler1 = $this->getMock('Monolog\Handler\HandlerInterface'); |
||||
$handler1->expects($this->any()) |
||||
->method('isHandling') |
||||
->will($this->returnValue(false)) |
||||
; |
||||
|
||||
$logger->pushHandler($handler1); |
||||
$this->assertFalse($logger->isHandling(Logger::DEBUG)); |
||||
|
||||
$handler2 = $this->getMock('Monolog\Handler\HandlerInterface'); |
||||
$handler2->expects($this->any()) |
||||
->method('isHandling') |
||||
->will($this->returnValue(true)) |
||||
; |
||||
|
||||
$logger->pushHandler($handler2); |
||||
$this->assertTrue($logger->isHandling(Logger::DEBUG)); |
||||
} |
||||
|
||||
/** |
||||
* @dataProvider logMethodProvider |
||||
* @covers Monolog\Logger::addDebug |
||||
* @covers Monolog\Logger::addInfo |
||||
* @covers Monolog\Logger::addNotice |
||||
* @covers Monolog\Logger::addWarning |
||||
* @covers Monolog\Logger::addError |
||||
* @covers Monolog\Logger::addCritical |
||||
* @covers Monolog\Logger::addAlert |
||||
* @covers Monolog\Logger::addEmergency |
||||
* @covers Monolog\Logger::debug |
||||
* @covers Monolog\Logger::info |
||||
* @covers Monolog\Logger::notice |
||||
* @covers Monolog\Logger::warn |
||||
* @covers Monolog\Logger::err |
||||
* @covers Monolog\Logger::crit |
||||
* @covers Monolog\Logger::alert |
||||
* @covers Monolog\Logger::emerg |
||||
*/ |
||||
public function testLogMethods($method, $expectedLevel) |
||||
{ |
||||
$logger = new Logger('foo'); |
||||
$handler = new TestHandler; |
||||
$logger->pushHandler($handler); |
||||
$logger->{$method}('test'); |
||||
list($record) = $handler->getRecords(); |
||||
$this->assertEquals($expectedLevel, $record['level']); |
||||
} |
||||
|
||||
public function logMethodProvider() |
||||
{ |
||||
return array( |
||||
// monolog methods |
||||
array('addDebug', Logger::DEBUG), |
||||
array('addInfo', Logger::INFO), |
||||
array('addNotice', Logger::NOTICE), |
||||
array('addWarning', Logger::WARNING), |
||||
array('addError', Logger::ERROR), |
||||
array('addCritical', Logger::CRITICAL), |
||||
array('addAlert', Logger::ALERT), |
||||
array('addEmergency', Logger::EMERGENCY), |
||||
|
||||
// ZF/Sf2 compat methods |
||||
array('debug', Logger::DEBUG), |
||||
array('info', Logger::INFO), |
||||
array('notice', Logger::NOTICE), |
||||
array('warn', Logger::WARNING), |
||||
array('err', Logger::ERROR), |
||||
array('crit', Logger::CRITICAL), |
||||
array('alert', Logger::ALERT), |
||||
array('emerg', Logger::EMERGENCY), |
||||
); |
||||
} |
||||
} |
||||
@ -1,65 +0,0 @@ |
||||
<?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\Processor; |
||||
|
||||
use Monolog\TestCase; |
||||
use Monolog\Handler\TestHandler; |
||||
|
||||
class IntrospectionProcessorTest extends TestCase |
||||
{ |
||||
public function getHandler() |
||||
{ |
||||
$processor = new IntrospectionProcessor(); |
||||
$handler = new TestHandler(); |
||||
$handler->pushProcessor($processor); |
||||
|
||||
return $handler; |
||||
} |
||||
|
||||
public function testProcessorFromClass() |
||||
{ |
||||
$handler = $this->getHandler(); |
||||
$tester = new \Acme\Tester; |
||||
$tester->test($handler, $this->getRecord()); |
||||
list($record) = $handler->getRecords(); |
||||
$this->assertEquals(__FILE__, $record['extra']['file']); |
||||
$this->assertEquals(58, $record['extra']['line']); |
||||
$this->assertEquals('Acme\Tester', $record['extra']['class']); |
||||
$this->assertEquals('test', $record['extra']['function']); |
||||
} |
||||
|
||||
public function testProcessorFromFunc() |
||||
{ |
||||
$handler = $this->getHandler(); |
||||
\Acme\tester($handler, $this->getRecord()); |
||||
list($record) = $handler->getRecords(); |
||||
$this->assertEquals(__FILE__, $record['extra']['file']); |
||||
$this->assertEquals(64, $record['extra']['line']); |
||||
$this->assertEquals(null, $record['extra']['class']); |
||||
$this->assertEquals('Acme\tester', $record['extra']['function']); |
||||
} |
||||
} |
||||
|
||||
namespace Acme; |
||||
|
||||
class Tester |
||||
{ |
||||
public function test($handler, $record) |
||||
{ |
||||
$handler->handle($record); |
||||
} |
||||
} |
||||
|
||||
function tester($handler, $record) |
||||
{ |
||||
$handler->handle($record); |
||||
} |
||||
@ -1,29 +0,0 @@ |
||||
<?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\Processor; |
||||
|
||||
use Monolog\TestCase; |
||||
|
||||
class MemoryPeakUsageProcessorTest extends TestCase |
||||
{ |
||||
/** |
||||
* @covers Monolog\Processor\MemoryPeakUsageProcessor::__invoke |
||||
* @covers Monolog\Processor\MemoryProcessor::formatBytes |
||||
*/ |
||||
public function testProcessor() |
||||
{ |
||||
$processor = new MemoryPeakUsageProcessor(); |
||||
$record = $processor($this->getRecord()); |
||||
$this->assertArrayHasKey('memory_peak_usage', $record['extra']); |
||||
$this->assertRegExp('#[0-9.]+ (M|K)?B$#', $record['extra']['memory_peak_usage']); |
||||
} |
||||
} |
||||
@ -1,29 +0,0 @@ |
||||
<?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\Processor; |
||||
|
||||
use Monolog\TestCase; |
||||
|
||||
class MemoryUsageProcessorTest extends TestCase |
||||
{ |
||||
/** |
||||
* @covers Monolog\Processor\MemoryUsageProcessor::__invoke |
||||
* @covers Monolog\Processor\MemoryProcessor::formatBytes |
||||
*/ |
||||
public function testProcessor() |
||||
{ |
||||
$processor = new MemoryUsageProcessor(); |
||||
$record = $processor($this->getRecord()); |
||||
$this->assertArrayHasKey('memory_usage', $record['extra']); |
||||
$this->assertRegExp('#[0-9.]+ (M|K)?B$#', $record['extra']['memory_usage']); |
||||
} |
||||
} |
||||
@ -1,30 +0,0 @@ |
||||
<?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\Processor; |
||||
|
||||
use Monolog\TestCase; |
||||
|
||||
class ProcessIdProcessorTest extends TestCase |
||||
{ |
||||
/** |
||||
* @covers Monolog\Processor\ProcessIdProcessor::__invoke |
||||
*/ |
||||
public function testProcessor() |
||||
{ |
||||
$processor = new ProcessIdProcessor(); |
||||
$record = $processor($this->getRecord()); |
||||
$this->assertArrayHasKey('process_id', $record['extra']); |
||||
$this->assertInternalType('int', $record['extra']['process_id']); |
||||
$this->assertGreaterThan(0, $record['extra']['process_id']); |
||||
$this->assertEquals(getmypid(), $record['extra']['process_id']); |
||||
} |
||||
} |
||||
@ -1,27 +0,0 @@ |
||||
<?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\Processor; |
||||
|
||||
use Monolog\TestCase; |
||||
|
||||
class UidProcessorTest extends TestCase |
||||
{ |
||||
/** |
||||
* @covers Monolog\Processor\UidProcessor::__invoke |
||||
*/ |
||||
public function testProcessor() |
||||
{ |
||||
$processor = new UidProcessor(); |
||||
$record = $processor($this->getRecord()); |
||||
$this->assertArrayHasKey('uid', $record['extra']); |
||||
} |
||||
} |
||||
@ -1,68 +0,0 @@ |
||||
<?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\Processor; |
||||
|
||||
use Monolog\TestCase; |
||||
|
||||
class WebProcessorTest extends TestCase |
||||
{ |
||||
public function testProcessor() |
||||
{ |
||||
$server = array( |
||||
'REQUEST_URI' => 'A', |
||||
'REMOTE_ADDR' => 'B', |
||||
'REQUEST_METHOD' => 'C', |
||||
'HTTP_REFERER' => 'D', |
||||
'SERVER_NAME' => 'F', |
||||
); |
||||
|
||||
$processor = new WebProcessor($server); |
||||
$record = $processor($this->getRecord()); |
||||
$this->assertEquals($server['REQUEST_URI'], $record['extra']['url']); |
||||
$this->assertEquals($server['REMOTE_ADDR'], $record['extra']['ip']); |
||||
$this->assertEquals($server['REQUEST_METHOD'], $record['extra']['http_method']); |
||||
$this->assertEquals($server['HTTP_REFERER'], $record['extra']['referrer']); |
||||
$this->assertEquals($server['SERVER_NAME'], $record['extra']['server']); |
||||
} |
||||
|
||||
public function testProcessorDoNothingIfNoRequestUri() |
||||
{ |
||||
$server = array( |
||||
'REMOTE_ADDR' => 'B', |
||||
'REQUEST_METHOD' => 'C', |
||||
); |
||||
$processor = new WebProcessor($server); |
||||
$record = $processor($this->getRecord()); |
||||
$this->assertEmpty($record['extra']); |
||||
} |
||||
|
||||
public function testProcessorReturnNullIfNoHttpReferer() |
||||
{ |
||||
$server = array( |
||||
'REQUEST_URI' => 'A', |
||||
'REMOTE_ADDR' => 'B', |
||||
'REQUEST_METHOD' => 'C', |
||||
'SERVER_NAME' => 'F', |
||||
); |
||||
$processor = new WebProcessor($server); |
||||
$record = $processor($this->getRecord()); |
||||
$this->assertNull($record['extra']['referrer']); |
||||
} |
||||
|
||||
/** |
||||
* @expectedException UnexpectedValueException |
||||
*/ |
||||
public function testInvalidData() |
||||
{ |
||||
new WebProcessor(new \stdClass); |
||||
} |
||||
} |
||||
@ -1,47 +0,0 @@ |
||||
<?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; |
||||
|
||||
use Monolog\Handler\TestHandler; |
||||
use Monolog\Formatter\LineFormatter; |
||||
use Monolog\Processor\PsrLogMessageProcessor; |
||||
use Psr\Log\Test\LoggerInterfaceTest; |
||||
|
||||
class PsrLogCompatTest extends LoggerInterfaceTest |
||||
{ |
||||
private $handler; |
||||
|
||||
public function getLogger() |
||||
{ |
||||
$logger = new Logger('foo'); |
||||
$logger->pushHandler($handler = new TestHandler); |
||||
$logger->pushProcessor(new PsrLogMessageProcessor); |
||||
$handler->setFormatter(new LineFormatter('%level_name% %message%')); |
||||
|
||||
$this->handler = $handler; |
||||
|
||||
return $logger; |
||||
} |
||||
|
||||
public function getLogs() |
||||
{ |
||||
$convert = function ($record) { |
||||
$lower = function ($match) { |
||||
return strtolower($match[0]); |
||||
}; |
||||
|
||||
return preg_replace_callback('{^[A-Z]+}', $lower, $record['formatted']); |
||||
}; |
||||
|
||||
return array_map($convert, $this->handler->getRecords()); |
||||
} |
||||
} |
||||
@ -1,58 +0,0 @@ |
||||
<?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; |
||||
|
||||
class TestCase extends \PHPUnit_Framework_TestCase |
||||
{ |
||||
/** |
||||
* @return array Record |
||||
*/ |
||||
protected function getRecord($level = Logger::WARNING, $message = 'test', $context = array()) |
||||
{ |
||||
return array( |
||||
'message' => $message, |
||||
'context' => $context, |
||||
'level' => $level, |
||||
'level_name' => Logger::getLevelName($level), |
||||
'channel' => 'test', |
||||
'datetime' => \DateTime::createFromFormat('U.u', sprintf('%.6F', microtime(true))), |
||||
'extra' => array(), |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @return array |
||||
*/ |
||||
protected function getMultipleRecords() |
||||
{ |
||||
return array( |
||||
$this->getRecord(Logger::DEBUG, 'debug message 1'), |
||||
$this->getRecord(Logger::DEBUG, 'debug message 2'), |
||||
$this->getRecord(Logger::INFO, 'information'), |
||||
$this->getRecord(Logger::WARNING, 'warning'), |
||||
$this->getRecord(Logger::ERROR, 'error') |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @return Monolog\Formatter\FormatterInterface |
||||
*/ |
||||
protected function getIdentityFormatter() |
||||
{ |
||||
$formatter = $this->getMock('Monolog\\Formatter\\FormatterInterface'); |
||||
$formatter->expects($this->any()) |
||||
->method('format') |
||||
->will($this->returnCallback(function($record) { return $record['message']; })); |
||||
|
||||
return $formatter; |
||||
} |
||||
} |
||||
@ -1,13 +0,0 @@ |
||||
<?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. |
||||
*/ |
||||
|
||||
$loader = require_once __DIR__ . "/../vendor/autoload.php"; |
||||
$loader->add('Monolog\\', __DIR__); |
||||
@ -1,63 +0,0 @@ |
||||
<?php |
||||
|
||||
define('ERR_SELECT_FAILED', 1); |
||||
define('ERR_TIMEOUT', 2); |
||||
define('ERR_READ_FAILED', 3); |
||||
define('ERR_WRITE_FAILED', 4); |
||||
|
||||
$read = array(STDIN); |
||||
$write = array(STDOUT, STDERR); |
||||
|
||||
stream_set_blocking(STDIN, false); |
||||
stream_set_blocking(STDOUT, false); |
||||
stream_set_blocking(STDERR, false); |
||||
|
||||
$out = $err = ''; |
||||
while ($read || $write) { |
||||
$r = $read; |
||||
$w = $write; |
||||
$e = null; |
||||
$n = stream_select($r, $w, $e, 5); |
||||
|
||||
if (false === $n) { |
||||
die(ERR_SELECT_FAILED); |
||||
} elseif ($n < 1) { |
||||
die(ERR_TIMEOUT); |
||||
} |
||||
|
||||
if (in_array(STDOUT, $w) && strlen($out) > 0) { |
||||
$written = fwrite(STDOUT, (binary) $out, 1024); |
||||
if (false === $written) { |
||||
die(ERR_WRITE_FAILED); |
||||
} |
||||
$out = (binary) substr($out, $written); |
||||
} |
||||
if (null === $read && strlen($out) < 1) { |
||||
$write = array_diff($write, array(STDOUT)); |
||||
} |
||||
|
||||
if (in_array(STDERR, $w) && strlen($err) > 0) { |
||||
$written = fwrite(STDERR, (binary) $err, 1024); |
||||
if (false === $written) { |
||||
die(ERR_WRITE_FAILED); |
||||
} |
||||
$err = (binary) substr($err, $written); |
||||
} |
||||
if (null === $read && strlen($err) < 1) { |
||||
$write = array_diff($write, array(STDERR)); |
||||
} |
||||
|
||||
if ($r) { |
||||
$str = fread(STDIN, 1024); |
||||
if (false !== $str) { |
||||
$out .= $str; |
||||
$err .= $str; |
||||
} |
||||
if (false === $str || feof(STDIN)) { |
||||
$read = null; |
||||
if (!feof(STDIN)) { |
||||
die(ERR_READ_FAILED); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue