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

Commit 41c30e2

Browse files
committed
Ensure input filter plugin manager is BC with v2
- Renamed `MigrationTest` to `InputFilterPluginManagerCompatibilityTest` (consistency with other components, and this is specifically for testing migration of the plugin manager). - Added tests to validate that the `InputFilterPluginManager` accepts no arguments and/or a `ConfigInterface` argument to the constructor when using zend-servicemanager v2. - Updated the `InputFilterPluginManager` constructor to mirror that of the 2.7 and 3.0 series of zend-servicemanager; it also populates the initializers prior to calling the parent constructor, allowing overriding.
1 parent ec011db commit 41c30e2

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
lines changed

src/InputFilterPluginManager.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,16 @@ class InputFilterPluginManager extends AbstractPluginManager
6262
*/
6363
protected $shareByDefault = false;
6464

65-
6665
/**
67-
* @param ContainerInterface $parentLocator
68-
* @param array $config
66+
* @param null|\Zend\ServiceManager\ConfigInterface|ContainerInterface $configOrContainer
67+
* For zend-servicemanager v2, null or a ConfigInterface instance are
68+
* allowed; for v3, a ContainerInterface is expected.
69+
* @param array $v3config Optional configuration array (zend-servicemanager v3 only)
6970
*/
70-
public function __construct(ContainerInterface $parentLocator, array $config = [])
71+
public function __construct($configOrContainer = null, array $v3config = [])
7172
{
72-
parent::__construct($parentLocator, $config);
73-
$this->addInitializer([$this, 'populateFactory']);
73+
$this->initializers[] = [$this, 'populateFactory'];
74+
parent::__construct($configOrContainer, $v3config);
7475
}
7576

7677
/**

test/MigrationTest.php renamed to test/InputFilterPluginManagerCompatibilityTest.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
use PHPUnit_Framework_TestCase as TestCase;
1313
use Zend\InputFilter\Exception\RuntimeException;
1414
use Zend\InputFilter\InputFilterPluginManager;
15+
use Zend\ServiceManager\Config;
1516
use Zend\ServiceManager\ServiceManager;
1617
use Zend\ServiceManager\Test\CommonPluginManagerTrait;
1718

18-
class MigrationTest extends TestCase
19+
class InputFilterPluginManagerCompatibilityTest extends TestCase
1920
{
2021
use CommonPluginManagerTrait;
2122

@@ -39,4 +40,26 @@ protected function getInstanceOf()
3940
// InputFilterManager accepts multiple instance types
4041
return;
4142
}
43+
44+
public function testConstructorArgumentsAreOptionalUnderV2()
45+
{
46+
$plugins = $this->getPluginManager();
47+
if (method_exists($plugins, 'configure')) {
48+
$this->markTestSkipped('zend-servicemanager v3 plugin managers require a container argument');
49+
}
50+
51+
$plugins = new InputFilterPluginManager();
52+
$this->assertInstanceOf(InputFilterPluginManager::class, $plugins);
53+
}
54+
55+
public function testConstructorAllowsConfigInstanceAsFirstArgumentUnderV2()
56+
{
57+
$plugins = $this->getPluginManager();
58+
if (method_exists($plugins, 'configure')) {
59+
$this->markTestSkipped('zend-servicemanager v3 plugin managers require a container argument');
60+
}
61+
62+
$plugins = new InputFilterPluginManager(new Config([]));
63+
$this->assertInstanceOf(InputFilterPluginManager::class, $plugins);
64+
}
4265
}

0 commit comments

Comments
 (0)