31 $content = fread($this->res, 1024);
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);
40 $this->
createHandler(
'myToken',
'room1',
'Monolog',
true,
'hipchat.foo.bar');
43 $content = fread($this->res, 1024);
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);
51 $this->
createHandler(
'myToken',
'room1',
'Monolog',
false,
'hipchat.foo.bar',
'v2');
54 $content = fread($this->res, 1024);
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);
62 $this->
createHandler(
'myToken',
'room1',
'Monolog',
true,
'hipchat.foo.bar',
'v2');
65 $content = fread($this->res, 1024);
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);
73 $this->
createHandler(
'myToken',
'room name',
'Monolog',
false,
'hipchat.foo.bar',
'v2');
76 $content = fread($this->res, 1024);
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);
88 $this->assertRegexp(
'/notify=0&message=test1&message_format=text&color=red&room_id=room1&from=Monolog$/', $content);
96 $this->assertRegexp(
'/notify=1&message=test1&message_format=text&color=red&room_id=room1&from=Monolog$/', $content);
104 $this->assertRegexp(
'/notify=false&message=test1&message_format=text&color=red$/', $content);
112 $this->assertRegexp(
'/notify=true&message=test1&message_format=text&color=red$/', $content);
119 fseek($this->res, 0);
120 $content = fread($this->res, 1024);
122 $this->assertRegexp(
'/message=Backup\+of\+database\+%22example%22\+finished\+in\+16\+minutes\./', $content);
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);
135 $this->assertRegexp(
'/color='.$expectedColor.
'/', $content);
159 $this->handler->handleBatch(
$records);
161 fseek($this->res, 0);
162 $content = fread($this->res, 1024);
164 $this->assertRegexp(
'/color='.$expectedColor.
'/', $content);
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())
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()),
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()),
194 array(
'level' =>
Logger::DEBUG,
'message' =>
'Just debugging.',
'level_name' =>
'debug',
'datetime' =>
new \DateTime()),
201 private function createHandler($token =
'myToken', $room =
'room1', $name =
'Monolog', $notify =
false, $host =
'api.hipchat.com', $version =
'v1')
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'),
211 $reflectionProperty = new \ReflectionProperty(
'\Monolog\Handler\SocketHandler',
'connectionString');
212 $reflectionProperty->setAccessible(
true);
213 $reflectionProperty->setValue($this->handler,
'localhost:1234');
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));
233 $hipChatHandler = new \Monolog\Handler\HipChatHandler(
'token',
'room',
'SixteenCharsHere');
238 $hipChatHandler = new \Monolog\Handler\HipChatHandler(
'token',
'room',
'SixteenCharsHere',
false,
Logger::CRITICAL,
true,
true,
'test',
'api.hipchat.com',
'v2');
const NOTICE
Uncommon events.
const DEBUG
Detailed debug information.
const ERROR
Runtime errors.
testWriteContentV2($content)
testWriteV2
createHandler($token='myToken', $room='room1', $name='Monolog', $notify=false, $host='api.hipchat.com', $version='v1')
testWriteContent($content)
testWriteHeader
getRecord($level=Logger::WARNING, $message='test', $context=array())
testWriteCustomHostHeader()
testWriteContentV2Notify($content)
testWriteV2Notify
testWriteWithErrorLevelsAndColors($level, $expectedColor)
provideLevelColors
const WARNING
Exceptional occurrences that are not errors.
testHandleBatch($records, $expectedColor)
provideBatchRecords
const EMERGENCY
Urgent alert.
testCreateWithTooLongNameV2()
const CRITICAL
Critical conditions.
testWriteContentNotify($content)
testWriteCustomHostHeader
const ALERT
Action must be taken immediately.
testWriteWithComplexMessage()
testCreateWithTooLongName()
InvalidArgumentException
const INFO
Interesting events.