Skip to content

Commit

Permalink
Add addMessages method to LogGroup and use in HttpDataCollector (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
siraic authored and Florian Preusner committed Sep 30, 2016
1 parent ae14e6e commit c0b7404
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DataCollector/HttpDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function collect(Request $request, Response $response, \Exception $except

$logGroup = $this->getLogGroup($requestId);
$logGroup->setRequestName($request->getPathInfo());
$logGroup->setMessages($messages);
$logGroup->addMessages($messages);
} // end: collect()

/**
Expand Down
13 changes: 13 additions & 0 deletions Log/LogGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ public function setMessages(array $value) {
$this->messages = $value;
} // end: setMessages()

/**
* Add Log Messages
*
* @author Bart Swaalf
* @since 2016-09
*
* @param array $value
*/
public function addMessages(array $value) {

$this->messages = array_merge($this->messages, $value);
} // end: addMessages()

/**
* Return Log Messages
*
Expand Down
9 changes: 9 additions & 0 deletions Tests/Log/LogGroupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function testRequestName() {
*
* @covers EightPoints\Bundle\GuzzleBundle\Log\LogGroup::setMessages
* @covers EightPoints\Bundle\GuzzleBundle\Log\LogGroup::getMessages
* @covers EightPoints\Bundle\GuzzleBundle\Log\LogGroup::addMessages
*/
public function testMessages() {

Expand All @@ -61,12 +62,20 @@ public function testMessages() {
->disableOriginalConstructor()
->getMock();

$message3 = $this->getMockBuilder('EightPoints\Bundle\GuzzleBundle\Log\LogMessage')
->disableOriginalConstructor()
->getMock();

$messages = [$message1, $message2];

$group->setMessages($messages);

$this->assertCount(2, $group->getMessages());

$group->addMessages([$message3]);

$this->assertCount(3, $group->getMessages());

foreach($group->getMessages() as $message) {

$this->assertInstanceOf('EightPoints\Bundle\GuzzleBundle\Log\LogMessage', $message);
Expand Down

0 comments on commit c0b7404

Please sign in to comment.