ILIAS  release_5-2 Revision v5.2.25-18-g3f80b82851
Monolog\Handler\HipChatHandlerTest Class Reference
+ Inheritance diagram for Monolog\Handler\HipChatHandlerTest:
+ Collaboration diagram for Monolog\Handler\HipChatHandlerTest:

Public Member Functions

 testWriteHeader ()
 
 testWriteCustomHostHeader ()
 
 testWriteV2 ()
 
 testWriteV2Notify ()
 
 testRoomSpaces ()
 
 testWriteContent ($content)
 testWriteHeader More...
 
 testWriteContentV1WithoutName ()
 
 testWriteContentNotify ($content)
 testWriteCustomHostHeader More...
 
 testWriteContentV2 ($content)
 testWriteV2 More...
 
 testWriteContentV2Notify ($content)
 testWriteV2Notify More...
 
 testWriteContentV2WithoutName ()
 
 testWriteWithComplexMessage ()
 
 testWriteTruncatesLongMessage ()
 
 testWriteWithErrorLevelsAndColors ($level, $expectedColor)
 provideLevelColors More...
 
 provideLevelColors ()
 
 testHandleBatch ($records, $expectedColor)
 provideBatchRecords More...
 
 provideBatchRecords ()
 
 testCreateWithTooLongName ()
 InvalidArgumentException More...
 
 testCreateWithTooLongNameV2 ()
 

Private Member Functions

 createHandler ($token='myToken', $room='room1', $name='Monolog', $notify=false, $host='api.hipchat.com', $version='v1')
 

Private Attributes

 $res
 
 $handler
 

Additional Inherited Members

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

Detailed Description

Author
Rafael Dohms rafae.nosp@m.l@do.nosp@m.h.ms
See also
https://www.hipchat.com/docs/api

Definition at line 21 of file HipChatHandlerTest.php.

Member Function Documentation

◆ createHandler()

Monolog\Handler\HipChatHandlerTest::createHandler (   $token = 'myToken',
  $room = 'room1',
  $name = 'Monolog',
  $notify = false,
  $host = 'api.hipchat.com',
  $version = 'v1' 
)
private

Definition at line 239 of file HipChatHandlerTest.php.

References $version, array, Monolog\Logger\DEBUG, and Monolog\TestCase\getIdentityFormatter().

Referenced by Monolog\Handler\HipChatHandlerTest\testHandleBatch(), Monolog\Handler\HipChatHandlerTest\testRoomSpaces(), Monolog\Handler\HipChatHandlerTest\testWriteContentV1WithoutName(), Monolog\Handler\HipChatHandlerTest\testWriteContentV2WithoutName(), Monolog\Handler\HipChatHandlerTest\testWriteCustomHostHeader(), Monolog\Handler\HipChatHandlerTest\testWriteHeader(), Monolog\Handler\HipChatHandlerTest\testWriteTruncatesLongMessage(), Monolog\Handler\HipChatHandlerTest\testWriteV2(), Monolog\Handler\HipChatHandlerTest\testWriteV2Notify(), Monolog\Handler\HipChatHandlerTest\testWriteWithComplexMessage(), and Monolog\Handler\HipChatHandlerTest\testWriteWithErrorLevelsAndColors().

240  {
241  $constructorArgs = array($token, $room, $name, $notify, Logger::DEBUG, true, true, 'text', $host, $version);
242  $this->res = fopen('php://memory', 'a');
243  $this->handler = $this->getMock(
244  '\Monolog\Handler\HipChatHandler',
245  array('fsockopen', 'streamSetTimeout', 'closeSocket'),
246  $constructorArgs
247  );
248 
249  $reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString');
250  $reflectionProperty->setAccessible(true);
251  $reflectionProperty->setValue($this->handler, 'localhost:1234');
252 
253  $this->handler->expects($this->any())
254  ->method('fsockopen')
255  ->will($this->returnValue($this->res));
256  $this->handler->expects($this->any())
257  ->method('streamSetTimeout')
258  ->will($this->returnValue(true));
259  $this->handler->expects($this->any())
260  ->method('closeSocket')
261  ->will($this->returnValue(true));
262 
263  $this->handler->setFormatter($this->getIdentityFormatter());
264  }
const DEBUG
Detailed debug information.
Definition: Logger.php:32
Create styles array
The data for the language used.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ provideBatchRecords()

