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

Test for v2-v3 PluginManager migration #81

Merged
merged 2 commits into from
Feb 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}