Skip to content

Commit

Permalink
Merge branch 'hotfix/3594'
Browse files Browse the repository at this point in the history
  • Loading branch information
weierophinney committed Jan 29, 2013
2 parents d5dc7f8 + 0769bf4 commit 7045795
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
24 changes: 24 additions & 0 deletions library/Zend/Log/Filter/SuppressFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

namespace Zend\Log\Filter;

use Zend\Log\Exception;

/**
* @category Zend
Expand All @@ -23,6 +24,29 @@ class SuppressFilter implements FilterInterface
*/
protected $accept = true;

/**
* This is a simple boolean filter.
*
* @param int|array|Traversable $suppress
* @throws Exception\InvalidArgumentException
*/
public function __construct($suppress = false)
{
if ($suppress instanceof Traversable) {
$suppress = iterator_to_array($suppress);
}
if (is_array($suppress)) {
$suppress = isset($suppress['suppress']) ? $suppress['suppress'] : false;
}
if (!is_bool($suppress)) {
throw new Exception\InvalidArgumentException(sprintf(
'Suppress must be an boolean; received "%s"', gettype($suppress)
));
}

$this->suppress($suppress);
}

/**
* This is a simple boolean filter.
*
Expand Down
20 changes: 20 additions & 0 deletions tests/ZendTest/Log/Filter/SuppressFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,26 @@ public function testSuppressIsInitiallyOff()
$this->assertTrue($this->filter->filter(array()));
}

public function testSuppressByConstructorBoolean()
{
$this->filter = new SuppressFilter(true);
$this->assertFalse($this->filter->filter(array()));
$this->assertFalse($this->filter->filter(array()));
}

public function testSuppressByConstructorArray()
{
$this->filter = new SuppressFilter(array('suppress' => true));
$this->assertFalse($this->filter->filter(array()));
$this->assertFalse($this->filter->filter(array()));
}

public function testConstructorThrowsOnInvalidSuppressValue()
{
$this->setExpectedException('Zend\Log\Exception\InvalidArgumentException', 'Suppress must be an boolean');
new SuppressFilter('foo');
}

public function testSuppressOn()
{
$this->filter->suppress(true);
Expand Down

0 comments on commit 7045795

Please sign in to comment.