Skip to content

Commit

Permalink
[zendframework#15] validateInputs must allow ArrayAccess for $data
Browse files Browse the repository at this point in the history
Per report on zendframework#15, the change made in zendframework#7 could lead to an issue if $data
is an `ArrayAccess` instance, as `validateInputs()` typehinted on `array`.
This patch adds a test for that condition, and removes the typehint.
  • Loading branch information
weierophinney committed Aug 11, 2015
1 parent bb78ee1 commit aad437a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/BaseInputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,12 @@ public function isValid($context = null)
/**
* Validate a set of inputs against the current data
*
* @param array $inputs
* @param array $data
* @param array $inputs
* @param array|ArrayAccess $data
* @param mixed|null $context
* @return bool
*/
protected function validateInputs(array $inputs, array $data = [], $context = null)
protected function validateInputs(array $inputs, $data = [], $context = null)
{
// backwards compatibility
if (empty($data)) {
Expand Down
18 changes: 18 additions & 0 deletions test/BaseInputFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace ZendTest\InputFilter;

use ArrayObject;
use PHPUnit_Framework_TestCase as TestCase;
use stdClass;
use Zend\InputFilter\Input;
Expand Down Expand Up @@ -1096,4 +1097,21 @@ public function testEmptyRequiredValueWithFallbackShouldMarkInputValid()
$this->assertArrayHasKey('bar', $data);
$this->assertEquals($bar->getFallbackValue(), $data['bar']);
}

/**
* @group 15
*/
public function testAllowsValidatingArrayAccessData()
{
$filter = new InputFilter();
$foo = new Input();
$foo->getFilterChain()->attachByName('stringtrim')
->attachByName('alpha');
$foo->getValidatorChain()->attach(new Validator\StringLength(3, 6));
$filter->add($foo, 'foo');

$data = new ArrayObject(['foo' => ' valid ']);
$filter->setData($data);
$this->assertTrue($filter->isValid());
}
}

0 comments on commit aad437a

Please sign in to comment.