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/81' into release-2.7
Browse files Browse the repository at this point in the history
Close #81
  • Loading branch information
weierophinney committed Feb 1, 2016
2 parents 6479b54 + 956ef92 commit a2da76e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ All notable changes to this project will be documented in this file, in reverse

### Added

- Nothing.
- [#81](https://github.com/zendframework/zend-servicemanager/pull/81) adds a
test covering forwards-compatibility features for plugin manager
implementations.

### Deprecated

Expand Down
8 changes: 8 additions & 0 deletions test/AbstractPluginManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
use Zend\ServiceManager\Exception\RuntimeException;
use Zend\ServiceManager\ServiceManager;
use ZendTest\ServiceManager\TestAsset\FooPluginManager;
use ZendTest\ServiceManager\TestAsset\InvokableObject;
use ZendTest\ServiceManager\TestAsset\MockSelfReturningDelegatorFactory;
use ZendTest\ServiceManager\TestAsset\V2v3PluginManager;

class AbstractPluginManagerTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -333,4 +335,10 @@ public function testPassingArgumentsOtherThanNullConfigOrContainerAsFirstConstru
$this->setExpectedException(InvalidArgumentException::class);
new FooPluginManager($arg);
}

public function testV2v3PluginManager()
{
$pluginManager = new V2v3PluginManager(new ServiceManager());
$this->assertInstanceOf(InvokableObject::class, $pluginManager->get('foo'));
}
}
51 changes: 51 additions & 0 deletions test/TestAsset/V2v3PluginManager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?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;

use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\Exception\InvalidServiceException;
use Zend\ServiceManager\Factory\InvokableFactory;

class V2v3PluginManager extends AbstractPluginManager
{
protected $aliases = [
'foo' => InvokableObject::class,
];

protected $factories = [
InvokableObject::class => InvokableFactory::class,
// Legacy (v2) due to alias resolution
'zendtestservicemanagertestassetinvokableobject' => InvokableFactory::class,
];

protected $instanceOf = InvokableObject::class;


public function validate($plugin)
{
if ($plugin instanceof $this->instanceOf) {
return;
}

throw new InvalidServiceException(sprintf(
"'%s' is not an instance of '%s'",
get_class($plugin),
$this->instanceOf
));
}

/**
* {@inheritDoc}
*/
public function validatePlugin($plugin)
{
$this->validate($plugin);
}
}

0 comments on commit a2da76e

Please sign in to comment.