mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-18 02:41:24 +02:00
Merge PhpAmqlLibHandler into the AmqpHandler, refs #389
This commit is contained in:
@@ -13,13 +13,16 @@ namespace Monolog\Handler;
|
||||
|
||||
use Monolog\TestCase;
|
||||
use Monolog\Logger;
|
||||
use PhpAmqpLib\Message\AMQPMessage;
|
||||
use PhpAmqpLib\Channel\AMQPChannel;
|
||||
use PhpAmqpLib\Connection\AMQPConnection;
|
||||
|
||||
/**
|
||||
* @covers Monolog\Handler\RotatingFileHandler
|
||||
*/
|
||||
class AmqpHandlerTest extends TestCase
|
||||
{
|
||||
public function setUp()
|
||||
public function testHandleAmqpExt()
|
||||
{
|
||||
if (!class_exists('AMQPConnection') || !class_exists('AMQPExchange')) {
|
||||
$this->markTestSkipped("amqp-php not installed");
|
||||
@@ -28,10 +31,7 @@ class AmqpHandlerTest extends TestCase
|
||||
if (!class_exists('AMQPChannel')) {
|
||||
$this->markTestSkipped("Please update AMQP to version >= 1.0");
|
||||
}
|
||||
}
|
||||
|
||||
public function testHandle()
|
||||
{
|
||||
$messages = array();
|
||||
|
||||
$exchange = $this->getMock('AMQPExchange', array('publish', 'setName'), array(), '', false);
|
||||
@@ -77,4 +77,61 @@ class AmqpHandlerTest extends TestCase
|
||||
unset($messages[0][0]['datetime']);
|
||||
$this->assertEquals($expected, $messages[0]);
|
||||
}
|
||||
|
||||
public function testHandlePhpAmqpLib()
|
||||
{
|
||||
if (!class_exists('PhpAmqpLib\Connection\AMQPConnection')) {
|
||||
$this->markTestSkipped("php-amqplib not installed");
|
||||
}
|
||||
|
||||
$messages = array();
|
||||
|
||||
$exchange = $this->getMock('PhpAmqpLib\Channel\AMQPChannel', array('basic_publish', '__destruct'), array(), '', false);
|
||||
|
||||
$exchange->expects($this->any())
|
||||
->method('basic_publish')
|
||||
->will($this->returnCallback(function (AMQPMessage $msg, $exchange = "", $routing_key = "", $mandatory = false, $immediate = false, $ticket = null) use (&$messages) {
|
||||
$messages[] = array($msg, $exchange, $routing_key, $mandatory, $immediate, $ticket);
|
||||
}))
|
||||
;
|
||||
|
||||
$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(),
|
||||
),
|
||||
'log',
|
||||
'warn.test',
|
||||
false,
|
||||
false,
|
||||
null,
|
||||
array(
|
||||
'delivery_mode' => 2,
|
||||
'content_type' => 'application/json'
|
||||
)
|
||||
);
|
||||
|
||||
$handler->handle($record);
|
||||
|
||||
$this->assertCount(1, $messages);
|
||||
|
||||
/* @var $msg AMQPMessage */
|
||||
$msg = $messages[0][0];
|
||||
$messages[0][0] = json_decode($msg->body, true);
|
||||
$messages[0][] = $msg->get_properties();
|
||||
unset($messages[0][0]['datetime']);
|
||||
|
||||
$this->assertEquals($expected, $messages[0]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user