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

Do not re-inject filter/validator chains of inputs pulled from plugin manager #151

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,10 @@ public function createInput($inputSpecification)
));
}

if ($this->defaultFilterChain) {
if (! $managerInstance && $this->defaultFilterChain) {
$input->setFilterChain(clone $this->defaultFilterChain);
}
if ($this->defaultValidatorChain) {
if (! $managerInstance && $this->defaultValidatorChain) {
$input->setValidatorChain(clone $this->defaultValidatorChain);
}

Expand Down
22 changes: 22 additions & 0 deletions test/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Interop\Container\ContainerInterface;
use PHPUnit_Framework_MockObject_MockObject as MockObject;
use PHPUnit\Framework\TestCase;
use Prophecy\Argument;
use Zend\Filter;
use Zend\InputFilter\CollectionInputFilter;
use Zend\InputFilter\Exception\InvalidArgumentException;
Expand Down Expand Up @@ -996,6 +997,27 @@ public function testClearDefaultValidatorChain()
$this->assertNull($factory->getDefaultValidatorChain());
}

/**
* @see https://github.com/zendframework/zend-inputfilter/issues/8
*/
public function testWhenCreateInputPullsInputFromThePluginManagerItMustNotOverwriteFilterAndValidatorChains()
{
$input = $this->prophesize(InputInterface::class);
$input->setFilterChain(Argument::any())->shouldNotBeCalled();
$input->setValidatorChain(Argument::any())->shouldNotBeCalled();

$pluginManager = $this->prophesize(InputFilterPluginManager::class);
$pluginManager->populateFactoryPluginManagers(Argument::type(Factory::class))->shouldBeCalled();
$pluginManager->has('Some\Test\Input')->willReturn(true);
$pluginManager->get('Some\Test\Input')->will([$input, 'reveal']);

$spec = ['type' => 'Some\Test\Input'];

$factory = new Factory($pluginManager->reveal());

$this->assertSame($input->reveal(), $factory->createInput($spec));
}

/**
* @return Factory
*/
Expand Down