Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Remove exceptions from #4734 #4761

Merged
merged 4 commits into from

3 participants

@weierophinney

#4734 introduced some type checking into a number of filters in order to remove notices that were being raised about "array to string" conversions. However, it did so by raising exceptions, which will be a non-starter for anybody who was previously passing arrays and/or objects to these filters.

Likely the more appropriate method would be to simply return the value presented, and potentially raise an E_USER_WARNING indicating the filter's inability to process the value.

@weierophinney weierophinney was assigned
weierophinney added some commits
@weierophinney weierophinney [#4761] Convert exceptions to warnings
- To retain BC, filters should never raise exceptions
- Instead, raising warning and returning original value
60ff684
@weierophinney weierophinney [#4761] Added tests for null values
- null values should be filtered without warnings
5d40260
@weierophinney weierophinney [#4761] null values should not raise warnings
- null values should not be filtered, and should not raise warnings
8750864
@gag237

If we accept an agreement that any Filter instance of Zend\Filter\FilterInterface should generate an error if it can not filter out, it is best to leave the exception.

I want to draw attention to such cases:

Lets we have $input (instance of InputFilrer\Input) based on config below

$inputSpec = array(
    'title' => array(
           'required' => false,
            'validators' => array(
                array(
                    'name' => 'stringLength',
                    'options' => array(
                        'max' => 2000
                    )
                )
            ),
            'filters' => array(
                array(
                    'name' => 'stripTags',
                ),
                array(
                    'name' => 'null',
                ),
            ),
     )
);

and we have any $data (of course not valid).

$data = array(
  'title' => array()
);

then i call $input->isValid() will be triggered notice.

If this data is from form it's logical trigger notice to developer to show that form does not correspond to inputFilter. But this data may be from any part, for example from GET.
And i think it is not good idea trigger notice, better leave Exception, because possible to make small changes in InputFilter\Input something like that:

public function getValue()
{
    $filter = $this->getFilterChain();
    try {
        return $filter->filter($this->value);
    } catch (\Zend\Filter\Exception\InputFilterException $e) {
       return $this->getRawValue();
    }
}
@weierophinney

@gag237 It's a bad idea to use try/catch for logical branching -- if nothing else, because it adds a ton of processing overhead. Additionally, you're confusing filtering and validation. In the InputFilter, filters happen prior to validation -- so even if the values cannot be filtered, they will likely still fail validation.

Throwing the notice is still useful in these situations, however, as you can then see in the logs that some location on your site is submitting data incorrectly -- or somebody is attempting to trigger failures to try and find vulnerabilities.

@gag237

Perhaps you are right.

Is it possible to change the description of Filter\FilterInterfatse::filter() when the filter should throw an exception RuntimeException, when trigger error.

@weierophinney

@gag237 Go for it.

@Maks3w
Collaborator

That methods have a contract for return string but with this approach are returning null or mixed

If this try to resolve a BC Break I suggest revert the original PR (#4734) and apply it for the next "major" version

@weierophinney

@Maks3w It's not a BC break; it's correcting already released behavior to be more consistent and less brittle.

@Maks3w
Collaborator

Can you update the docblocks for reflect the changes? (return types and some note about the E_USER_WARNING)

@weierophinney weierophinney Add info in docblock about warnings
- Added a paragraph indicating inability to filter non-scalar values,
  and that a warning will be raised in such circumstances.
- Updated return annotations to indicate a "mixed" possibility.
f5c6ba2
@weierophinney

@Maks3w Done.

@Maks3w Maks3w was assigned
@Maks3w Maks3w merged commit f5c6ba2 into zendframework:master

1 check failed

Details default The Travis CI build failed
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-filter
@weierophinney weierophinney [zendframework/zf2#4761] Convert exceptions to warnings
- To retain BC, filters should never raise exceptions
- Instead, raising warning and returning original value
d0d0794
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-filter
@weierophinney weierophinney [zendframework/zf2#4761] Added tests for null values
- null values should be filtered without warnings
06b07aa
@weierophinney weierophinney referenced this pull request from a commit in zendframework/zend-filter
@weierophinney weierophinney [zendframework/zf2#4761] null values should not raise warnings
- null values should not be filtered, and should not raise warnings
a0143d3
@gianarb gianarb referenced this pull request from a commit in zendframework/zend-filter
@Maks3w Maks3w Merge pull request zendframework/zf2#4761 a124306
@gianarb gianarb referenced this pull request from a commit in zendframework/zend-filter
@Maks3w Maks3w Merge pull request zendframework/zf2#4761 in develop fe09441
@gianarb gianarb referenced this pull request from a commit in zendframework/zend-filter
@Maks3w Maks3w Merge pull request zendframework/zf2#4761 in master bf4b889
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jul 1, 2013
  1. @weierophinney

    [#4761] Convert exceptions to warnings

    weierophinney authored
    - To retain BC, filters should never raise exceptions
    - Instead, raising warning and returning original value
  2. @weierophinney

    [#4761] Added tests for null values

    weierophinney authored
    - null values should be filtered without warnings
  3. @weierophinney

    [#4761] null values should not raise warnings

    weierophinney authored
    - null values should not be filtered, and should not raise warnings
Commits on Jul 19, 2013
  1. @weierophinney

    Add info in docblock about warnings

    weierophinney authored
    - Added a paragraph indicating inability to filter non-scalar values,
      and that a warning will be raised in such circumstances.
    - Updated return annotations to indicate a "mixed" possibility.
This page is out of date. Refresh to see the latest.
View
27 library/Zend/Filter/BaseName.php
@@ -14,19 +14,30 @@ class BaseName extends AbstractFilter
/**
* Defined by Zend\Filter\FilterInterface
*
- * Returns basename($value)
+ * Returns basename($value).
+ *
+ * If the value provided is non-scalar, the value will remain unfiltered
+ * and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @param string $value
- * @return string
+ * @return string|mixed
*/
public function filter($value)
{
- if(!is_scalar($value)){
- throw new Exception\InvalidArgumentException(sprintf(
- '%s expects parameter to be scalar, "%s" given',
- __METHOD__,
- (is_object($value) ? get_class($value) : gettype($value))
- ));
+ if (null === $value) {
+ return null;
+ }
+
+ if (!is_scalar($value)){
+ trigger_error(
+ sprintf(
+ '%s expects parameter to be scalar, "%s" given; cannot filter',
+ __METHOD__,
+ (is_object($value) ? get_class($value) : gettype($value))
+ ),
+ E_USER_WARNING
+ );
+ return $value;
}
return basename((string) $value);
View
25 library/Zend/Filter/Digits.php
@@ -18,17 +18,28 @@ class Digits extends AbstractFilter
*
* Returns the string $value, removing all but digit characters
*
+ * If the value provided is non-scalar, the value will remain unfiltered
+ * and an E_USER_WARNING will be raised indicating it's unfilterable.
+ *
* @param string $value
- * @return string
+ * @return string|mixed
*/
public function filter($value)
{
- if(!is_scalar($value)){
- throw new Exception\InvalidArgumentException(sprintf(
- '%s expects parameter to be scalar, "%s" given',
- __METHOD__,
- (is_object($value) ? get_class($value) : gettype($value))
- ));
+ if (null === $value) {
+ return null;
+ }
+
+ if (!is_scalar($value)){
+ trigger_error(
+ sprintf(
+ '%s expects parameter to be scalar, "%s" given; cannot filter',
+ __METHOD__,
+ (is_object($value) ? get_class($value) : gettype($value))
+ ),
+ E_USER_WARNING
+ );
+ return $value;
}
if (!StringUtils::hasPcreUnicodeSupport()) {
View
27 library/Zend/Filter/HtmlEntities.php
@@ -173,18 +173,29 @@ public function setDoubleQuote($doubleQuote)
* Returns the string $value, converting characters to their corresponding HTML entity
* equivalents where they exist
*
+ * If the value provided is non-scalar, the value will remain unfiltered
+ * and an E_USER_WARNING will be raised indicating it's unfilterable.
+ *
* @param string $value
- * @throws Exception\DomainException
- * @return string
+ * @return string|mixed
+ * @throws Exception\DomainException on encoding mismatches
*/
public function filter($value)
{
- if(!is_scalar($value)){
- throw new Exception\InvalidArgumentException(sprintf(
- '%s expects parameter to be scalar, "%s" given',
- __METHOD__,
- (is_object($value) ? get_class($value) : gettype($value))
- ));
+ if (null === $value) {
+ return null;
+ }
+
+ if (!is_scalar($value)){
+ trigger_error(
+ sprintf(
+ '%s expects parameter to be scalar, "%s" given; cannot filter',
+ __METHOD__,
+ (is_object($value) ? get_class($value) : gettype($value))
+ ),
+ E_USER_WARNING
+ );
+ return $value;
}
$filtered = htmlentities((string) $value, $this->getQuoteStyle(), $this->getEncoding(), $this->getDoubleQuote());
View
25 library/Zend/Filter/Int.php
@@ -16,17 +16,28 @@ class Int extends AbstractFilter
*
* Returns (int) $value
*
+ * If the value provided is non-scalar, the value will remain unfiltered
+ * and an E_USER_WARNING will be raised indicating it's unfilterable.
+ *
* @param string $value
- * @return int
+ * @return int|mixed
*/
public function filter($value)
{
- if(!is_scalar($value)){
- throw new Exception\InvalidArgumentException(sprintf(
- '%s expects parameter to be scalar, "%s" given',
- __METHOD__,
- (is_object($value) ? get_class($value) : gettype($value))
- ));
+ if (null === $value) {
+ return null;
+ }
+
+ if (!is_scalar($value)){
+ trigger_error(
+ sprintf(
+ '%s expects parameter to be scalar, "%s" given; cannot filter',
+ __METHOD__,
+ (is_object($value) ? get_class($value) : gettype($value))
+ ),
+ E_USER_WARNING
+ );
+ return $value;
}
return (int) ((string) $value);
View
25 library/Zend/Filter/RealPath.php
@@ -66,17 +66,28 @@ public function getExists()
*
* Returns realpath($value)
*
+ * If the value provided is non-scalar, the value will remain unfiltered
+ * and an E_USER_WARNING will be raised indicating it's unfilterable.
+ *
* @param string $value
- * @return string
+ * @return string|mixed
*/
public function filter($value)
{
- if(!is_scalar($value)){
- throw new Exception\InvalidArgumentException(sprintf(
- '%s expects parameter to be scalar, "%s" given',
- __METHOD__,
- (is_object($value) ? get_class($value) : gettype($value))
- ));
+ if (null === $value) {
+ return null;
+ }
+
+ if (!is_scalar($value)){
+ trigger_error(
+ sprintf(
+ '%s expects parameter to be scalar, "%s" given; cannot filter',
+ __METHOD__,
+ (is_object($value) ? get_class($value) : gettype($value))
+ ),
+ E_USER_WARNING
+ );
+ return $value;
}
$path = (string) $value;
View
25 library/Zend/Filter/StringToLower.php
@@ -41,17 +41,28 @@ public function __construct($encodingOrOptions = null)
*
* Returns the string $value, converting characters to lowercase as necessary
*
+ * If the value provided is non-scalar, the value will remain unfiltered
+ * and an E_USER_WARNING will be raised indicating it's unfilterable.
+ *
* @param string $value
- * @return string
+ * @return string|mixed
*/
public function filter($value)
{
- if(!is_scalar($value)){
- throw new Exception\InvalidArgumentException(sprintf(
- '%s expects parameter to be scalar, "%s" given',
- __METHOD__,
- (is_object($value) ? get_class($value) : gettype($value))
- ));
+ if (null === $value) {
+ return null;
+ }
+
+ if (!is_scalar($value)){
+ trigger_error(
+ sprintf(
+ '%s expects parameter to be scalar, "%s" given; cannot filter',
+ __METHOD__,
+ (is_object($value) ? get_class($value) : gettype($value))
+ ),
+ E_USER_WARNING
+ );
+ return $value;
}
if ($this->options['encoding'] !== null) {
View
27 library/Zend/Filter/StringToUpper.php
@@ -39,19 +39,30 @@ public function __construct($encodingOrOptions = null)
/**
* Defined by Zend\Filter\FilterInterface
*
- * Returns the string $value, converting characters to lowercase as necessary
+ * Returns the string $value, converting characters to uppercase as necessary
+ *
+ * If the value provided is non-scalar, the value will remain unfiltered
+ * and an E_USER_WARNING will be raised indicating it's unfilterable.
*
* @param string $value
- * @return string
+ * @return string|mixed
*/
public function filter($value)
{
- if(!is_scalar($value)){
- throw new Exception\InvalidArgumentException(sprintf(
- '%s expects parameter to be scalar, "%s" given',
- __METHOD__,
- (is_object($value) ? get_class($value) : gettype($value))
- ));
+ if (null === $value) {
+ return null;
+ }
+
+ if (!is_scalar($value)){
+ trigger_error(
+ sprintf(
+ '%s expects parameter to be scalar, "%s" given; cannot filter',
+ __METHOD__,
+ (is_object($value) ? get_class($value) : gettype($value))
+ ),
+ E_USER_WARNING
+ );
+ return $value;
}
if ($this->options['encoding'] !== null) {
View
26 library/Zend/Filter/StripTags.php
@@ -166,19 +166,29 @@ public function setAttributesAllowed($attributesAllowed)
/**
* Defined by Zend\Filter\FilterInterface
*
- * @todo improve docblock descriptions
+ * If the value provided is non-scalar, the value will remain unfiltered
+ * and an E_USER_WARNING will be raised indicating it's unfilterable.
*
+ * @todo improve docblock descriptions
* @param string $value
- * @return string
+ * @return string|mixed
*/
public function filter($value)
{
- if(!is_scalar($value)){
- throw new Exception\InvalidArgumentException(sprintf(
- '%s expects parameter to be scalar, "%s" given',
- __METHOD__,
- (is_object($value) ? get_class($value) : gettype($value))
- ));
+ if (null === $value) {
+ return null;
+ }
+
+ if (!is_scalar($value)){
+ trigger_error(
+ sprintf(
+ '%s expects parameter to be scalar, "%s" given; cannot filter',
+ __METHOD__,
+ (is_object($value) ? get_class($value) : gettype($value))
+ ),
+ E_USER_WARNING
+ );
+ return $value;
}
$value = (string) $value;
View
27 tests/ZendTest/Filter/BaseNameTest.php
@@ -11,6 +11,7 @@
namespace ZendTest\Filter;
use Zend\Filter\BaseName as BaseNameFilter;
+use Zend\Stdlib\ErrorHandler;
/**
* @category Zend
@@ -38,21 +39,31 @@ public function testBasic()
}
/**
- * Ensures that an InvalidArgumentException is raised if array is used
+ * Ensures that a warning is raised if array is used
*
* @return void
*/
- public function testExceptionRaisedIfArrayUsed()
+ public function testWarningIsRaisedIfArrayUsed()
{
$filter = new BaseNameFilter();
$input = array('/path/to/filename', '/path/to/filename.ext');
- try {
- $filter->filter($input);
- } catch (\Zend\Filter\Exception\InvalidArgumentException $expected) {
- return;
- }
+ ErrorHandler::start(E_USER_WARNING);
+ $filtered = $filter->filter($input);
+ $err = ErrorHandler::stop();
+
+ $this->assertEquals($input, $filtered);
+ $this->assertInstanceOf('ErrorException', $err);
+ $this->assertContains('cannot filter', $err->getMessage());
+ }
- $this->fail('An expected InvalidArgumentException has not been raised.');
+ /**
+ * @return void
+ */
+ public function testReturnsNullIfNullIsUsed()
+ {
+ $filter = new BaseNameFilter();
+ $filtered = $filter->filter(null);
+ $this->assertNull($filtered);
}
}
View
27 tests/ZendTest/Filter/DigitsTest.php
@@ -11,6 +11,7 @@
namespace ZendTest\Filter;
use Zend\Filter\Digits as DigitsFilter;
+use Zend\Stdlib\ErrorHandler;
/**
* @category Zend
@@ -87,21 +88,31 @@ public function testBasic()
}
/**
- * Ensures that an InvalidArgumentException is raised if array is used
+ * Ensures that an error is raised if array is used
*
* @return void
*/
- public function testExceptionRaisedIfArrayUsed()
+ public function testWarningIsRaisedIfArrayUsed()
{
$filter = new DigitsFilter();
$input = array('abc123', 'abc 123');
- try {
- $filter->filter($input);
- } catch (\Zend\Filter\Exception\InvalidArgumentException $expected) {
- return;
- }
+ ErrorHandler::start(E_USER_WARNING);
+ $filtered = $filter->filter($input);
+ $err = ErrorHandler::stop();
+
+ $this->assertEquals($input, $filtered);
+ $this->assertInstanceOf('ErrorException', $err);
+ $this->assertContains('cannot filter', $err->getMessage());
+ }
- $this->fail('An expected InvalidArgumentException has not been raised.');
+ /**
+ * @return void
+ */
+ public function testReturnsNullIfNullIsUsed()
+ {
+ $filter = new DigitsFilter();
+ $filtered = $filter->filter(null);
+ $this->assertNull($filtered);
}
}
View
26 tests/ZendTest/Filter/HtmlEntitiesTest.php
@@ -12,6 +12,7 @@
use Zend\Filter\HtmlEntities as HtmlEntitiesFilter;
use Zend\Filter\Exception;
+use Zend\Stdlib\ErrorHandler;
/**
* @category Zend
@@ -259,21 +260,30 @@ public function testRaisesExceptionIfEncodingMismatchDetectedAndFinalStringIsEmp
}
/**
- * Ensures that an InvalidArgumentException is raised if array is used
+ * Ensures that a warning is raised if array is used
*
* @return void
*/
- public function testExceptionRaisedIfArrayUsed()
+ public function testWarningIsRaisedIfArrayUsed()
{
$input = array('<', '>');
- try {
- $this->_filter->filter($input);
- } catch (\Zend\Filter\Exception\InvalidArgumentException $expected) {
- return;
- }
+ ErrorHandler::start(E_USER_WARNING);
+ $filtered = $this->_filter->filter($input);
+ $err = ErrorHandler::stop();
+
+ $this->assertEquals($input, $filtered);
+ $this->assertInstanceOf('ErrorException', $err);
+ $this->assertContains('cannot filter', $err->getMessage());
+ }
- $this->fail('An expected InvalidArgumentException has not been raised.');
+ /**
+ * @return void
+ */
+ public function testReturnsNullIfNullIsUsed()
+ {
+ $filtered = $this->_filter->filter(null);
+ $this->assertNull($filtered);
}
/**
View
27 tests/ZendTest/Filter/IntTest.php
@@ -11,6 +11,7 @@
namespace ZendTest\Filter;
use Zend\Filter\Int as IntFilter;
+use Zend\Stdlib\ErrorHandler;
/**
* @category Zend
@@ -43,21 +44,31 @@ public function testBasic()
}
/**
- * Ensures that an InvalidArgumentException is raised if array is used
+ * Ensures that a warning is raised if array is used
*
* @return void
*/
- public function testExceptionRaisedIfArrayUsed()
+ public function testWarningIsRaisedIfArrayUsed()
{
$filter = new IntFilter();
$input = array('123 test', '456 test');
- try {
- $filter->filter($input);
- } catch (\Zend\Filter\Exception\InvalidArgumentException $expected) {
- return;
- }
+ ErrorHandler::start(E_USER_WARNING);
+ $filtered = $filter->filter($input);
+ $err = ErrorHandler::stop();
+
+ $this->assertEquals($input, $filtered);
+ $this->assertInstanceOf('ErrorException', $err);
+ $this->assertContains('cannot filter', $err->getMessage());
+ }
- $this->fail('An expected InvalidArgumentException has not been raised.');
+ /**
+ * @return void
+ */
+ public function testReturnsNullIfNullIsUsed()
+ {
+ $filter = new IntFilter();
+ $filtered = $filter->filter(null);
+ $this->assertNull($filtered);
}
}
View
26 tests/ZendTest/Filter/RealPathTest.php
@@ -11,6 +11,7 @@
namespace ZendTest\Filter;
use Zend\Filter\RealPath as RealPathFilter;
+use Zend\Stdlib\ErrorHandler;
/**
* @category Zend
@@ -108,11 +109,11 @@ public function testNonExistantPath()
}
/**
- * Ensures that an InvalidArgumentException is raised if array is used
+ * Ensures that a warning is raised if array is used
*
* @return void
*/
- public function testExceptionRaisedIfArrayUsed()
+ public function testWarningIsRaisedIfArrayUsed()
{
$filter = $this->_filter;
$input = array(
@@ -120,12 +121,21 @@ public function testExceptionRaisedIfArrayUsed()
$this->_filesPath . DIRECTORY_SEPARATOR . 'file.2'
);
- try {
- $filter->filter($input);
- } catch (\Zend\Filter\Exception\InvalidArgumentException $expected) {
- return;
- }
+ ErrorHandler::start(E_USER_WARNING);
+ $filtered = $filter->filter($input);
+ $err = ErrorHandler::stop();
+
+ $this->assertEquals($input, $filtered);
+ $this->assertInstanceOf('ErrorException', $err);
+ $this->assertContains('cannot filter', $err->getMessage());
+ }
- $this->fail('An expected InvalidArgumentException has not been raised.');
+ /**
+ * @return void
+ */
+ public function testReturnsNullIfNullIsUsed()
+ {
+ $filtered = $this->_filter->filter(null);
+ $this->assertNull($filtered);
}
}
View
26 tests/ZendTest/Filter/StringToLowerTest.php
@@ -11,6 +11,7 @@
namespace ZendTest\Filter;
use Zend\Filter\StringToLower as StringToLowerFilter;
+use Zend\Stdlib\ErrorHandler;
/**
* @category Zend
@@ -160,20 +161,29 @@ public function testDetectMbInternalEncoding()
}
/**
- * Ensures that an InvalidArgumentException is raised if array is used
+ * Ensures that a warning is raised if array is used
*
* @return void
*/
- public function testExceptionRaisedIfArrayUsed()
+ public function testWarningIsRaisedIfArrayUsed()
{
$input = array('ABC', 'DEF');
- try {
- $this->_filter->filter($input);
- } catch (\Zend\Filter\Exception\InvalidArgumentException $expected) {
- return;
- }
+ ErrorHandler::start(E_USER_WARNING);
+ $filtered = $this->_filter->filter($input);
+ $err = ErrorHandler::stop();
+
+ $this->assertEquals($input, $filtered);
+ $this->assertInstanceOf('ErrorException', $err);
+ $this->assertContains('cannot filter', $err->getMessage());
+ }
- $this->fail('An expected InvalidArgumentException has not been raised.');
+ /**
+ * @return void
+ */
+ public function testReturnsNullIfNullIsUsed()
+ {
+ $filtered = $this->_filter->filter(null);
+ $this->assertNull($filtered);
}
}
View
26 tests/ZendTest/Filter/StringToUpperTest.php
@@ -11,6 +11,7 @@
namespace ZendTest\Filter;
use Zend\Filter\StringToUpper as StringToUpperFilter;
+use Zend\Stdlib\ErrorHandler;
/**
* @category Zend
@@ -160,20 +161,29 @@ public function testDetectMbInternalEncoding()
}
/**
- * Ensures that an InvalidArgumentException is raised if array is used
+ * Ensures that a warning is raised if array is used
*
* @return void
*/
- public function testExceptionRaisedIfArrayUsed()
+ public function testWarningIsRaisedIfArrayUsed()
{
$input = array('abc', 'def');
- try {
- $this->_filter->filter($input);
- } catch (\Zend\Filter\Exception\InvalidArgumentException $expected) {
- return;
- }
+ ErrorHandler::start(E_USER_WARNING);
+ $filtered = $this->_filter->filter($input);
+ $err = ErrorHandler::stop();
+
+ $this->assertEquals($input, $filtered);
+ $this->assertInstanceOf('ErrorException', $err);
+ $this->assertContains('cannot filter', $err->getMessage());
+ }
- $this->fail('An expected InvalidArgumentException has not been raised.');
+ /**
+ * @return void
+ */
+ public function testReturnsNullIfNullIsUsed()
+ {
+ $filtered = $this->_filter->filter(null);
+ $this->assertNull($filtered);
}
}
View
26 tests/ZendTest/Filter/StripTagsTest.php
@@ -11,6 +11,7 @@
namespace ZendTest\Filter;
use Zend\Filter\StripTags as StripTagsFilter;
+use Zend\Stdlib\ErrorHandler;
/**
* @category Zend
@@ -540,20 +541,29 @@ public function testFilterCanAllowHyphenatedAttributeNames()
}
/**
- * Ensures that an InvalidArgumentException is raised if array is used
+ * Ensures that a warning is raised if array is used
*
* @return void
*/
- public function testExceptionRaisedIfArrayUsed()
+ public function testWarningIsRaisedIfArrayUsed()
{
$input = array('<li data-name="Test User" data-id="11223"></li>', '<li data-name="Test User 2" data-id="456789"></li>');
- try {
- $this->_filter->filter($input);
- } catch (\Zend\Filter\Exception\InvalidArgumentException $expected) {
- return;
- }
+ ErrorHandler::start(E_USER_WARNING);
+ $filtered = $this->_filter->filter($input);
+ $err = ErrorHandler::stop();
- $this->fail('An expected InvalidArgumentException has not been raised.');
+ $this->assertEquals($input, $filtered);
+ $this->assertInstanceOf('ErrorException', $err);
+ $this->assertContains('cannot filter', $err->getMessage());
+ }
+
+ /**
+ * @return void
+ */
+ public function testReturnsNullIfNullIsUsed()
+ {
+ $filtered = $this->_filter->filter(null);
+ $this->assertNull($filtered);
}
}
Something went wrong with that request. Please try again.