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

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2
Browse files Browse the repository at this point in the history
  • Loading branch information
wdalmut committed Jun 14, 2012
4 parents dcc1eaf + 6f4b805 + 51601cb + a30a64f commit b487f00
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 39 deletions.
8 changes: 1 addition & 7 deletions src/Filter/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,9 @@ class Validator implements FilterInterface
* Filter out any log messages not matching the validator
*
* @param ZendValidator $validator
* @throws Exception\InvalidArgumentException
*/
public function __construct($validator)
public function __construct(ZendValidator $validator)
{
if (!$validator instanceof ZendValidator) {
throw new Exception\InvalidArgumentException(sprintf(
'Expected Zend\Validator object'
));
}
$this->validator = $validator;
}

Expand Down
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
5 changes: 1 addition & 4 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,8 @@ public function getWriters()
* @throws Exception\InvalidArgumentException
* @return Logger
*/
public function setWriters($writers)
public function setWriters(SplPriorityQueue $writers)
{
if (!$writers instanceof SplPriorityQueue) {
throw new Exception\InvalidArgumentException('Writers must be a SplPriorityQueue of Zend\Log\Writer');
}
foreach ($writers->toArray() as $writer) {
if (!$writer instanceof Writer\WriterInterface) {
throw new Exception\InvalidArgumentException('Writers must be a SplPriorityQueue of Zend\Log\Writer');
Expand Down
4 changes: 1 addition & 3 deletions src/Writer/AbstractWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ public function addFilter($filter)
{
if (is_int($filter)) {
$filter = new Filter\Priority($filter);
}

if (!$filter instanceof Filter\FilterInterface) {
} elseif (!$filter instanceof Filter\FilterInterface) {
throw new Exception\InvalidArgumentException(sprintf(
'Filter must implement Zend\Log\Filter; received %s',
is_object($filter) ? get_class($filter) : gettype($filter)
Expand Down
6 changes: 0 additions & 6 deletions test/Filter/ValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@
*/
class ValidatorTest extends \PHPUnit_Framework_TestCase
{
public function testRecognizesInvalidValidator()
{
$this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'Expected Zend\Validator object');
new Validator('invalid');
}

public function testValidatorFilter()
{
$filter = new Validator(new Alnum());
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 b487f00

Please sign in to comment.