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

Commit bc5fb2a

Browse files
committed
Ensure HelperPluginManager constructor is forwards compatible
Added tests to ensure the plugin manager can be instantiated with either no arguments, or a `Zend\ServiceManager\Config` argument, when under zend-servicemanager v2, and updated the code to comply with the signature of `AbstractPluginManager::__construct()`.
1 parent 364ce6d commit bc5fb2a

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/HelperPluginManager.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -235,15 +235,16 @@ class HelperPluginManager extends AbstractPluginManager
235235
* Adds initializers to inject the attached renderer and translator, if
236236
* any, to the currently requested helper.
237237
*
238-
* @param ContainerInterface $container
239-
* @param array $config
238+
* @param null|ConfigInterface|ContainerInterface $configOrContainerInstance
239+
* @param array $v3config If $configOrContainerInstance is a container, this
240+
* value will be passed to the parent constructor.
240241
*/
241-
public function __construct(ContainerInterface $container, array $config = [])
242+
public function __construct($configOrContainerInstance = null, array $v3config = [])
242243
{
243244
$this->initializers[] = [$this, 'injectRenderer'];
244245
$this->initializers[] = [$this, 'injectTranslator'];
245246

246-
parent::__construct($container, $config);
247+
parent::__construct($configOrContainerInstance, $v3config);
247248
}
248249

249250
/**

test/HelperPluginManagerTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,32 @@ public function setUp()
3030
$this->helpers = new HelperPluginManager(new ServiceManager());
3131
}
3232

33+
/**
34+
* @group 43
35+
*/
36+
public function testConstructorArgumentsAreOptionalUnderV2()
37+
{
38+
if (method_exists($this->helpers, 'configure')) {
39+
$this->markTestSkipped('zend-servicemanager v3 plugin managers require a container argument');
40+
}
41+
42+
$helpers = new HelperPluginManager();
43+
$this->assertInstanceOf(HelperPluginManager::class, $helpers);
44+
}
45+
46+
/**
47+
* @group 43
48+
*/
49+
public function testConstructorAllowsConfigInstanceAsFirstArgumentUnderV2()
50+
{
51+
if (method_exists($this->helpers, 'configure')) {
52+
$this->markTestSkipped('zend-servicemanager v3 plugin managers require a container argument');
53+
}
54+
55+
$helpers = new HelperPluginManager(new Config([]));
56+
$this->assertInstanceOf(HelperPluginManager::class, $helpers);
57+
}
58+
3359
public function testViewIsNullByDefault()
3460
{
3561
$this->assertNull($this->helpers->getRenderer());

0 commit comments

Comments
 (0)