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

Commit

Permalink
Merge branch 'hotfix/127' into release-2.7
Browse files Browse the repository at this point in the history
Close #127
Fixes #126
  • Loading branch information
weierophinney committed Sep 1, 2016
2 parents ac6675d + 24aa9be commit eeecb78
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 2.7.7 - TBD
## 2.7.7 - 2016-09-01

### Added

Expand All @@ -18,7 +18,10 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#127](https://github.com/zendframework/zend-servicemanager/pull/127) fixes
how the `AbstractPluingManager` handles `$options` arrays passed when
retrieving a plugin when that plugin resolves to the `InvokableFactory`,
ensuring subsequent calls with different options are created correctly.

## 2.7.6 - 2016-04-27

Expand Down
2 changes: 2 additions & 0 deletions src/AbstractPluginManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,8 @@ protected function createServiceViaCallback($callable, $cName, $rName)
&& !empty($this->creationOptions)
) {
$factory->setCreationOptions($this->creationOptions);
} elseif ($factory instanceof Factory\InvokableFactory) {
$factory->setCreationOptions([]);
}

return parent::createServiceViaCallback($callable, $cName, $rName);
Expand Down
15 changes: 15 additions & 0 deletions test/AbstractPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
use Interop\Container\ContainerInterface;
use ReflectionClass;
use ReflectionObject;
use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\Config;
use Zend\ServiceManager\Exception\InvalidArgumentException;
use Zend\ServiceManager\Exception\RuntimeException;
use Zend\ServiceManager\Factory\InvokableFactory;
use Zend\ServiceManager\ServiceManager;
use ZendTest\ServiceManager\TestAsset\Baz;
use ZendTest\ServiceManager\TestAsset\FooPluginManager;
use ZendTest\ServiceManager\TestAsset\InvokableObject;
use ZendTest\ServiceManager\TestAsset\MockSelfReturningDelegatorFactory;
Expand Down Expand Up @@ -138,6 +140,19 @@ public function testCallableObjectWithMutableCreationOptions()
$method->invoke($this->pluginManager, $callable, 'foo', 'bar');
}

public function testInvokableFactoryOptionsAffectMultipleInstantiations()
{
/** @var $pluginManager AbstractPluginManager */
$pluginManager = $this->getMockForAbstractClass('Zend\ServiceManager\AbstractPluginManager');
$pluginManager->setFactory(Baz::class, InvokableFactory::class);
$pluginManager->setShared(Baz::class, false);
$creationOptions = ['key1' => 'value1'];
$plugin1 = $pluginManager->get(Baz::class, $creationOptions);
$plugin2 = $pluginManager->get(Baz::class);

$this->assertNotEquals($plugin1, $plugin2);
}

public function testValidatePluginIsCalledWithDelegatorFactoryIfItsAService()
{
$pluginManager = $this->getMockForAbstractClass('Zend\ServiceManager\AbstractPluginManager');
Expand Down
20 changes: 20 additions & 0 deletions test/TestAsset/Baz.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/

namespace ZendTest\ServiceManager\TestAsset;

class Baz
{
public $options;

public function __construct($options = null)
{
$this->options = $options;
}
}

0 comments on commit eeecb78

Please sign in to comment.