ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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...
 
 testWriteContentNotify ($content)
 testWriteCustomHostHeader More...
 
 testWriteContentV2 ($content)
 testWriteV2 More...
 
 testWriteContentV2Notify ($content)
 testWriteV2Notify More...
 
 testWriteWithComplexMessage ()
 
 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 201 of file HipChatHandlerTest.php.

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

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

202  {
203  $constructorArgs = array($token, $room, $name, $notify, Logger::DEBUG, true, true, 'text', $host, $version);
204  $this->res = fopen('php://memory', 'a');
205  $this->handler = $this->getMock(
206  '\Monolog\Handler\HipChatHandler',
207  array('fsockopen', 'streamSetTimeout', 'closeSocket'),
208  $constructorArgs
209  );
210 
211  $reflectionProperty = new \ReflectionProperty('\Monolog\Handler\SocketHandler', 'connectionString');
212  $reflectionProperty->setAccessible(true);
213  $reflectionProperty->setValue($this->handler, 'localhost:1234');
214 
215  $this->handler->expects($this->any())
216  ->method('fsockopen')
217  ->will($this->returnValue($this->res));
218  $this->handler->expects($this->any())
219  ->method('streamSetTimeout')
220  ->will($this->returnValue(true));
221  $this->handler->expects($this->any())
222  ->method('closeSocket')
223  ->will($this->returnValue(true));
224 
225  $this->handler->setFormatter($this->getIdentityFormatter());
226  }
const DEBUG
Detailed debug information.
Definition: Logger.php:32
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ provideBatchRecords()

Monolog\Handler\HipChatHandlerTest::provideBatchRecords ( )

Definition at line 167 of file HipChatHandlerTest.php.

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

168  {
169  return array(
170  array(
171  array(
172  array('level' => Logger::WARNING, 'message' => 'Oh bugger!', 'level_name' => 'warning', 'datetime' => new \DateTime()),
173  array('level' => Logger::NOTICE, 'message' => 'Something noticeable happened.', 'level_name' => 'notice', 'datetime' => new \DateTime()),
174  array('level' => Logger::CRITICAL, 'message' => 'Everything is broken!', 'level_name' => 'critical', 'datetime' => new \DateTime())
175  ),
176  'red',
177  ),
178  array(
179  array(
180  array('level' => Logger::WARNING, 'message' => 'Oh bugger!', 'level_name' => 'warning', 'datetime' => new \DateTime()),
181  array('level' => Logger::NOTICE, 'message' => 'Something noticeable happened.', 'level_name' => 'notice', 'datetime' => new \DateTime()),
182  ),
183  'yellow',
184  ),
185  array(
186  array(
187  array('level' => Logger::DEBUG, 'message' => 'Just debugging.', 'level_name' => 'debug', 'datetime' => new \DateTime()),
188  array('level' => Logger::NOTICE, 'message' => 'Something noticeable happened.', 'level_name' => 'notice', 'datetime' => new \DateTime()),
189  ),
190  'green',
191  ),
192  array(
193  array(
194  array('level' => Logger::DEBUG, 'message' => 'Just debugging.', 'level_name' => 'debug', 'datetime' => new \DateTime()),
195  ),
196  'gray',
197  ),
198  );
199  }
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
const CRITICAL
Critical conditions.
Definition: Logger.php:64

◆ provideLevelColors()

Monolog\Handler\HipChatHandlerTest::provideLevelColors ( )

Definition at line 138 of file HipChatHandlerTest.php.

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

139  {
140  return array(
141  array(Logger::DEBUG, 'gray'),
142  array(Logger::INFO, 'green'),
143  array(Logger::WARNING, 'yellow'),
144  array(Logger::ERROR, 'red'),
145  array(Logger::CRITICAL, 'red'),
146  array(Logger::ALERT, 'red'),
147  array(Logger::EMERGENCY,'red'),
148  array(Logger::NOTICE, 'green'),
149  );
150  }
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
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 231 of file HipChatHandlerTest.php.

232  {
233  $hipChatHandler = new \Monolog\Handler\HipChatHandler('token', 'room', 'SixteenCharsHere');
234  }

