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

Commit

Permalink
Merge branch 'master' of git://github.com/zendframework/zf2
Browse files Browse the repository at this point in the history
  • Loading branch information
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,19 +157,27 @@ public function createInput($inputSpecification)
}
break;
case 'filters':
if ($value instanceof FilterChain) {
$input->setFilterChain($value);
break;
}
if (!is_array($value) && !$value instanceof Traversable) {
throw new Exception\RuntimeException(sprintf(
'%s expects the value associated with "filters" to be an array/Traversable of filters or filter specifications; received "%s"',
'%s expects the value associated with "filters" to be an array/Traversable of filters or filter specifications, or a FilterChain; received "%s"',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
));
}
$this->populateFilters($input->getFilterChain(), $value);
break;
case 'validators':
if ($value instanceof ValidatorChain) {
$input->setValidatorChain($value);
break;
}
if (!is_array($value) && !$value instanceof Traversable) {
throw new Exception\RuntimeException(sprintf(
'%s expects the value associated with "validators" to be an array/Traversable of validators or validator specifications; received "%s"',
'%s expects the value associated with "validators" to be an array/Traversable of validators or validator specifications, or a ValidatorChain; received "%s"',
__METHOD__,
(is_object($value) ? get_class($value) : gettype($value))
));
Expand Down
26 changes: 26 additions & 0 deletions test/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,30 @@ public function testFactoryWillCreateInputFilterMatchingInputNameWhenNotSpecifie
$this->assertTrue($inputFilter->has('foo'));
$this->assertInstanceOf('Zend\InputFilter\Input', $inputFilter->get('foo'));
}

public function testFactoryAllowsPassingValidatorChainsInInputSpec()
{
$factory = new Factory();
$chain = new Validator\ValidatorChain();
$input = $factory->createInput(array(
'name' => 'foo',
'validators' => $chain,
));
$this->assertInstanceOf('Zend\InputFilter\InputInterface', $input);
$test = $input->getValidatorChain();
$this->assertSame($chain, $test);
}

public function testFactoryAllowsPassingFilterChainsInInputSpec()
{
$factory = new Factory();
$chain = new Filter\FilterChain();
$input = $factory->createInput(array(
'name' => 'foo',
'filters' => $chain,
));
$this->assertInstanceOf('Zend\InputFilter\InputInterface', $input);
$test = $input->getFilterChain();
$this->assertSame($chain, $test);
}
}

0 comments on commit 68c3d64

Please sign in to comment.