1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-05 04:37:38 +02:00

Merge pull request #686 from apfelbox/hipchat-from

[HipChatHandler] Always send the "from" name
This commit is contained in:
Jordi Boggiano
2015-11-18 17:12:52 +00:00
2 changed files with 33 additions and 3 deletions

View File

@@ -146,7 +146,12 @@ class HipChatHandler extends SocketHandler
// if we are using the legacy API then we need to send some additional information
if ($this->version == self::API_V1) {
$dataArray['room_id'] = $this->room;
$dataArray['from'] = $this->name;
}
// append the sender name if it is set
// always append it if we use the v1 api (it is required in v1)
if ($this->version == self::API_V1 || $this->name !== null) {
$dataArray['from'] = (string) $this->name;
}
return http_build_query($dataArray);

View File

@@ -21,6 +21,7 @@ use Monolog\Logger;
class HipChatHandlerTest extends TestCase
{
private $res;
/** @var HipChatHandler */
private $handler;
public function testWriteHeader()
@@ -91,6 +92,18 @@ class HipChatHandlerTest extends TestCase
$this->assertRegexp('/notify=0&message=test1&message_format=text&color=red&room_id=room1&from=Monolog$/', $content);
}
public function testWriteContentV1WithoutName()
{
$this->createHandler('myToken', 'room1', null, false, 'hipchat.foo.bar', 'v1');
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
fseek($this->res, 0);
$content = fread($this->res, 1024);
$this->assertRegexp('/notify=0&message=test1&message_format=text&color=red&room_id=room1&from=$/', $content);
return $content;
}
/**
* @depends testWriteCustomHostHeader
*/
@@ -104,7 +117,7 @@ class HipChatHandlerTest extends TestCase
*/
public function testWriteContentV2($content)
{
$this->assertRegexp('/notify=false&message=test1&message_format=text&color=red$/', $content);
$this->assertRegexp('/notify=false&message=test1&message_format=text&color=red&from=Monolog$/', $content);
}
/**
@@ -112,7 +125,19 @@ class HipChatHandlerTest extends TestCase
*/
public function testWriteContentV2Notify($content)
{
$this->assertRegexp('/notify=true&message=test1&message_format=text&color=red$/', $content);
$this->assertRegexp('/notify=true&message=test1&message_format=text&color=red&from=Monolog$/', $content);
}
public function testWriteContentV2WithoutName()
{
$this->createHandler('myToken', 'room1', null, false, 'hipchat.foo.bar', 'v2');
$this->handler->handle($this->getRecord(Logger::CRITICAL, 'test1'));
fseek($this->res, 0);
$content = fread($this->res, 1024);
$this->assertRegexp('/notify=false&message=test1&message_format=text&color=red$/', $content);
return $content;
}
public function testWriteWithComplexMessage()