Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Commit

Permalink
Merge pull request zendframework/zendframework#5594 in master
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Formatter/Base.php
Expand Up @@ -54,7 +54,7 @@ public function format($event)
{
foreach ($event as $key => $value) {
// Keep extra as an array
if ('extra' === $key) {
if ('extra' === $key && is_array($value)) {
$event[$key] = self::format($value);
} else {
$event[$key] = $this->normalize($value);
Expand Down
16 changes: 16 additions & 0 deletions test/Formatter/BaseTest.php
Expand Up @@ -157,4 +157,20 @@ public function testFormatNoInfiniteLoopOnSelfReferencingArrayValues()

$this->assertEquals($outputExpected, $formatter->format($event));
}

public function testFormatExtraArrayKeyWithNonArrayValue()
{
$formatter = new BaseFormatter();

$event = array(
'message' => 'Hi',
'extra' => '',
);
$outputExpected = array(
'message' => 'Hi',
'extra' => '',
);

$this->assertEquals($outputExpected, $formatter->format($event));
}
}
19 changes: 19 additions & 0 deletions test/LoggerTest.php
Expand Up @@ -366,4 +366,23 @@ public function testExceptionHandler()
$this->assertEquals($expectedEvent['file'], $event['extra']['file'], 'Unexpected file');
}
}

public function testLogExtraArrayKeyWithNonArrayValue()
{
$stream = fopen("php://memory", "r+");
$options = array(
'writers' => array(
array(
'name' => 'stream',
'options' => array(
'stream' => $stream
),
),
),
);
$logger = new Logger($options);

$this->assertInstanceOf('Zend\Log\Logger', $logger->info('Hi', array('extra' => '')));
fclose($stream);
}
}

0 comments on commit 975bb98

Please sign in to comment.