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

Commit

Permalink
Ensure HelperPluginManager constructor is forwards compatible
Browse files Browse the repository at this point in the history
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()`.
  • Loading branch information
weierophinney committed Feb 18, 2016
1 parent 364ce6d commit bc5fb2a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/HelperPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,15 +235,16 @@ class HelperPluginManager extends AbstractPluginManager
* Adds initializers to inject the attached renderer and translator, if
* any, to the currently requested helper.
*
* @param ContainerInterface $container
* @param array $config
* @param null|ConfigInterface|ContainerInterface $configOrContainerInstance
* @param array $v3config If $configOrContainerInstance is a container, this
* value will be passed to the parent constructor.
*/
public function __construct(ContainerInterface $container, array $config = [])
public function __construct($configOrContainerInstance = null, array $v3config = [])
{
$this->initializers[] = [$this, 'injectRenderer'];
$this->initializers[] = [$this, 'injectTranslator'];

parent::__construct($container, $config);
parent::__construct($configOrContainerInstance, $v3config);
}

/**
Expand Down
26 changes: 26 additions & 0 deletions test/HelperPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,32 @@ public function setUp()
$this->helpers = new HelperPluginManager(new ServiceManager());
}

/**
* @group 43
*/
public function testConstructorArgumentsAreOptionalUnderV2()
{
if (method_exists($this->helpers, 'configure')) {
$this->markTestSkipped('zend-servicemanager v3 plugin managers require a container argument');
}

$helpers = new HelperPluginManager();
$this->assertInstanceOf(HelperPluginManager::class, $helpers);
}

/**
* @group 43
*/
public function testConstructorAllowsConfigInstanceAsFirstArgumentUnderV2()
{
if (method_exists($this->helpers, 'configure')) {
$this->markTestSkipped('zend-servicemanager v3 plugin managers require a container argument');
}

$helpers = new HelperPluginManager(new Config([]));
$this->assertInstanceOf(HelperPluginManager::class, $helpers);
}

public function testViewIsNullByDefault()
{
$this->assertNull($this->helpers->getRenderer());
Expand Down

0 comments on commit bc5fb2a

Please sign in to comment.