mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-06 13:16:39 +02:00
Add Hipchat V2 support
Adds support for Hipchat's V2 API by way of setting the version flag. V1 paths should remain unchanged. A setVersion() method is provided for convenience in case one does not want to override all of the default parameters.
This commit is contained in:
@@ -35,6 +35,18 @@ class HipChatHandlerTest extends TestCase
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function testCanSetVersionAfterCreate() {
|
||||
$this->createHandler();
|
||||
$this->handler->setVersion('v2');
|
||||
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
|
||||
fseek($this->res, 0);
|
||||
$content = fread($this->res, 1024);
|
||||
|
||||
$this->assertRegexp('/POST \/v2\/room\/room1\/notification\?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);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function testWriteCustomHostHeader()
|
||||
{
|
||||
$this->createHandler('myToken', 'room1', 'Monolog', false, 'hipchat.foo.bar');
|
||||
@@ -47,12 +59,50 @@ class HipChatHandlerTest extends TestCase
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function testWriteV2() {
|
||||
$this->createHandler('myToken', 'room1', 'Monolog', false, 'hipchat.foo.bar', 'v2');
|
||||
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
|
||||
fseek($this->res, 0);
|
||||
$content = fread($this->res, 1024);
|
||||
|
||||
$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);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
public function testRoomSpaces() {
|
||||
$this->createHandler('myToken', 'room name', 'Monolog', false, 'hipchat.foo.bar', 'v2');
|
||||
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
|
||||
fseek($this->res, 0);
|
||||
$content = fread($this->res, 1024);
|
||||
|
||||
$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);
|
||||
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testWriteHeader
|
||||
*/
|
||||
public function testWriteContent($content)
|
||||
{
|
||||
$this->assertRegexp('/from=Monolog&room_id=room1¬ify=0&message=test1&message_format=text&color=red$/', $content);
|
||||
$this->assertRegexp('/notify=0&message=test1&message_format=text&color=red&room_id=room1&from=Monolog$/', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testWriteV2
|
||||
*/
|
||||
public function testWriteContentV2($content)
|
||||
{
|
||||
$this->assertRegexp('/notify=0&message=test1&message_format=text&color=red$/', $content);
|
||||
}
|
||||
|
||||
/**
|
||||
* @depends testCanSetVersionAfterCreate
|
||||
*/
|
||||
public function testWriteContentV2AfterCreate($content)
|
||||
{
|
||||
$this->assertRegexp('/notify=0&message=test1&message_format=text&color=red$/', $content);
|
||||
}
|
||||
|
||||
public function testWriteWithComplexMessage()
|
||||
@@ -141,9 +191,9 @@ class HipChatHandlerTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
private function createHandler($token = 'myToken', $room = 'room1', $name = 'Monolog', $notify = false, $host = 'api.hipchat.com')
|
||||
private function createHandler($token = 'myToken', $room = 'room1', $name = 'Monolog', $notify = false, $host = 'api.hipchat.com', $version = 'v1')
|
||||
{
|
||||
$constructorArgs = array($token, $room, $name, $notify, Logger::DEBUG, true, true, 'text', $host);
|
||||
$constructorArgs = array($token, $room, $name, $notify, Logger::DEBUG, true, true, 'text', $host, $version);
|
||||
$this->res = fopen('php://memory', 'a');
|
||||
$this->handler = $this->getMock(
|
||||
'\Monolog\Handler\HipChatHandler',
|
||||
@@ -175,4 +225,9 @@ class HipChatHandlerTest extends TestCase
|
||||
{
|
||||
$hipChatHandler = new \Monolog\Handler\HipChatHandler('token', 'room', 'SixteenCharsHere');
|
||||
}
|
||||
|
||||
public function testCreateWithTooLongNameV2() {
|
||||
// creating a handler with too long of a name but using the v2 api doesn't matter.
|
||||
$hipChatHandler = new \Monolog\Handler\HipChatHandler('token', 'room', 'SixteenCharsHere', false, Logger::CRITICAL, true, true, 'test', 'api.hipchat.com', 'v2');
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user