From 640303e18d43288149e9ba9df0dc43ed842faa0c Mon Sep 17 00:00:00 2001 From: George Steel Date: Mon, 10 Jan 2022 23:02:48 +0000 Subject: [PATCH] - Removes all compatibility with service-manager v2 - Update baseline Signed-off-by: George Steel --- psalm-baseline.xml | 72 +++---------------- src/Helper/Navigation/AbstractHelper.php | 33 ++------- src/Helper/Navigation/PluginManager.php | 10 ++- src/Helper/Service/AssetFactory.php | 5 -- src/Helper/Service/FlashMessengerFactory.php | 6 -- src/Helper/Service/IdentityFactory.php | 7 -- test/Helper/Navigation/BreadcrumbsTest.php | 4 +- test/Helper/Navigation/LinksTest.php | 3 +- .../PluginManagerCompatibilityTest.php | 50 ------------- test/HelperPluginManagerTest.php | 46 +----------- 10 files changed, 21 insertions(+), 215 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index d9a9b8995..23d7397a5 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,5 @@ - + $templatePath @@ -862,10 +862,9 @@ $view $view - + $helper $helper - $this->getServiceLocator() $this->plugins $view && $this->plugins @@ -875,16 +874,9 @@ - - getServiceLocator - getServiceLocator - - - ! $services + ! is_int($this->minDepth) ! is_string($message) - $services - $this->role === null null === $this->container @@ -894,7 +886,7 @@ Navigation\Exception\ExceptionInterface - + $container $container $container @@ -914,28 +906,16 @@ $minDepth $minDepth $minDepth - $role - $role - $role - $role - $role - $serviceLocator - $serviceLocator - $serviceLocator - $serviceLocator - $serviceLocator $page->getTextDomain() $page->getTextDomain() - + $container $container $container $label - $serviceLocator - $this->serviceLocator $value @@ -962,10 +942,9 @@ $page->getTitle() - + $maxDepth $minDepth - $role attach @@ -978,17 +957,12 @@ (bool) $useAcl (string) $indent - - $serviceLocator->getServiceLocator() + $this->acl === null && static::$defaultAcl !== null - $this->role === null && static::$defaultRole !== null is_int($maxDepth) is_int($minDepth) - is_string($this->role) - is_string(static::$defaultRole) null !== $this->container static::$defaultAcl !== null - static::$defaultRole !== null plugin @@ -1664,20 +1638,13 @@ $config['view_helper_config'] - + $config $configHelper - $container - - get - $cName - - getServiceLocator - @@ -1711,14 +1678,13 @@ $configHelper['message_separator_string'] $config['view_helper_config'] - + $config $configHelper - $container $controllerPluginManager $flashMessenger - + get get get @@ -1729,20 +1695,11 @@ $requestedName - - getServiceLocator - IdentityFactory - - $container - - - $container - null|AuthenticationServiceInterface @@ -1753,9 +1710,6 @@ $cName - - getServiceLocator - @@ -3282,12 +3236,6 @@ $code - - - $this->getServiceNotFoundException() - $this->getServiceNotFoundException() - - $acl['acl'] diff --git a/src/Helper/Navigation/AbstractHelper.php b/src/Helper/Navigation/AbstractHelper.php index e7cb9d5b2..b34699416 100644 --- a/src/Helper/Navigation/AbstractHelper.php +++ b/src/Helper/Navigation/AbstractHelper.php @@ -14,14 +14,12 @@ use Laminas\Navigation\Page\AbstractPage; use Laminas\Permissions\Acl; use Laminas\Permissions\Acl\AclInterface; -use Laminas\ServiceManager\AbstractPluginManager; use Laminas\View; use Laminas\View\Exception; use Laminas\View\Helper\Navigation\Listener\AclListener; use Laminas\View\Helper\TranslatorAwareTrait; use RecursiveIteratorIterator; use ReflectionClass; -use ReflectionProperty; use function call_user_func_array; use function get_class; @@ -30,7 +28,6 @@ use function is_int; use function is_object; use function is_string; -use function method_exists; use function sprintf; use function str_repeat; use function strlen; @@ -101,11 +98,11 @@ abstract class AbstractHelper extends View\Helper\AbstractHtmlElement implements /** * ACL role to use when iterating pages * - * @var string|Acl\Role\RoleInterface + * @var string|Acl\Role\RoleInterface|null */ protected $role; - /** @var ContainerInterface */ + /** @var ContainerInterface|null */ protected $serviceLocator; /** @@ -127,7 +124,7 @@ abstract class AbstractHelper extends View\Helper\AbstractHtmlElement implements * Default ACL role to use when iterating pages if not explicitly set in the * instance by calling {@link setRole()} * - * @var string|Acl\Role\RoleInterface + * @var string|Acl\Role\RoleInterface|null */ protected static $defaultRole; @@ -767,28 +764,6 @@ public function hasRole() */ public function setServiceLocator(ContainerInterface $serviceLocator) { - // If we are provided a plugin manager, we should pull the parent - // context from it. - // @todo We should update tests and code to ensure that this situation - // doesn't happen in the future. - if ( - $serviceLocator instanceof AbstractPluginManager - && ! method_exists($serviceLocator, 'configure') - && $serviceLocator->getServiceLocator() - ) { - $serviceLocator = $serviceLocator->getServiceLocator(); - } - - // v3 variant; likely won't be needed. - if ( - $serviceLocator instanceof AbstractPluginManager - && method_exists($serviceLocator, 'configure') - ) { - $r = new ReflectionProperty($serviceLocator, 'creationContext'); - $r->setAccessible(true); - $serviceLocator = $r->getValue($serviceLocator); - } - $this->serviceLocator = $serviceLocator; return $this; } @@ -798,7 +773,7 @@ public function setServiceLocator(ContainerInterface $serviceLocator) * * Used internally to pull named navigation containers to render. * - * @return ContainerInterface + * @return ContainerInterface|null */ public function getServiceLocator() { diff --git a/src/Helper/Navigation/PluginManager.php b/src/Helper/Navigation/PluginManager.php index f08f8efda..7ed5cf102 100644 --- a/src/Helper/Navigation/PluginManager.php +++ b/src/Helper/Navigation/PluginManager.php @@ -5,7 +5,6 @@ namespace Laminas\View\Helper\Navigation; use Interop\Container\ContainerInterface; -use Laminas\ServiceManager\ConfigInterface; use Laminas\ServiceManager\Factory\InvokableFactory; use Laminas\ServiceManager\ServiceManager; use Laminas\View\HelperPluginManager; @@ -67,20 +66,19 @@ class PluginManager extends HelperPluginManager ]; /** - * @param null|ConfigInterface|ContainerInterface $configOrContainerInstance - * @param array $v3config If $configOrContainerInstance is a container, this - * value will be passed to the parent constructor. + * @param ContainerInterface $configOrContainerInstance + * @param array $v3config * @psalm-param ServiceManagerConfiguration $v3config */ public function __construct($configOrContainerInstance = null, array $v3config = []) { - /** @psalm-suppress MissingClosureParamType */ + /** @psalm-suppress UnusedClosureParam, MissingClosureParamType */ $this->initializers[] = function (ContainerInterface $container, $instance): void { if (! $instance instanceof AbstractHelper) { return; } - $instance->setServiceLocator($container); + $instance->setServiceLocator($this->creationContext); }; parent::__construct($configOrContainerInstance, $v3config); diff --git a/src/Helper/Service/AssetFactory.php b/src/Helper/Service/AssetFactory.php index 0395e6197..c707acc6d 100644 --- a/src/Helper/Service/AssetFactory.php +++ b/src/Helper/Service/AssetFactory.php @@ -11,7 +11,6 @@ use Laminas\View\Helper\Asset; use function is_array; -use function method_exists; class AssetFactory implements FactoryInterface { @@ -23,10 +22,6 @@ class AssetFactory implements FactoryInterface */ public function __invoke(ContainerInterface $container, $name, ?array $options = null) { - // test if we are using Laminas\ServiceManager v2 or v3 - if (! method_exists($container, 'configure')) { - $container = $container->getServiceLocator(); - } $helper = new Asset(); $config = $container->get('config'); diff --git a/src/Helper/Service/FlashMessengerFactory.php b/src/Helper/Service/FlashMessengerFactory.php index bffb9be06..8d605efdf 100644 --- a/src/Helper/Service/FlashMessengerFactory.php +++ b/src/Helper/Service/FlashMessengerFactory.php @@ -9,8 +9,6 @@ use Laminas\ServiceManager\ServiceLocatorInterface; use Laminas\View\Helper\FlashMessenger; -use function method_exists; - class FlashMessengerFactory implements FactoryInterface { /** @@ -22,10 +20,6 @@ class FlashMessengerFactory implements FactoryInterface */ public function __invoke(ContainerInterface $container, $name, ?array $options = null) { - // test if we are using Laminas\ServiceManager v2 or v3 - if (! method_exists($container, 'configure')) { - $container = $container->getServiceLocator(); - } $helper = new FlashMessenger(); $controllerPluginManager = $container->get('ControllerPluginManager'); $flashMessenger = $controllerPluginManager->get('flashmessenger'); diff --git a/src/Helper/Service/IdentityFactory.php b/src/Helper/Service/IdentityFactory.php index c4ad9ef15..9e0e8c296 100644 --- a/src/Helper/Service/IdentityFactory.php +++ b/src/Helper/Service/IdentityFactory.php @@ -11,8 +11,6 @@ use Laminas\ServiceManager\ServiceLocatorInterface; use Laminas\View\Helper\Identity; -use function method_exists; - class IdentityFactory implements FactoryInterface { /** @@ -22,11 +20,6 @@ class IdentityFactory implements FactoryInterface */ public function __invoke(ContainerInterface $container, $name, ?array $options = null) { - // test if we are using Laminas\ServiceManager v2 or v3 - if (! method_exists($container, 'configure')) { - $container = $container->getServiceLocator(); - } - $helper = new Identity(); if (null !== ($authenticationService = $this->discoverAuthenticationService($container))) { diff --git a/test/Helper/Navigation/BreadcrumbsTest.php b/test/Helper/Navigation/BreadcrumbsTest.php index 0e24ecdb9..99ebad415 100644 --- a/test/Helper/Navigation/BreadcrumbsTest.php +++ b/test/Helper/Navigation/BreadcrumbsTest.php @@ -7,7 +7,6 @@ use Laminas\Navigation\Navigation; use Laminas\View\Exception\InvalidArgumentException; use Laminas\View\Helper\Navigation\Breadcrumbs; -use Laminas\View\HelperPluginManager; use function extension_loaded; use function strlen; @@ -69,8 +68,7 @@ public function testHelperEntryPointWithContainerParam(): void public function testHelperEntryPointWithContainerStringParam(): void { - $pm = new HelperPluginManager($this->serviceManager); - $this->_helper->setServiceLocator($pm); + $this->_helper->setServiceLocator($this->serviceManager); $returned = $this->_helper->__invoke('nav1'); $this->assertEquals($this->_helper, $returned); diff --git a/test/Helper/Navigation/LinksTest.php b/test/Helper/Navigation/LinksTest.php index 1e3427213..7ee824f51 100644 --- a/test/Helper/Navigation/LinksTest.php +++ b/test/Helper/Navigation/LinksTest.php @@ -66,8 +66,7 @@ protected function setUp(): void public function testCanRenderFromServiceAlias(): void { - $sm = $this->serviceManager; - $this->_helper->setServiceLocator($sm); + $this->_helper->setServiceLocator($this->serviceManager); $returned = $this->_helper->render('Navigation'); $this->assertEquals($returned, $this->getExpectedFileContents('links/default.html')); diff --git a/test/Helper/Navigation/PluginManagerCompatibilityTest.php b/test/Helper/Navigation/PluginManagerCompatibilityTest.php index dc224661a..f601f3d37 100644 --- a/test/Helper/Navigation/PluginManagerCompatibilityTest.php +++ b/test/Helper/Navigation/PluginManagerCompatibilityTest.php @@ -13,8 +13,6 @@ use Laminas\View\Helper\Navigation\PluginManager; use PHPUnit\Framework\TestCase; -use function method_exists; - /** * @group Laminas_View */ @@ -37,34 +35,6 @@ protected function getInstanceOf(): string return AbstractHelper::class; } - /** - * @group 43 - */ - public function testConstructorArgumentsAreOptionalUnderV2(): void - { - $helpers = $this->getPluginManager(); - if (method_exists($helpers, 'configure')) { - $this->markTestSkipped('laminas-servicemanager v3 plugin managers require a container argument'); - } - - $helpers = new PluginManager(); - $this->assertInstanceOf(PluginManager::class, $helpers); - } - - /** - * @group 43 - */ - public function testConstructorAllowsConfigInstanceAsFirstArgumentUnderV2(): void - { - $helpers = $this->getPluginManager(); - if (method_exists($helpers, 'configure')) { - $this->markTestSkipped('laminas-servicemanager v3 plugin managers require a container argument'); - } - - $helpers = new PluginManager(new Config([])); - $this->assertInstanceOf(PluginManager::class, $helpers); - } - public function testInjectsParentContainerIntoHelpers(): void { $config = new Config([ @@ -81,24 +51,4 @@ public function testInjectsParentContainerIntoHelpers(): void $this->assertInstanceOf(Breadcrumbs::class, $helper); $this->assertSame($services, $helper->getServiceLocator()); } - - /** - * @todo remove this test once we set the minimum laminas-servicemanager version to 3 - */ - public function testRegisteringInvalidElementRaisesException(): void - { - $this->expectException($this->getServiceNotFoundException()); - $this->getPluginManager()->setService('test', $this); - } - - /** - * @todo remove this test once we set the minimum laminas-servicemanager version to 3 - */ - public function testLoadingInvalidElementRaisesException(): void - { - $manager = $this->getPluginManager(); - $manager->setInvokableClass('test', static::class); - $this->expectException($this->getServiceNotFoundException()); - $manager->get('test'); - } } diff --git a/test/HelperPluginManagerTest.php b/test/HelperPluginManagerTest.php index 8eb895c1b..1ac4952c1 100644 --- a/test/HelperPluginManagerTest.php +++ b/test/HelperPluginManagerTest.php @@ -30,40 +30,13 @@ class HelperPluginManagerTest extends TestCase { use ProphecyTrait; - /** @var HelperPluginManager */ - private $helpers; + private HelperPluginManager $helpers; protected function setUp(): void { $this->helpers = new HelperPluginManager(new ServiceManager()); } - /** - * @group 43 - */ - public function testConstructorArgumentsAreOptionalUnderV2(): void - { - if (method_exists($this->helpers, 'configure')) { - $this->markTestSkipped('laminas-servicemanager v3 plugin managers require a container argument'); - } - - $helpers = new HelperPluginManager(); - $this->assertInstanceOf(HelperPluginManager::class, $helpers); - } - - /** - * @group 43 - */ - public function testConstructorAllowsConfigInstanceAsFirstArgumentUnderV2(): void - { - if (method_exists($this->helpers, 'configure')) { - $this->markTestSkipped('laminas-servicemanager v3 plugin managers require a container argument'); - } - - $helpers = new HelperPluginManager(new Config([])); - $this->assertInstanceOf(HelperPluginManager::class, $helpers); - } - public function testViewIsNullByDefault(): void { $this->assertNull($this->helpers->getRenderer()); @@ -185,23 +158,6 @@ public function testIfHelperIsTranslatorAwareAndBothMvcTranslatorAndTranslatorAr $this->assertSame($translator, $helper->getTranslator()); } - /** - * @group 47 - */ - public function testInjectTranslatorWillReturnEarlyIfThePluginManagerDoesNotHaveAParentContainer(): void - { - if (method_exists($this->helpers, 'configure')) { - $this->markTestSkipped( - 'Skip test when testing against laminas-servicemanager v3, as that implementation ' - . 'guarantees a parent container in plugin managers' - ); - } - $helpers = new HelperPluginManager(); - $helper = new HeadTitle(); - $this->assertNull($helpers->injectTranslator($helper, $helpers)); - $this->assertNull($helper->getTranslator()); - } - public function testInjectTranslatorWillReturnEarlyIfTheHelperHasTranslatorAlready(): void { $translatorA = new Translator();