32 $content = fread($this->res, 1024);
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);
41 $this->
createHandler(
'myToken',
'room1',
'Monolog',
true,
'hipchat.foo.bar');
44 $content = fread($this->res, 1024);
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);
53 $this->
createHandler(
'myToken',
'room1',
'Monolog',
false,
'hipchat.foo.bar',
'v2');
56 $content = fread($this->res, 1024);
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);
65 $this->
createHandler(
'myToken',
'room1',
'Monolog',
true,
'hipchat.foo.bar',
'v2');
68 $content = fread($this->res, 1024);
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);
77 $this->
createHandler(
'myToken',
'room name',
'Monolog',
false,
'hipchat.foo.bar',
'v2');
80 $content = fread($this->res, 1024);
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);
92 $this->assertRegexp(
'/notify=0&message=test1&message_format=text&color=red&room_id=room1&from=Monolog$/', $content);
97 $this->
createHandler(
'myToken',
'room1', null,
false,
'hipchat.foo.bar',
'v1');
100 $content = fread($this->res, 1024);
102 $this->assertRegexp(
'/notify=0&message=test1&message_format=text&color=red&room_id=room1&from=$/', $content);
112 $this->assertRegexp(
'/notify=1&message=test1&message_format=text&color=red&room_id=room1&from=Monolog$/', $content);
120 $this->assertRegexp(
'/notify=false&message=test1&message_format=text&color=red&from=Monolog$/', $content);
128 $this->assertRegexp(
'/notify=true&message=test1&message_format=text&color=red&from=Monolog$/', $content);
133 $this->
createHandler(
'myToken',
'room1', null,
false,
'hipchat.foo.bar',
'v2');
135 fseek($this->res, 0);
136 $content = fread($this->res, 1024);
138 $this->assertRegexp(
'/notify=false&message=test1&message_format=text&color=red$/', $content);
147 fseek($this->res, 0);
148 $content = fread($this->res, 1024);
150 $this->assertRegexp(
'/message=Backup\+of\+database\+%22example%22\+finished\+in\+16\+minutes\./', $content);
157 fseek($this->res, 0);
158 $content = fread($this->res, 12000);
160 $this->assertRegexp(
'/message='.str_repeat(
'abcde', 1900).
'\+%5Btruncated%5D/', $content);
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);
173 $this->assertRegexp(
'/color='.$expectedColor.
'/', $content);
197 $this->handler->handleBatch(
$records);
199 fseek($this->res, 0);
200 $content = fread($this->res, 1024);
202 $this->assertRegexp(
'/color='.$expectedColor.
'/', $content);
211 array(
'level' =>
Logger::NOTICE,
'message' =>
'Something noticeable happened.',
'level_name' =>
'notice',
'datetime' =>
new \
DateTime()),
219 array(
'level' =>
Logger::NOTICE,
'message' =>
'Something noticeable happened.',
'level_name' =>
'notice',
'datetime' =>
new \
DateTime()),
226 array(
'level' =>
Logger::NOTICE,
'message' =>
'Something noticeable happened.',
'level_name' =>
'notice',
'datetime' =>
new \
DateTime()),
239 private function createHandler($token =
'myToken', $room =
'room1',
$name =
'Monolog', $notify =
false, $host =
'api.hipchat.com',
$version =
'v1')
242 $this->res = fopen(
'php://memory',
'a');
243 $this->handler = $this->getMock(
244 '\Monolog\Handler\HipChatHandler',
245 array(
'fsockopen',
'streamSetTimeout',
'closeSocket'),
249 $reflectionProperty = new \ReflectionProperty(
'\Monolog\Handler\SocketHandler',
'connectionString');
250 $reflectionProperty->setAccessible(
true);
251 $reflectionProperty->setValue($this->handler,
'localhost:1234');
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));
271 $hipChatHandler =
new HipChatHandler(
'token',
'room',
'SixteenCharsHere');
const NOTICE
Uncommon events.
const DEBUG
Detailed debug information.
const ERROR
Runtime errors.
testWriteTruncatesLongMessage()
testWriteContentV2($content)
testWriteV2
createHandler($token='myToken', $room='room1', $name='Monolog', $notify=false, $host='api.hipchat.com', $version='v1')
testWriteContent($content)
testWriteHeader
testWriteContentV2WithoutName()
Sends notifications through the hipchat api to a hipchat room.
getRecord($level=Logger::WARNING, $message='test', $context=array())
testWriteCustomHostHeader()
testWriteContentV2Notify($content)
testWriteV2Notify
testWriteContentV1WithoutName()
testWriteWithErrorLevelsAndColors($level, $expectedColor)
provideLevelColors
const WARNING
Exceptional occurrences that are not errors.
testHandleBatch($records, $expectedColor)
provideBatchRecords
const EMERGENCY
Urgent alert.
Create styles array
The data for the language used.
testCreateWithTooLongNameV2()
const CRITICAL
Critical conditions.
testWriteContentNotify($content)
testWriteCustomHostHeader
const ALERT
Action must be taken immediately.
testWriteWithComplexMessage()
testCreateWithTooLongName()
InvalidArgumentException
const INFO
Interesting events.