From 645cb36b90024889f59ebdebabfac5aab2353a5d Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 29 Mar 2016 15:04:29 -0500 Subject: [PATCH 1/6] Correct namespace for RouteMatch --- test/Controller/ConsoleControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Controller/ConsoleControllerTest.php b/test/Controller/ConsoleControllerTest.php index 9139db3..b2434a1 100644 --- a/test/Controller/ConsoleControllerTest.php +++ b/test/Controller/ConsoleControllerTest.php @@ -16,7 +16,7 @@ use Zend\Mvc\Console\View\ViewModel; use Zend\Mvc\Controller\PluginManager; use Zend\Mvc\MvcEvent; -use Zend\Mvc\Router\RouteMatch; +use Zend\Router\RouteMatch; class ConsoleControllerTest extends TestCase { From 1b6d75dad9477a167e80289b560259849c590f77 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 29 Mar 2016 15:04:56 -0500 Subject: [PATCH 2/6] Update to latest develop branch of zend-mvc --- composer.lock | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/composer.lock b/composer.lock index ab8ccf3..17bcd13 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "e534104245ac99f8750c5de45d0c92c0", - "content-hash": "badac3ab64d35b86406b3b4b35467012", + "hash": "54a678bd018f51298c8ce341e9e6bacc", + "content-hash": "af17ddd6ea48f54eb17254af8ad1a202", "packages": [ { "name": "container-interop/container-interop", @@ -677,12 +677,12 @@ "source": { "type": "git", "url": "https://github.com/zendframework/zend-mvc.git", - "reference": "2ed15b67c2d7cc60a1ba3c4b3f7075af4934b359" + "reference": "e1e42c33c9e329794767d8dd7b92fd644e1d0e1a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/zendframework/zend-mvc/zipball/2ed15b67c2d7cc60a1ba3c4b3f7075af4934b359", - "reference": "2ed15b67c2d7cc60a1ba3c4b3f7075af4934b359", + "url": "https://api.github.com/repos/zendframework/zend-mvc/zipball/e1e42c33c9e329794767d8dd7b92fd644e1d0e1a", + "reference": "e1e42c33c9e329794767d8dd7b92fd644e1d0e1a", "shasum": "" }, "require": { @@ -690,8 +690,10 @@ "php": "^5.5 || ^7.0", "zendframework/zend-eventmanager": "^2.6.2 || ^3.0", "zendframework/zend-form": "^2.7", + "zendframework/zend-http": "^2.5.4", "zendframework/zend-hydrator": "^1.1 || ^2.1", "zendframework/zend-psr7bridge": "^0.2", + "zendframework/zend-router": "^3.0", "zendframework/zend-servicemanager": "^2.7.5 || ^3.0.3", "zendframework/zend-stdlib": "^2.7.5 || ^3.0" }, @@ -699,21 +701,16 @@ "fabpot/php-cs-fixer": "1.7.*", "phpunit/phpunit": "^4.5", "sebastian/version": "^1.0.4", - "zendframework/zend-authentication": "^2.5.3", "zendframework/zend-cache": "^2.6.1", - "zendframework/zend-console": "^2.6", "zendframework/zend-di": "^2.6", "zendframework/zend-filter": "^2.6.1", - "zendframework/zend-http": "^2.5.4", "zendframework/zend-i18n": "^2.6", "zendframework/zend-inputfilter": "^2.6", "zendframework/zend-json": "^2.6.1", "zendframework/zend-log": "^2.7.1", "zendframework/zend-modulemanager": "^2.7.1", "zendframework/zend-serializer": "^2.6.1", - "zendframework/zend-session": "^2.6.2", "zendframework/zend-text": "^2.6", - "zendframework/zend-uri": "^2.5", "zendframework/zend-validator": "^2.6", "zendframework/zend-version": "^2.5", "zendframework/zend-view": "^2.6.3" @@ -721,7 +718,6 @@ "suggest": { "zendframework/zend-authentication": "Zend\\Authentication component for Identity plugin", "zendframework/zend-config": "Zend\\Config component", - "zendframework/zend-console": "Zend\\Console component", "zendframework/zend-di": "Zend\\Di component", "zendframework/zend-filter": "Zend\\Filter component", "zendframework/zend-http": "Zend\\Http component", @@ -730,10 +726,14 @@ "zendframework/zend-json": "Zend\\Json component", "zendframework/zend-log": "Zend\\Log component", "zendframework/zend-modulemanager": "Zend\\ModuleManager component", + "zendframework/zend-mvc-console": "zend-mvc-console provides the ability to expose zend-mvc as a console application", + "zendframework/zend-mvc-plugin-fileprg": "To provide Post/Redirect/Get functionality around forms that container file uploads", + "zendframework/zend-mvc-plugin-flashmessenger": "To provide flash messaging capabilities between requests", + "zendframework/zend-mvc-plugin-identity": "To access the authenticated identity (per zend-authentication) in controllers", + "zendframework/zend-mvc-plugin-prg": "To provide Post/Redirect/Get functionality within controllers", "zendframework/zend-serializer": "Zend\\Serializer component", "zendframework/zend-session": "Zend\\Session component for FlashMessenger, PRG, and FPRG plugins", "zendframework/zend-text": "Zend\\Text component", - "zendframework/zend-uri": "Zend\\Uri component", "zendframework/zend-validator": "Zend\\Validator component", "zendframework/zend-version": "Zend\\Version component", "zendframework/zend-view": "Zend\\View component" @@ -742,7 +742,7 @@ "extra": { "branch-alias": { "dev-master": "2.7-dev", - "dev-develop": "2.8-dev" + "dev-develop": "3.0-dev" } }, "autoload": { @@ -759,7 +759,7 @@ "mvc", "zf2" ], - "time": "2016-03-08 18:57:26" + "time": "2016-03-29 18:44:18" }, { "name": "zendframework/zend-psr7bridge", @@ -2193,25 +2193,25 @@ }, { "name": "symfony/yaml", - "version": "v3.0.3", + "version": "v2.8.4", "source": { "type": "git", "url": "https://github.com/symfony/yaml.git", - "reference": "b5ba64cd67ecd6887f63868fa781ca094bd1377c" + "reference": "584e52cb8f788a887553ba82db6caacb1d6260bb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/yaml/zipball/b5ba64cd67ecd6887f63868fa781ca094bd1377c", - "reference": "b5ba64cd67ecd6887f63868fa781ca094bd1377c", + "url": "https://api.github.com/repos/symfony/yaml/zipball/584e52cb8f788a887553ba82db6caacb1d6260bb", + "reference": "584e52cb8f788a887553ba82db6caacb1d6260bb", "shasum": "" }, "require": { - "php": ">=5.5.9" + "php": ">=5.3.9" }, "type": "library", "extra": { "branch-alias": { - "dev-master": "3.0-dev" + "dev-master": "2.8-dev" } }, "autoload": { @@ -2238,7 +2238,7 @@ ], "description": "Symfony Yaml Component", "homepage": "https://symfony.com", - "time": "2016-02-23 15:16:06" + "time": "2016-03-04 07:54:35" } ], "aliases": [ From 291cab7e9d66dabed361a8a7046568e26f0e2420 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 29 Mar 2016 15:29:47 -0500 Subject: [PATCH 3/6] Ensure tests run with latest develop version of zend-mvc Since zend-mvc removes console functionality now, we need to mimic the work that the `Module` class does in prepping services within tests. --- test/Controller/ConsoleControllerTest.php | 6 ++++++ test/View/ViewManagerTest.php | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/test/Controller/ConsoleControllerTest.php b/test/Controller/ConsoleControllerTest.php index b2434a1..c2ea646 100644 --- a/test/Controller/ConsoleControllerTest.php +++ b/test/Controller/ConsoleControllerTest.php @@ -17,6 +17,7 @@ use Zend\Mvc\Controller\PluginManager; use Zend\Mvc\MvcEvent; use Zend\Router\RouteMatch; +use Zend\ServiceManager\Factory\InvokableFactory; class ConsoleControllerTest extends TestCase { @@ -28,6 +29,11 @@ class ConsoleControllerTest extends TestCase public function setUp() { $this->controller = new TestAsset\ConsoleController(); + + $plugins = $this->controller->getPluginManager(); + $plugins->setAlias('createConsoleNotFoundModel', CreateConsoleNotFoundModel::class); + $plugins->setFactory(CreateConsoleNotFoundModel::class, InvokableFactory::class); + $routeMatch = new RouteMatch(['controller' => 'controller-sample']); $event = new MvcEvent(); $event->setRouteMatch($routeMatch); diff --git a/test/View/ViewManagerTest.php b/test/View/ViewManagerTest.php index b3f56aa..ea23f60 100644 --- a/test/View/ViewManagerTest.php +++ b/test/View/ViewManagerTest.php @@ -24,16 +24,21 @@ use Zend\EventManager\Test\EventListenerIntrospectionTrait; use Zend\Mvc\Application; use Zend\Mvc\MvcEvent; +use Zend\Mvc\Console\Service\ConsoleExceptionStrategyFactory; +use Zend\Mvc\Console\Service\ConsoleRouteNotFoundStrategyFactory; use Zend\Mvc\Console\Service\ConsoleViewManagerFactory; +use Zend\Mvc\Console\Service\DefaultRenderingStrategyFactory; use Zend\Mvc\Console\View\DefaultRenderingStrategy; use Zend\Mvc\Console\View\ExceptionStrategy; use Zend\Mvc\Console\View\CreateViewModelListener; use Zend\Mvc\Console\View\InjectNamedConsoleParamsListener; use Zend\Mvc\Console\View\InjectViewModelListener; +use Zend\Mvc\Console\View\Renderer; use Zend\Mvc\Console\View\RouteNotFoundStrategy; use Zend\Mvc\Console\View\ViewManager; use Zend\Mvc\Service\ServiceListenerFactory; use Zend\Mvc\Service\ServiceManagerConfig; +use Zend\ServiceManager\Factory\InvokableFactory; use Zend\ServiceManager\ServiceManager; use Zend\Stdlib\DispatchableInterface; use Zend\View\View; @@ -243,6 +248,10 @@ public function testConsoleKeyWillOverrideDisplayExceptionAndExceptionMessage($c $this->services->setService('EventManager', $eventManager); $this->services->setService('Request', $request); $this->services->setService('Response', $response); + $this->services->setFactory('ConsoleRouteNotFoundStrategy', ConsoleRouteNotFoundStrategyFactory::class); + $this->services->setFactory('ConsoleExceptionStrategy', ConsoleExceptionStrategyFactory::class); + $this->services->setFactory('ConsoleDefaultRenderingStrategy', DefaultRenderingStrategyFactory::class); + $this->services->setFactory(Renderer::class, InvokableFactory::class); $this->services->setAllowOverride(false); $manager = $this->factory->__invoke($this->services, 'ConsoleViewRenderer'); @@ -271,6 +280,10 @@ public function testConsoleDisplayExceptionIsTrue() $this->services->setService('EventManager', $eventManager); $this->services->setService('Request', $request); $this->services->setService('Response', $response); + $this->services->setFactory('ConsoleRouteNotFoundStrategy', ConsoleRouteNotFoundStrategyFactory::class); + $this->services->setFactory('ConsoleExceptionStrategy', ConsoleExceptionStrategyFactory::class); + $this->services->setFactory('ConsoleDefaultRenderingStrategy', DefaultRenderingStrategyFactory::class); + $this->services->setFactory(Renderer::class, InvokableFactory::class); $this->services->setAllowOverride(false); $manager = new ViewManager; @@ -281,11 +294,11 @@ public function testConsoleDisplayExceptionIsTrue() $manager->onBootstrap($event); $exceptionStrategy = $this->services->get('ConsoleExceptionStrategy'); - $this->assertInstanceOf('Zend\Mvc\View\Console\ExceptionStrategy', $exceptionStrategy); + $this->assertInstanceOf(ExceptionStrategy::class, $exceptionStrategy); $this->assertTrue($exceptionStrategy->displayExceptions()); $routeNotFoundStrategy = $this->services->get('ConsoleRouteNotFoundStrategy'); - $this->assertInstanceOf('Zend\Mvc\View\Console\RouteNotFoundStrategy', $routeNotFoundStrategy); + $this->assertInstanceOf(RouteNotFoundStrategy::class, $routeNotFoundStrategy); $this->assertTrue($routeNotFoundStrategy->displayNotFoundReason()); } From 2d89fd10db8b371399240419850978fee2d904e2 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 29 Mar 2016 15:34:04 -0500 Subject: [PATCH 4/6] Plugins can be registered via standard configuration They do not require a delegator factory! --- src/ConfigProvider.php | 23 +++++++- src/Module.php | 1 + ...ontrollerPluginManagerDelegatorFactory.php | 52 ------------------- ...ollerPluginManagerDelegatorFactoryTest.php | 38 -------------- 4 files changed, 23 insertions(+), 91 deletions(-) delete mode 100644 src/Service/ControllerPluginManagerDelegatorFactory.php delete mode 100644 test/Service/ControllerPluginManagerDelegatorFactoryTest.php diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 5cc5586..3f3459c 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -20,7 +20,8 @@ class ConfigProvider public function __invoke() { return [ - 'dependencies' => $this->getDependencyConfig(), + 'controller_plugins' => $this->getPluginConfig(), + 'dependencies' => $this->getDependencyConfig(), ]; } @@ -57,4 +58,24 @@ public function getDependencyConfig() ], ]; } + + /** + * Provide controller plugin configuration for this component. + * + * @return array + */ + public function getPluginConfig() + { + return [ + 'aliases' => [ + 'CreateConsoleNotFoundModel' => Controller\Plugin\CreateConsoleNotFoundModel::class, + 'createConsoleNotFoundModel' => Controller\Plugin\CreateConsoleNotFoundModel::class, + 'createconsolenotfoundmodel' => Controller\Plugin\CreateConsoleNotFoundModel::class, + 'Zend\Mvc\Controller\Plugin\CreateConsoleNotFoundModel::class' => Controller\Plugin\CreateConsoleNotFoundModel::class, + ], + 'factories' => [ + Controller\Plugin\CreateConsoleNotFoundModel::class => InvokableFactory::class, + ], + ]; + } } diff --git a/src/Module.php b/src/Module.php index ada33f8..ff59a92 100644 --- a/src/Module.php +++ b/src/Module.php @@ -18,6 +18,7 @@ public function getConfig() { $provider = new ConfigProvider(); return [ + 'controller_plugins' => $provider->getPluginConfig(), 'service_manager' => $provider->getDependencyConfig(), 'console' => ['router' => ['routes' => []]], ]; diff --git a/src/Service/ControllerPluginManagerDelegatorFactory.php b/src/Service/ControllerPluginManagerDelegatorFactory.php deleted file mode 100644 index 131aa13..0000000 --- a/src/Service/ControllerPluginManagerDelegatorFactory.php +++ /dev/null @@ -1,52 +0,0 @@ -setAlias('CreateConsoleNotFoundModel', CreateConsoleNotFoundModel::class); - $plugins->setAlias('createConsoleNotFoundModel', CreateConsoleNotFoundModel::class); - $plugins->setAlias('createconsolenotfoundmodel', CreateConsoleNotFoundModel::class); - $plugins->setFactory(CreateConsoleNotFoundModel::class, InvokableFactory::class); - - return $plugins; - } - - /** - * Add console-specific plugins to the controller PluginManager. (v2) - * - * @param ServiceLocatorInterface $container - * @param string $name - * @param string $requestedName - * @param callable $callback - * @return \Zend\Mvc\Controller\PluginManager - */ - public function createDelegatorWithName(ServiceLocatorInterface $container, $name, $requestedName, $callback) - { - return $this($container, $requestedName, $callback); - } -} diff --git a/test/Service/ControllerPluginManagerDelegatorFactoryTest.php b/test/Service/ControllerPluginManagerDelegatorFactoryTest.php deleted file mode 100644 index 11838ca..0000000 --- a/test/Service/ControllerPluginManagerDelegatorFactoryTest.php +++ /dev/null @@ -1,38 +0,0 @@ -prophesize(PluginManager::class); - $plugins->setAlias('CreateConsoleNotFoundModel', CreateConsoleNotFoundModel::class)->shouldBeCalled(); - $plugins->setAlias('createConsoleNotFoundModel', CreateConsoleNotFoundModel::class)->shouldBeCalled(); - $plugins->setAlias('createconsolenotfoundmodel', CreateConsoleNotFoundModel::class)->shouldBeCalled(); - $plugins->setFactory(CreateConsoleNotFoundModel::class, InvokableFactory::class)->shouldBeCalled(); - - $callback = function () use ($plugins) { - return $plugins->reveal(); - }; - - $factory = new ControllerPluginManagerDelegatorFactory(); - $this->assertSame($plugins->reveal(), $factory( - $this->prophesize(ContainerInterface::class)->reveal(), - 'ControllerPluginManager', - $callback - )); - } -} From d2b3f92ed0c652b509fc03f7eb55b0820ae91534 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 29 Mar 2016 15:38:42 -0500 Subject: [PATCH 5/6] Fix CS warning in ConfigProvider --- src/ConfigProvider.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 3f3459c..c4369d2 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -66,6 +66,7 @@ public function getDependencyConfig() */ public function getPluginConfig() { + // @codingStandardsIgnoreStart return [ 'aliases' => [ 'CreateConsoleNotFoundModel' => Controller\Plugin\CreateConsoleNotFoundModel::class, @@ -77,5 +78,6 @@ public function getPluginConfig() Controller\Plugin\CreateConsoleNotFoundModel::class => InvokableFactory::class, ], ]; + // @codingStandardsIgnoreEnd } } From 292eb3c27e009f62ea1b83ac75c8028bc5129a89 Mon Sep 17 00:00:00 2001 From: Matthew Weier O'Phinney Date: Tue, 29 Mar 2016 15:41:43 -0500 Subject: [PATCH 6/6] Added CHANGELOG for #4 --- CHANGELOG.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9ae29a..5392663 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,11 @@ All notable changes to this project will be documented in this file, in reverse ### Fixed -- Nothing. +- [#4](https://github.com/zendframework/zend-mvc-console/pull/4) updates the + code base to work with zendframework/zend-mvc@e1e42c33. As that revision (a) + removes console-related functionality, and (b) removes routing functionality, + it detailed further changes to this component required to ensure it runs + correctly as a module. ## 1.1.0 - 2016-03-23