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);
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()),
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()),
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()),
232 array(
'level' =>
Logger::DEBUG,
'message' =>
'Just debugging.',
'level_name' =>
'debug',
'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');
An exception for terminatinating execution or to throw for unit testing.
testWriteWithErrorLevelsAndColors($level, $expectedColor)
@dataProvider provideLevelColors
testWriteWithComplexMessage()
testWriteContentV2WithoutName()
testCreateWithTooLongName()
@expectedException InvalidArgumentException
testWriteContentV2Notify($content)
@depends testWriteV2Notify
createHandler($token='myToken', $room='room1', $name='Monolog', $notify=false, $host='api.hipchat.com', $version='v1')
testWriteTruncatesLongMessage()
testHandleBatch($records, $expectedColor)
@dataProvider provideBatchRecords
testWriteContentNotify($content)
@depends testWriteCustomHostHeader
testWriteContentV1WithoutName()
testWriteContentV2($content)
@depends testWriteV2
testWriteContent($content)
@depends testWriteHeader
testWriteCustomHostHeader()
testCreateWithTooLongNameV2()
Sends notifications through the hipchat api to a hipchat room.
const EMERGENCY
Urgent alert.
const ERROR
Runtime errors.
const CRITICAL
Critical conditions.
const WARNING
Exceptional occurrences that are not errors.
const INFO
Interesting events.
const DEBUG
Detailed debug information.
const NOTICE
Uncommon events.
const ALERT
Action must be taken immediately.
getRecord($level=Logger::WARNING, $message='test', $context=array())