Monolog\Handler\HipChatHandlerTest::provideBatchRecords ( )

Definition at line 205 of file HipChatHandlerTest.php.

References array, Monolog\Logger\CRITICAL, Monolog\Logger\DEBUG, Monolog\Logger\NOTICE, and Monolog\Logger\WARNING.

206  {
207  return array(
208  array(
209  array(
210  array('level' => Logger::WARNING, 'message' => 'Oh bugger!', 'level_name' => 'warning', 'datetime' => new \DateTime()),
211  array('level' => Logger::NOTICE, 'message' => 'Something noticeable happened.', 'level_name' => 'notice', 'datetime' => new \DateTime()),
212  array('level' => Logger::CRITICAL, 'message' => 'Everything is broken!', 'level_name' => 'critical', 'datetime' => new \DateTime()),
213  ),
214  'red',
215  ),
216  array(
217  array(
218  array('level' => Logger::WARNING, 'message' => 'Oh bugger!', 'level_name' => 'warning', 'datetime' => new \DateTime()),
219  array('level' => Logger::NOTICE, 'message' => 'Something noticeable happened.', 'level_name' => 'notice', 'datetime' => new \DateTime()),
220  ),
221  'yellow',
222  ),
223  array(
224  array(
225  array('level' => Logger::DEBUG, 'message' => 'Just debugging.', 'level_name' => 'debug', 'datetime' => new \DateTime()),
226  array('level' => Logger::NOTICE, 'message' => 'Something noticeable happened.', 'level_name' => 'notice', 'datetime' => new \DateTime()),
227  ),
228  'green',
229  ),
230  array(
231  array(
232  array('level' => Logger::DEBUG, 'message' => 'Just debugging.', 'level_name' => 'debug', 'datetime' => new \DateTime()),
233  ),
234  'gray',
235  ),
236  );
237  }
const NOTICE
Uncommon events.
Definition: Logger.php:44
const DEBUG
Detailed debug information.
Definition: Logger.php:32
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
Create styles array
The data for the language used.
const CRITICAL
Critical conditions.
Definition: Logger.php:64

◆ provideLevelColors()

Monolog\Handler\HipChatHandlerTest::provideLevelColors ( )

Definition at line 176 of file HipChatHandlerTest.php.

References Monolog\Logger\ALERT, array, Monolog\Logger\CRITICAL, Monolog\Logger\DEBUG, Monolog\Logger\EMERGENCY, Monolog\Logger\ERROR, Monolog\Logger\INFO, Monolog\Logger\NOTICE, and Monolog\Logger\WARNING.

177  {
178  return array(
179  array(Logger::DEBUG, 'gray'),
180  array(Logger::INFO, 'green'),
181  array(Logger::WARNING, 'yellow'),
182  array(Logger::ERROR, 'red'),
183  array(Logger::CRITICAL, 'red'),
184  array(Logger::ALERT, 'red'),
185  array(Logger::EMERGENCY,'red'),
186  array(Logger::NOTICE, 'green'),
187  );
188  }
const NOTICE
Uncommon events.
Definition: Logger.php:44
const DEBUG
Detailed debug information.
Definition: Logger.php:32
const ERROR
Runtime errors.
Definition: Logger.php:57
const WARNING
Exceptional occurrences that are not errors.
Definition: Logger.php:52
const EMERGENCY
Urgent alert.
Definition: Logger.php:77
Create styles array
The data for the language used.
const CRITICAL
Critical conditions.
Definition: Logger.php:64
const ALERT
Action must be taken immediately.
Definition: Logger.php:72
const INFO
Interesting events.
Definition: Logger.php:39

◆ testCreateWithTooLongName()

Monolog\Handler\HipChatHandlerTest::testCreateWithTooLongName ( )

InvalidArgumentException

Definition at line 269 of file HipChatHandlerTest.php.

270  {
271  $hipChatHandler = new HipChatHandler('token', 'room', 'SixteenCharsHere');
272  }

◆ testCreateWithTooLongNameV2()

Monolog\Handler\HipChatHandlerTest::testCreateWithTooLongNameV2 ( )

Definition at line 274 of file HipChatHandlerTest.php.

References Monolog\Logger\CRITICAL.

