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

Commit

Permalink
Merge remote-tracking branch 'Maks3w/hotfix/ZF2-355'
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanDotPro committed Jun 12, 2012
4 parents 2435138 + dcc1eaf + 6f4b805 + 3fad1a9 commit 51601cb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 19 deletions.
13 changes: 7 additions & 6 deletions src/Formatter/ExceptionHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,14 @@ public function format($event)
$event['priority'] . ') ' . $event['message'] .' in ' .
$event['extra']['file'] . ' on line ' . $event['extra']['line'];
if (!empty($event['extra']['trace'])) {
$outputTrace = '';
foreach ($event['extra']['trace'] as $trace) {
$outputTrace = "File : {$trace['file']}\n" .
"Line : {$trace['line']}\n" .
"Func : {$trace['function']}\n" .
"Class : {$trace['class']}\n" .
"Type : " . $this->getType($trace['type']) . "\n" .
"Args : " . print_r($trace['args'], true) . "\n";
$outputTrace .= "File : {$trace['file']}\n" .
"Line : {$trace['line']}\n" .
"Func : {$trace['function']}\n" .
"Class : {$trace['class']}\n" .
"Type : " . $this->getType($trace['type']) . "\n" .
"Args : " . print_r($trace['args'], true) . "\n";
}
$output.= "\n[Trace]\n" . $outputTrace;
}
Expand Down
59 changes: 46 additions & 13 deletions test/Formatter/ExceptionHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,63 @@ class ExceptionHandlerTest extends \PHPUnit_Framework_TestCase
{
public function testFormat()
{
$date = date('c');
$event = array(
'timestamp' => $date,
'timestamp' => '2012-06-12T09:00:00+02:00',
'message' => 'test',
'priority' => 1,
'priorityName' => 'CRIT',
'extra' => array (
'file' => 'test.php',
'line' => 1,
'trace' => array(array(
'file' => 'test.php',
'line' => 1,
'function' => 'test',
'class' => 'Test',
'type' => '::',
'args' => array(1)
))
'trace' => array(
array(
'file' => 'test.php',
'line' => 1,
'function' => 'test',
'class' => 'Test',
'type' => '::',
'args' => array(1)
),
array(
'file' => 'test.php',
'line' => 2,
'function' => 'test',
'class' => 'Test',
'type' => '::',
'args' => array(1)
)
)
)
);
$expected = <<<EOF
2012-06-12T09:00:00+02:00 CRIT (1) test in test.php on line 1
[Trace]
File : test.php
Line : 1
Func : test
Class : Test
Type : static
Args : Array
(
[0] => 1
)
File : test.php
Line : 2
Func : test
Class : Test
Type : static
Args : Array
(
[0] => 1
)
EOF;

$formatter = new ExceptionHandler();
$output = $formatter->format($event);

$this->assertEquals($date . " CRIT (1) test in test.php on line 1\n" .
"[Trace]\nFile : test.php\nLine : 1\nFunc : test\nClass : Test\n" .
"Type : static\nArgs : Array\n(\n [0] => 1\n)\n\n", $output);
$this->assertEquals($expected, $output);
}
}

0 comments on commit 51601cb

Please sign in to comment.