◆ testCreateWithTooLongNameV2()

Monolog\Handler\HipChatHandlerTest::testCreateWithTooLongNameV2 ( )

Definition at line 236 of file HipChatHandlerTest.php.

References Monolog\Logger\CRITICAL.

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

◆ testHandleBatch()

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

provideBatchRecords

Definition at line 155 of file HipChatHandlerTest.php.

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

156  {
157  $this->createHandler();
158 
159  $this->handler->handleBatch($records);
160 
161  fseek($this->res, 0);
162  $content = fread($this->res, 1024);
163 
164  $this->assertRegexp('/color='.$expectedColor.'/', $content);
165  }
createHandler($token='myToken', $room='room1', $name='Monolog', $notify=false, $host='api.hipchat.com', $version='v1')
$records
Definition: simple_test.php:17
+ Here is the call graph for this function:

◆ testRoomSpaces()

Monolog\Handler\HipChatHandlerTest::testRoomSpaces ( )

Definition at line 72 of file HipChatHandlerTest.php.

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

72  {
73  $this->createHandler('myToken', 'room name', 'Monolog', false, 'hipchat.foo.bar', 'v2');
74  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
75  fseek($this->res, 0);
76  $content = fread($this->res, 1024);
77 
78  $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);
79 
80  return $content;
81  }
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 86 of file HipChatHandlerTest.php.

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

◆ testWriteContentNotify()

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

testWriteCustomHostHeader

Definition at line 94 of file HipChatHandlerTest.php.

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

◆ testWriteContentV2()

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

testWriteV2

Definition at line 102 of file HipChatHandlerTest.php.

103  {
104  $this->assertRegexp('/notify=false&message=test1&message_format=text&color=red$/', $content);
105  }

◆ testWriteContentV2Notify()

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

testWriteV2Notify

Definition at line 110 of file HipChatHandlerTest.php.

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

◆ testWriteCustomHostHeader()

Monolog\Handler\HipChatHandlerTest::testWriteCustomHostHeader ( )

Definition at line 38 of file HipChatHandlerTest.php.

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

39  {
40  $this->createHandler('myToken', 'room1', 'Monolog', true, 'hipchat.foo.bar');
41  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
42  fseek($this->res, 0);
43  $content = fread($this->res, 1024);
44 
45  $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);
46 
47  return $content;
48  }
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 26 of file HipChatHandlerTest.php.

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

27  {
28  $this->createHandler();
29  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
30  fseek($this->res, 0);
31  $content = fread($this->res, 1024);
32 
33  $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);
34 
35  return $content;
36  }
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 50 of file HipChatHandlerTest.php.

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

50  {
51  $this->createHandler('myToken', 'room1', 'Monolog', false, 'hipchat.foo.bar', 'v2');
52  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
53  fseek($this->res, 0);
54  $content = fread($this->res, 1024);
55 
56  $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);
57 
58  return $content;
59  }
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 61 of file HipChatHandlerTest.php.

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

61  {
62  $this->createHandler('myToken', 'room1', 'Monolog', true, 'hipchat.foo.bar', 'v2');
63  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
64  fseek($this->res, 0);
65  $content = fread($this->res, 1024);
66 
67  $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);
68 
69  return $content;
70  }
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 115 of file HipChatHandlerTest.php.

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

116  {
117  $this->createHandler();
118  $this->handler->handle($this->getRecord(Logger::CRITICAL, 'Backup of database "example" finished in 16 minutes.'));
119  fseek($this->res, 0);
120  $content = fread($this->res, 1024);
121 
122  $this->assertRegexp('/message=Backup\+of\+database\+%22example%22\+finished\+in\+16\+minutes\./', $content);
123  }
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 128 of file HipChatHandlerTest.php.

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

129  {
130  $this->createHandler();
131  $this->handler->handle($this->getRecord($level, 'Backup of database "example" finished in 16 minutes.'));
132  fseek($this->res, 0);
133  $content = fread($this->res, 1024);
134 
135  $this->assertRegexp('/color='.$expectedColor.'/', $content);
136  }
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 24 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: