ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
Monolog\Handler\AmqpHandlerTest Class Reference

@covers Monolog\Handler\RotatingFileHandler More...

+ Inheritance diagram for Monolog\Handler\AmqpHandlerTest:
+ Collaboration diagram for Monolog\Handler\AmqpHandlerTest:

Public Member Functions

 testHandleAmqpExt ()
 
 testHandlePhpAmqpLib ()
 

Additional Inherited Members

- Protected Member Functions inherited from Monolog\TestCase
 getRecord ($level=Logger::WARNING, $message='test', $context=array())
 
 getMultipleRecords ()
 
 getIdentityFormatter ()
 

Detailed Description

@covers Monolog\Handler\RotatingFileHandler

Definition at line 22 of file AmqpHandlerTest.php.

Member Function Documentation

◆ testHandleAmqpExt()

Monolog\Handler\AmqpHandlerTest::testHandleAmqpExt ( )

Definition at line 24 of file AmqpHandlerTest.php.

25 {
26 if (!class_exists('AMQPConnection') || !class_exists('AMQPExchange')) {
27 $this->markTestSkipped("amqp-php not installed");
28 }
29
30 if (!class_exists('AMQPChannel')) {
31 $this->markTestSkipped("Please update AMQP to version >= 1.0");
32 }
33
34 $messages = array();
35
36 $exchange = $this->getMock('AMQPExchange', array('publish', 'setName'), array(), '', false);
37 $exchange->expects($this->once())
38 ->method('setName')
39 ->with('log')
40 ;
41 $exchange->expects($this->any())
42 ->method('publish')
43 ->will($this->returnCallback(function ($message, $routing_key, $flags = 0, $attributes = array()) use (&$messages) {
44 $messages[] = array($message, $routing_key, $flags, $attributes);
45 }))
46 ;
47
48 $handler = new AmqpHandler($exchange, 'log');
49
50 $record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34));
51
52 $expected = array(
53 array(
54 'message' => 'test',
55 'context' => array(
56 'data' => array(),
57 'foo' => 34,
58 ),
59 'level' => 300,
60 'level_name' => 'WARNING',
61 'channel' => 'test',
62 'extra' => array(),
63 ),
64 'warn.test',
65 0,
66 array(
67 'delivery_mode' => 2,
68 'Content-type' => 'application/json'
69 )
70 );
71
72 $handler->handle($record);
73
74 $this->assertCount(1, $messages);
75 $messages[0][0] = json_decode($messages[0][0], true);
76 unset($messages[0][0]['datetime']);
77 $this->assertEquals($expected, $messages[0]);
78 }
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
$messages
Definition: en-x-test.php:7

References $messages, Monolog\TestCase\getRecord(), and Monolog\Logger\WARNING.

+ Here is the call graph for this function:

◆ testHandlePhpAmqpLib()

Monolog\Handler\AmqpHandlerTest::testHandlePhpAmqpLib ( )

Definition at line 80 of file AmqpHandlerTest.php.

81 {
82 if (!class_exists('PhpAmqpLib\Connection\AMQPConnection')) {
83 $this->markTestSkipped("php-amqplib not installed");
84 }
85
86 $messages = array();
87
88 $exchange = $this->getMock('PhpAmqpLib\Channel\AMQPChannel', array('basic_publish', '__destruct'), array(), '', false);
89
90 $exchange->expects($this->any())
91 ->method('basic_publish')
92 ->will($this->returnCallback(function (AMQPMessage $msg, $exchange = "", $routing_key = "", $mandatory = false, $immediate = false, $ticket = null) use (&$messages) {
93 $messages[] = array($msg, $exchange, $routing_key, $mandatory, $immediate, $ticket);
94 }))
95 ;
96
97 $handler = new AmqpHandler($exchange, 'log');
98
99 $record = $this->getRecord(Logger::WARNING, 'test', array('data' => new \stdClass, 'foo' => 34));
100
101 $expected = array(
102 array(
103 'message' => 'test',
104 'context' => array(
105 'data' => array(),
106 'foo' => 34,
107 ),
108 'level' => 300,
109 'level_name' => 'WARNING',
110 'channel' => 'test',
111 'extra' => array(),
112 ),
113 'log',
114 'warn.test',
115 false,
116 false,
117 null,
118 array(
119 'delivery_mode' => 2,
120 'content_type' => 'application/json'
121 )
122 );
123
124 $handler->handle($record);
125
126 $this->assertCount(1, $messages);
127
128 /* @var $msg AMQPMessage */
129 $msg = $messages[0][0];
130 $messages[0][0] = json_decode($msg->body, true);
131 $messages[0][] = $msg->get_properties();
132 unset($messages[0][0]['datetime']);
133
134 $this->assertEquals($expected, $messages[0]);
135 }

References $messages, Monolog\TestCase\getRecord(), and Monolog\Logger\WARNING.

+ Here is the call graph for this function:

The documentation for this class was generated from the following file: