From 4c8a72d315e7727d4035b26635e4847778918577 Mon Sep 17 00:00:00 2001 From: Matt Kynaston Date: Fri, 29 Jan 2016 16:55:18 +0000 Subject: [PATCH 1/2] Updated factories, reverted validatePlugin for v2-v3 compat --- .travis.yml | 4 +++ composer.json | 7 +++-- src/Table/DecoratorManager.php | 48 +++++++++++++++++++++++++++-- test/Table/DecoratorManagerTest.php | 31 +++++++++++++++++++ 4 files changed, 84 insertions(+), 6 deletions(-) create mode 100644 test/Table/DecoratorManagerTest.php diff --git a/.travis.yml b/.travis.yml index 73f4c14..8432b54 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,9 +16,11 @@ matrix: include: - php: 5.5 env: + - SERVICE_MANAGER_VERSION="^2.7.3" - EXECUTE_CS_CHECK=true - php: 5.6 env: + - SERVICE_MANAGER_VERSION="^2.7.3" - EXECUTE_TEST_COVERALLS=true - php: 7 - php: hhvm @@ -34,6 +36,8 @@ before_install: - if [[ $EXECUTE_TEST_COVERALLS != 'true' ]]; then phpenv config-rm xdebug.ini || return 0 ; fi - composer self-update - if [[ $EXECUTE_TEST_COVERALLS == 'true' ]]; then composer require --dev --no-update satooshi/php-coveralls ; fi + - if [[ $SERVICE_MANAGER_VERSION != '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:$SERVICE_MANAGER_VERSION" ; fi + - if [[ $SERVICE_MANAGER_VERSION == '' ]]; then composer require --dev --no-update "zendframework/zend-servicemanager:^3.0" ; fi install: - travis_retry composer install --no-interaction --ignore-platform-reqs diff --git a/composer.json b/composer.json index 3916e33..70fb696 100644 --- a/composer.json +++ b/composer.json @@ -15,19 +15,20 @@ "require": { "php": ">=5.5", "zendframework/zend-stdlib": "dev-develop as 2.8.0", - "zendframework/zend-servicemanager": "dev-develop as 2.7.0" + "zendframework/zend-servicemanager": "^2.7.3 || ^3.0" }, "minimum-stability": "dev", "prefer-stable": true, "extra": { "branch-alias": { "dev-master": "2.5-dev", - "dev-develop": "3.0-dev" + "dev-develop": "2.6-dev" } }, "autoload-dev": { "psr-4": { - "ZendTest\\Text\\": "test/" + "ZendTest\\Text\\": "test/", + "ZendTest\\ServiceManager\\": "vendor/zendframework/zend-servicemanager/test" } }, "require-dev": { diff --git a/src/Table/DecoratorManager.php b/src/Table/DecoratorManager.php index 750c11e..ea24c53 100644 --- a/src/Table/DecoratorManager.php +++ b/src/Table/DecoratorManager.php @@ -9,6 +9,7 @@ namespace Zend\Text\Table; +use Zend\ServiceManager\Exception\InvalidServiceException; use Zend\ServiceManager\Factory\InvokableFactory; use Zend\ServiceManager\AbstractPluginManager; @@ -28,16 +29,57 @@ class DecoratorManager extends AbstractPluginManager */ protected $aliases = [ 'ascii' => Decorator\Ascii::class, + 'Ascii' => Decorator\Ascii::class, 'blank' => Decorator\Blank::class, + 'Blank' => Decorator\Blank::class, 'unicode' => Decorator\Unicode::class, + 'Unicode' => Decorator\Unicode::class, ]; protected $factories = [ - Decorator\Ascii::class => InvokableFactory::class, - Decorator\Blank::class => InvokableFactory::class, - Decorator\Unicode::class => InvokableFactory::class, + Decorator\Ascii::class => InvokableFactory::class, + Decorator\Unicode::class => InvokableFactory::class, + Decorator\Blank::class => InvokableFactory::class, + 'zendtexttabledecoratorascii' => InvokableFactory::class, + 'zendtexttabledecoratorblank' => InvokableFactory::class, + 'zendtexttabledecoratorunicode' => InvokableFactory::class, ]; protected $instanceOf = Decorator\DecoratorInterface::class; + + /** + * {@inheritdoc} (v3) + */ + public function validate($instance) + { + if ($instance instanceof $this->instanceOf) { + // we're okay + return; + } + + throw new InvalidServiceException(sprintf( + 'Plugin of type %s is invalid; must implement %s\Decorator\DecoratorInterface', + (is_object($instance) ? get_class($instance) : gettype($instance)), + __NAMESPACE__ + )); + } + + /** + * Validate the plugin (v2) + * + * Checks that the decorator loaded is an instance of Decorator\DecoratorInterface. + * + * @param mixed $plugin + * @return void + * @throws Exception\InvalidDecoratorException if invalid + */ + public function validatePlugin($plugin) + { + try { + $this->validate($plugin); + } catch (InvalidServiceException $e) { + throw new Exception\InvalidDecoratorException($e->getMessage(), $e->getCode(), $e); + } + } } diff --git a/test/Table/DecoratorManagerTest.php b/test/Table/DecoratorManagerTest.php new file mode 100644 index 0000000..d111c8f --- /dev/null +++ b/test/Table/DecoratorManagerTest.php @@ -0,0 +1,31 @@ + Date: Sat, 6 Feb 2016 11:33:16 +0000 Subject: [PATCH 2/2] Updated test to use CommonPluginManagerTrait from Zend\ServiceManager\Test --- composer.json | 3 +-- test/Table/DecoratorManagerTest.php | 8 +++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 70fb696..e35239f 100644 --- a/composer.json +++ b/composer.json @@ -27,8 +27,7 @@ }, "autoload-dev": { "psr-4": { - "ZendTest\\Text\\": "test/", - "ZendTest\\ServiceManager\\": "vendor/zendframework/zend-servicemanager/test" + "ZendTest\\Text\\": "test/" } }, "require-dev": { diff --git a/test/Table/DecoratorManagerTest.php b/test/Table/DecoratorManagerTest.php index d111c8f..a7876ba 100644 --- a/test/Table/DecoratorManagerTest.php +++ b/test/Table/DecoratorManagerTest.php @@ -11,9 +11,10 @@ use PHPUnit_Framework_TestCase as TestCase; use Zend\ServiceManager\ServiceManager; +use Zend\ServiceManager\Test\CommonPluginManagerTrait; +use Zend\Text\Table\Decorator\DecoratorInterface; use Zend\Text\Table\DecoratorManager; use Zend\Text\Table\Exception\InvalidDecoratorException; -use ZendTest\ServiceManager\CommonPluginManagerTrait; class DecoratorManagerTest extends TestCase { @@ -28,4 +29,9 @@ protected function getV2InvalidPluginException() { return InvalidDecoratorException::class; } + + protected function getInstanceOf() + { + return DecoratorInterface::class; + } }