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

Commit 1ae32f7

Browse files
committed
[#15] validateInputs must allow ArrayAccess for $data
Per report on #15, the change made in #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.
1 parent bb78ee1 commit 1ae32f7

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

src/BaseInputFilter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,12 +224,12 @@ public function isValid($context = null)
224224
/**
225225
* Validate a set of inputs against the current data
226226
*
227-
* @param array $inputs
228-
* @param array $data
227+
* @param array $inputs
228+
* @param array|ArrayAccess $data
229229
* @param mixed|null $context
230230
* @return bool
231231
*/
232-
protected function validateInputs(array $inputs, array $data = [], $context = null)
232+
protected function validateInputs(array $inputs, $data = [], $context = null)
233233
{
234234
// backwards compatibility
235235
if (empty($data)) {

test/BaseInputFilterTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace ZendTest\InputFilter;
1111

12+
use ArrayObject;
1213
use PHPUnit_Framework_TestCase as TestCase;
1314
use stdClass;
1415
use Zend\InputFilter\Input;
@@ -1096,4 +1097,21 @@ public function testEmptyRequiredValueWithFallbackShouldMarkInputValid()
10961097
$this->assertArrayHasKey('bar', $data);
10971098
$this->assertEquals($bar->getFallbackValue(), $data['bar']);
10981099
}
1100+
1101+
/**
1102+
* @group 15
1103+
*/
1104+
public function testAllowsValidatingArrayAccessData()
1105+
{
1106+
$filter = new InputFilter();
1107+
$foo = new Input();
1108+
$foo->getFilterChain()->attachByName('stringtrim')
1109+
->attachByName('alpha');
1110+
$foo->getValidatorChain()->attach(new Validator\StringLength(3, 6));
1111+
$filter->add($foo, 'foo');
1112+
1113+
$data = new ArrayObject(['foo' => ' valid ']);
1114+
$filter->setData($data);
1115+
$this->assertTrue($filter->isValid());
1116+
}
10991117
}

0 commit comments

Comments
 (0)