275  {
276  // creating a handler with too long of a name but using the v2 api doesn't matter.
277  $hipChatHandler = new HipChatHandler('token', 'room', 'SixteenCharsHere', false, Logger::CRITICAL, true, true, 'test', 'api.hipchat.com', 'v2');
278  }
const CRITICAL
Critical conditions.
Definition: Logger.php:64

◆ testHandleBatch()

Monolog\Handler\HipChatHandlerTest::testHandleBatch (   $records,
  $expectedColor 
)

provideBatchRecords

Definition at line 193 of file HipChatHandlerTest.php.

References $records, and Monolog\Handler\HipChatHandlerTest\createHandler().

194  {
195  $this->createHandler();
196 
197  $this->handler->handleBatch($records);
198 
199  fseek($this->res, 0);
200  $content = fread($this->res, 1024);
201 
202  $this->assertRegexp('/color='.$expectedColor.'/', $content);
203  }
createHandler($token='myToken', $room='room1', $name='Monolog', $notify=false, $host='api.hipchat.com', $version='v1')
$records
Definition: simple_test.php:22
+ Here is the call graph for this function:

◆ testRoomSpaces()

Monolog\Handler\HipChatHandlerTest::testRoomSpaces ( )

Definition at line 75 of file HipChatHandlerTest.php.

References Monolog\Handler\HipChatHandlerTest\createHandler(), Monolog\Logger\CRITICAL, and Monolog\TestCase\getRecord().

76  {
77  $this->createHandler('myToken', 'room name', 'Monolog', false, 'hipchat.foo.bar', 'v2');
78  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
79  fseek($this->res, 0);
80  $content = fread($this->res, 1024);
81 
82  $this->assertRegexp('/POST \/v2\/room\/room%20name\/notification\?auth_token=.* HTTP\/1.1\\r\\nHost: hipchat.foo.bar\\r\\nContent-Type: application\/x-www-form-urlencoded\\r\\nContent-Length: \d{2,4}\\r\\n\\r\\n/', $content);
83 
84  return $content;
85  }
createHandler($token='myToken', $room='room1', $name='Monolog', $notify=false, $host='api.hipchat.com', $version='v1')
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
const CRITICAL
Critical conditions.
Definition: Logger.php:64
+ Here is the call graph for this function:

◆ testWriteContent()

Monolog\Handler\HipChatHandlerTest::testWriteContent (   $content)

testWriteHeader

Definition at line 90 of file HipChatHandlerTest.php.

91  {
92  $this->assertRegexp('/notify=0&message=test1&message_format=text&color=red&room_id=room1&from=Monolog$/', $content);
93  }

◆ testWriteContentNotify()

Monolog\Handler\HipChatHandlerTest::testWriteContentNotify (   $content)

testWriteCustomHostHeader

Definition at line 110 of file HipChatHandlerTest.php.

111  {
112  $this->assertRegexp('/notify=1&message=test1&message_format=text&color=red&room_id=room1&from=Monolog$/', $content);
113  }

◆ testWriteContentV1WithoutName()

Monolog\Handler\HipChatHandlerTest::testWriteContentV1WithoutName ( )

Definition at line 95 of file HipChatHandlerTest.php.

References Monolog\Handler\HipChatHandlerTest\createHandler(), Monolog\Logger\CRITICAL, and Monolog\TestCase\getRecord().

96  {
97  $this->createHandler('myToken', 'room1', null, false, 'hipchat.foo.bar', 'v1');
98  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
99  fseek($this->res, 0);
100  $content = fread($this->res, 1024);
101 
102  $this->assertRegexp('/notify=0&message=test1&message_format=text&color=red&room_id=room1&from=$/', $content);
103 
104  return $content;
105  }
createHandler($token='myToken', $room='room1', $name='Monolog', $notify=false, $host='api.hipchat.com', $version='v1')
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
const CRITICAL
Critical conditions.
Definition: Logger.php:64
+ Here is the call graph for this function:

◆ testWriteContentV2()

Monolog\Handler\HipChatHandlerTest::testWriteContentV2 (   $content)

testWriteV2

Definition at line 118 of file HipChatHandlerTest.php.

119  {
120  $this->assertRegexp('/notify=false&message=test1&message_format=text&color=red&from=Monolog$/', $content);
121  }

◆ testWriteContentV2Notify()

Monolog\Handler\HipChatHandlerTest::testWriteContentV2Notify (   $content)

testWriteV2Notify

Definition at line 126 of file HipChatHandlerTest.php.

127  {
128  $this->assertRegexp('/notify=true&message=test1&message_format=text&color=red&from=Monolog$/', $content);
129  }

◆ testWriteContentV2WithoutName()

Monolog\Handler\HipChatHandlerTest::testWriteContentV2WithoutName ( )

Definition at line 131 of file HipChatHandlerTest.php.

References Monolog\Handler\HipChatHandlerTest\createHandler(), Monolog\Logger\CRITICAL, and Monolog\TestCase\getRecord().

132  {
133  $this->createHandler('myToken', 'room1', null, false, 'hipchat.foo.bar', 'v2');
134  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
135  fseek($this->res, 0);
136  $content = fread($this->res, 1024);
137 
138  $this->assertRegexp('/notify=false&message=test1&message_format=text&color=red$/', $content);
139 
140  return $content;
141  }
createHandler($token='myToken', $room='room1', $name='Monolog', $notify=false, $host='api.hipchat.com', $version='v1')
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
const CRITICAL
Critical conditions.
Definition: Logger.php:64
+ Here is the call graph for this function:

◆ testWriteCustomHostHeader()

Monolog\Handler\HipChatHandlerTest::testWriteCustomHostHeader ( )

Definition at line 39 of file HipChatHandlerTest.php.

References Monolog\Handler\HipChatHandlerTest\createHandler(), Monolog\Logger\CRITICAL, and Monolog\TestCase\getRecord().

40  {
41  $this->createHandler('myToken', 'room1', 'Monolog', true, 'hipchat.foo.bar');
42  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
43  fseek($this->res, 0);
44  $content = fread($this->res, 1024);
45 
46  $this->assertRegexp('/POST \/v1\/rooms\/message\?format=json&auth_token=.* HTTP\/1.1\\r\\nHost: hipchat.foo.bar\\r\\nContent-Type: application\/x-www-form-urlencoded\\r\\nContent-Length: \d{2,4}\\r\\n\\r\\n/', $content);
47 
48  return $content;
49  }
createHandler($token='myToken', $room='room1', $name='Monolog', $notify=false, $host='api.hipchat.com', $version='v1')
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
const CRITICAL
Critical conditions.
Definition: Logger.php:64
+ Here is the call graph for this function:

◆ testWriteHeader()

Monolog\Handler\HipChatHandlerTest::testWriteHeader ( )

Definition at line 27 of file HipChatHandlerTest.php.

References Monolog\Handler\HipChatHandlerTest\createHandler(), Monolog\Logger\CRITICAL, and Monolog\TestCase\getRecord().

28  {
29  $this->createHandler();
30  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
31  fseek($this->res, 0);
32  $content = fread($this->res, 1024);
33 
34  $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);
35 
36  return $content;
37  }
createHandler($token='myToken', $room='room1', $name='Monolog', $notify=false, $host='api.hipchat.com', $version='v1')
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
const CRITICAL
Critical conditions.
Definition: Logger.php:64
+ Here is the call graph for this function:

◆ testWriteTruncatesLongMessage()

Monolog\Handler\HipChatHandlerTest::testWriteTruncatesLongMessage ( )

Definition at line 153 of file HipChatHandlerTest.php.

References Monolog\Handler\HipChatHandlerTest\createHandler(), Monolog\Logger\CRITICAL, and Monolog\TestCase\getRecord().

154  {
155  $this->createHandler();
156  $this->handler->handle($this->getRecord(Logger::CRITICAL, str_repeat('abcde', 2000)));
157  fseek($this->res, 0);
158  $content = fread($this->res, 12000);
159 
160  $this->assertRegexp('/message='.str_repeat('abcde', 1900).'\+%5Btruncated%5D/', $content);
161  }
createHandler($token='myToken', $room='room1', $name='Monolog', $notify=false, $host='api.hipchat.com', $version='v1')
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
const CRITICAL
Critical conditions.
Definition: Logger.php:64
+ Here is the call graph for this function:

◆ testWriteV2()

Monolog\Handler\HipChatHandlerTest::testWriteV2 ( )

Definition at line 51 of file HipChatHandlerTest.php.

References Monolog\Handler\HipChatHandlerTest\createHandler(), Monolog\Logger\CRITICAL, and Monolog\TestCase\getRecord().

52  {
53  $this->createHandler('myToken', 'room1', 'Monolog', false, 'hipchat.foo.bar', 'v2');
54  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
55  fseek($this->res, 0);
56  $content = fread($this->res, 1024);
57 
58  $this->assertRegexp('/POST \/v2\/room\/room1\/notification\?auth_token=.* HTTP\/1.1\\r\\nHost: hipchat.foo.bar\\r\\nContent-Type: application\/x-www-form-urlencoded\\r\\nContent-Length: \d{2,4}\\r\\n\\r\\n/', $content);
59 
60  return $content;
61  }
createHandler($token='myToken', $room='room1', $name='Monolog', $notify=false, $host='api.hipchat.com', $version='v1')
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
const CRITICAL
Critical conditions.
Definition: Logger.php:64
+ Here is the call graph for this function:

◆ testWriteV2Notify()

Monolog\Handler\HipChatHandlerTest::testWriteV2Notify ( )

Definition at line 63 of file HipChatHandlerTest.php.

References Monolog\Handler\HipChatHandlerTest\createHandler(), Monolog\Logger\CRITICAL, and Monolog\TestCase\getRecord().

64  {
65  $this->createHandler('myToken', 'room1', 'Monolog', true, 'hipchat.foo.bar', 'v2');
66  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
67  fseek($this->res, 0);
68  $content = fread($this->res, 1024);
69 
70  $this->assertRegexp('/POST \/v2\/room\/room1\/notification\?auth_token=.* HTTP\/1.1\\r\\nHost: hipchat.foo.bar\\r\\nContent-Type: application\/x-www-form-urlencoded\\r\\nContent-Length: \d{2,4}\\r\\n\\r\\n/', $content);
71 
72  return $content;
73  }
createHandler($token='myToken', $room='room1', $name='Monolog', $notify=false, $host='api.hipchat.com', $version='v1')
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
const CRITICAL
Critical conditions.
Definition: Logger.php:64
+ Here is the call graph for this function:

◆ testWriteWithComplexMessage()

Monolog\Handler\HipChatHandlerTest::testWriteWithComplexMessage ( )

Definition at line 143 of file HipChatHandlerTest.php.

References Monolog\Handler\HipChatHandlerTest\createHandler(), Monolog\Logger\CRITICAL, and Monolog\TestCase\getRecord().

144  {
145  $this->createHandler();
146  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'Backup of database "example" finished in 16 minutes.'));
147  fseek($this->res, 0);
148  $content = fread($this->res, 1024);
149 
150  $this->assertRegexp('/message=Backup\+of\+database\+%22example%22\+finished\+in\+16\+minutes\./', $content);
151  }
createHandler($token='myToken', $room='room1', $name='Monolog', $notify=false, $host='api.hipchat.com', $version='v1')
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
const CRITICAL
Critical conditions.
Definition: Logger.php:64
+ Here is the call graph for this function:

◆ testWriteWithErrorLevelsAndColors()

Monolog\Handler\HipChatHandlerTest::testWriteWithErrorLevelsAndColors (   $level,
  $expectedColor 
)

provideLevelColors

Definition at line 166 of file HipChatHandlerTest.php.

References Monolog\Handler\HipChatHandlerTest\createHandler(), and Monolog\TestCase\getRecord().

167  {
168  $this->createHandler();
169  $this->handler->handle($this->getRecord($level, 'Backup of database "example" finished in 16 minutes.'));
170  fseek($this->res, 0);
171  $content = fread($this->res, 1024);
172 
173  $this->assertRegexp('/color='.$expectedColor.'/', $content);
174  }
createHandler($token='myToken', $room='room1', $name='Monolog', $notify=false, $host='api.hipchat.com', $version='v1')
getRecord($level=Logger::WARNING, $message='test', $context=array())
Definition: TestCase.php:19
+ Here is the call graph for this function:

Field Documentation

◆ $handler

Monolog\Handler\HipChatHandlerTest::$handler
private

Definition at line 25 of file HipChatHandlerTest.php.

◆ $res

Monolog\Handler\HipChatHandlerTest::$res
private

Definition at line 23 of file HipChatHandlerTest.php.


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