Permalink
Browse files

Merge branch 'hotfix/3594' into develop

Forward port #3594
  • Loading branch information...
2 parents bda3831 + 0769bf4 commit 8561cc4930e09a00811855c85a2d204e919d2200 @weierophinney weierophinney committed Jan 29, 2013
Showing with 44 additions and 0 deletions.
  1. +24 −0 library/Zend/Log/Filter/SuppressFilter.php
  2. +20 −0 tests/ZendTest/Log/Filter/SuppressFilterTest.php
@@ -9,6 +9,7 @@
namespace Zend\Log\Filter;
+use Zend\Log\Exception;
class SuppressFilter implements FilterInterface
{
@@ -20,6 +21,29 @@ class SuppressFilter implements FilterInterface
/**
* 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.
+ *
* Call suppress(true) to suppress all log events.
* Call suppress(false) to accept all log events.
*
@@ -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);

0 comments on commit 8561cc4

Please sign in to comment.