Skip to content

Commit

Permalink
Fix setting of message_format
Browse files Browse the repository at this point in the history
- Replaced array_merge_recursive with array_replace_recursive so the message_format gets overwritten and not appended to
  • Loading branch information
rjvandoesburg committed Feb 20, 2018
1 parent 312c0e0 commit 4cca754
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/HipChatDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function isBot()
*/
public function buildServicePayload($message, $matchingMessage, $additionalParameters = [])
{
$parameters = array_merge_recursive([
$parameters = array_replace_recursive([
'message_format' => 'text',
], $additionalParameters);
/*
Expand Down
31 changes: 31 additions & 0 deletions tests/HipChatDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,35 @@ public function it_is_configured()

$this->assertFalse($driver->isConfigured());
}

/** @test */
public function it_builds_the_correct_payload()
{
// Given a user wants to send html
$driver = $this->getDriver([
'event' => 'room_message',
'item' => [
'message' => [
'from' => [
'id' => '12345',
],
'message' => 'Hi Julia',
],
'room' => [
'id' => '98765',
],
],
'webhook_id' => '11223344',
]);
$message = $driver->getMessages()[0];
$payload = $driver->buildServicePayload('Test message', $message);
$this->assertEquals('text', $payload['message_format']);

// Now if the user wants to set the format to HTML
$payload = $driver->buildServicePayload('Test message', $message, [
'message_format' => 'html'
]);

$this->assertEquals('html', $payload['message_format']);
}
}

0 comments on commit 4cca754

Please sign in to comment.