From 8c7543cc60e9df6a847982d0ffb791eee78f0298 Mon Sep 17 00:00:00 2001 From: George Steel Date: Mon, 25 Jul 2022 12:22:21 +0100 Subject: [PATCH 1/6] Bumps minimum version of doctrine annotations to `1.13.3` to solve test failures Doctrine Annotations now converts deprecations to exceptions ref: https://github.com/doctrine/annotations/pull/438 Signed-off-by: George Steel --- composer.json | 2 +- composer.lock | 21 ++++++++--------- test/Annotation/AbstractBuilderTestCase.php | 25 +++++++++++---------- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/composer.json b/composer.json index 0e23e5602..f3022f018 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ }, "require-dev": { "ext-intl": "*", - "doctrine/annotations": "^1.13.2", + "doctrine/annotations": "^1.13.3", "laminas/laminas-captcha": "^2.11.0", "laminas/laminas-coding-standard": "^2.3.0", "laminas/laminas-db": "^2.13.4", diff --git a/composer.lock b/composer.lock index 1d73edf1f..5426d3271 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "963c67ebd2e2fb4c8e185ddbc4ea14b4", + "content-hash": "4f01b05d2599142db421356c57fc6a32", "packages": [ { "name": "container-interop/container-interop", @@ -1312,16 +1312,16 @@ }, { "name": "doctrine/annotations", - "version": "1.13.2", + "version": "1.13.3", "source": { "type": "git", "url": "https://github.com/doctrine/annotations.git", - "reference": "5b668aef16090008790395c02c893b1ba13f7e08" + "reference": "648b0343343565c4a056bfc8392201385e8d89f0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/doctrine/annotations/zipball/5b668aef16090008790395c02c893b1ba13f7e08", - "reference": "5b668aef16090008790395c02c893b1ba13f7e08", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/648b0343343565c4a056bfc8392201385e8d89f0", + "reference": "648b0343343565c4a056bfc8392201385e8d89f0", "shasum": "" }, "require": { @@ -1333,9 +1333,10 @@ "require-dev": { "doctrine/cache": "^1.11 || ^2.0", "doctrine/coding-standard": "^6.0 || ^8.1", - "phpstan/phpstan": "^0.12.20", + "phpstan/phpstan": "^1.4.10 || ^1.8.0", "phpunit/phpunit": "^7.5 || ^8.0 || ^9.1.5", - "symfony/cache": "^4.4 || ^5.2" + "symfony/cache": "^4.4 || ^5.2", + "vimeo/psalm": "^4.10" }, "type": "library", "autoload": { @@ -1378,9 +1379,9 @@ ], "support": { "issues": "https://github.com/doctrine/annotations/issues", - "source": "https://github.com/doctrine/annotations/tree/1.13.2" + "source": "https://github.com/doctrine/annotations/tree/1.13.3" }, - "time": "2021-08-05T19:00:23+00:00" + "time": "2022-07-02T10:48:51+00:00" }, { "name": "doctrine/instantiator", @@ -6188,5 +6189,5 @@ "platform-overrides": { "php": "7.4.99" }, - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.3.0" } diff --git a/test/Annotation/AbstractBuilderTestCase.php b/test/Annotation/AbstractBuilderTestCase.php index b4aeaab17..136d4eaf1 100644 --- a/test/Annotation/AbstractBuilderTestCase.php +++ b/test/Annotation/AbstractBuilderTestCase.php @@ -4,6 +4,7 @@ namespace LaminasTest\Form\Annotation; +use Doctrine\Common\Annotations\AnnotationException; use Generator; use Laminas\Form\Annotation; use Laminas\Form\Element; @@ -406,37 +407,37 @@ public function testInputFilterAnnotationAllowsComposition(): void public function testLegacyComposedObjectAnnotation(): void { - $this->expectDeprecation(); - $this->expectDeprecationMessageMatches('/Passing a single array .* is deprecated/'); + $this->expectException(AnnotationException::class); + $this->expectExceptionMessageMatches('/Passing a single array .* is deprecated/'); $entity = new TestAsset\Annotation\LegacyComposedObjectAnnotation(); $builder = $this->createBuilder(); - $form = $builder->createForm($entity); + $builder->createForm($entity); } public function testLegacyStyleFilterAnnotations(): void { - $this->expectDeprecation(); - $this->expectDeprecationMessageMatches('/Passing a single array .* is deprecated/'); + $this->expectException(AnnotationException::class); + $this->expectExceptionMessageMatches('/Passing a single array .* is deprecated/'); $entity = new TestAsset\Annotation\LegacyFilterAnnotation(); $builder = $this->createBuilder(); - $form = $builder->createForm($entity); + $builder->createForm($entity); } public function testLegacyStyleHydratorAnnotations(): void { - $this->expectDeprecation(); - $this->expectDeprecationMessageMatches('/Passing a single array .* is deprecated/'); + $this->expectException(AnnotationException::class); + $this->expectExceptionMessageMatches('/Passing a single array .* is deprecated/'); $entity = new TestAsset\Annotation\LegacyHydratorAnnotation(); $builder = $this->createBuilder(); - $form = $builder->createForm($entity); + $builder->createForm($entity); } public function testLegacyStyleValidatorAnnotations(): void { - $this->expectDeprecation(); - $this->expectDeprecationMessageMatches('/Passing a single array .* is deprecated/'); + $this->expectException(AnnotationException::class); + $this->expectExceptionMessageMatches('/Passing a single array .* is deprecated/'); $entity = new TestAsset\Annotation\LegacyValidatorAnnotation(); $builder = $this->createBuilder(); - $form = $builder->createForm($entity); + $builder->createForm($entity); } } From c87ce11c3124b969518285eb6ac61a0a1d5ff6af Mon Sep 17 00:00:00 2001 From: George Steel Date: Mon, 25 Jul 2022 17:16:50 +0100 Subject: [PATCH 2/6] Bump inputfilter to fix regression, forcing update of servicemanager Signed-off-by: George Steel --- composer.json | 4 +-- composer.lock | 85 ++++++++++++++++----------------------------------- 2 files changed, 28 insertions(+), 61 deletions(-) diff --git a/composer.json b/composer.json index f3022f018..a8e8bf0bf 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "require": { "php": "^7.4 || ~8.0.0 || ~8.1.0", "laminas/laminas-hydrator": "^4.3.1", - "laminas/laminas-inputfilter": "^2.13.0", + "laminas/laminas-inputfilter": "^2.19.1", "laminas/laminas-stdlib": "^3.7.1" }, "conflict": { @@ -34,7 +34,7 @@ "laminas/laminas-i18n": "^2.14.0", "laminas/laminas-modulemanager": "^2.11.0", "laminas/laminas-recaptcha": "^3.4.0", - "laminas/laminas-servicemanager": "^3.10.0", + "laminas/laminas-servicemanager": "^3.15.1", "laminas/laminas-session": "^2.12.1", "laminas/laminas-text": "^2.9.0", "laminas/laminas-validator": "^2.16.0", diff --git a/composer.lock b/composer.lock index 5426d3271..1b0da38ac 100644 --- a/composer.lock +++ b/composer.lock @@ -4,44 +4,8 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "4f01b05d2599142db421356c57fc6a32", + "content-hash": "947f03491ce796b7b2534403c2477d24", "packages": [ - { - "name": "container-interop/container-interop", - "version": "1.2.0", - "source": { - "type": "git", - "url": "https://github.com/container-interop/container-interop.git", - "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/container-interop/container-interop/zipball/79cbf1341c22ec75643d841642dd5d6acd83bdb8", - "reference": "79cbf1341c22ec75643d841642dd5d6acd83bdb8", - "shasum": "" - }, - "require": { - "psr/container": "^1.0" - }, - "type": "library", - "autoload": { - "psr-4": { - "Interop\\Container\\": "src/Interop/Container/" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "description": "Promoting the interoperability of container objects (DIC, SL, etc.)", - "homepage": "https://github.com/container-interop/container-interop", - "support": { - "issues": "https://github.com/container-interop/container-interop/issues", - "source": "https://github.com/container-interop/container-interop/tree/master" - }, - "abandoned": "psr/container", - "time": "2017-02-14T19:40:03+00:00" - }, { "name": "laminas/laminas-filter", "version": "2.14.0", @@ -200,21 +164,21 @@ }, { "name": "laminas/laminas-inputfilter", - "version": "2.13.0", + "version": "2.19.1", "source": { "type": "git", "url": "https://github.com/laminas/laminas-inputfilter.git", - "reference": "6124b3678051b792d1444be689cf9370531593a6" + "reference": "864a98cd869fc732274e0045eff63f5775d3f107" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-inputfilter/zipball/6124b3678051b792d1444be689cf9370531593a6", - "reference": "6124b3678051b792d1444be689cf9370531593a6", + "url": "https://api.github.com/repos/laminas/laminas-inputfilter/zipball/864a98cd869fc732274e0045eff63f5775d3f107", + "reference": "864a98cd869fc732274e0045eff63f5775d3f107", "shasum": "" }, "require": { "laminas/laminas-filter": "^2.13", - "laminas/laminas-servicemanager": "^3.3.1", + "laminas/laminas-servicemanager": "^3.12.0", "laminas/laminas-stdlib": "^3.0", "laminas/laminas-validator": "^2.15", "php": "^7.4 || ~8.0.0 || ~8.1.0" @@ -223,14 +187,12 @@ "zendframework/zend-inputfilter": "*" }, "require-dev": { - "laminas/laminas-coding-standard": "~2.2.1", + "laminas/laminas-coding-standard": "~2.3.0", "laminas/laminas-db": "^2.13.4", - "phpspec/prophecy": "^1.14", - "phpspec/prophecy-phpunit": "^2.0", - "phpunit/phpunit": "^9.5.5", - "psalm/plugin-phpunit": "^0.15.1", + "phpunit/phpunit": "^9.5.21", + "psalm/plugin-phpunit": "^0.17.0", "psr/http-message": "^1.0", - "vimeo/psalm": "^4.6" + "vimeo/psalm": "^4.24.0" }, "suggest": { "psr/http-message-implementation": "PSR-7 is required if you wish to validate PSR-7 UploadedFileInterface payloads" @@ -271,48 +233,50 @@ "type": "community_bridge" } ], - "time": "2021-12-02T14:46:43+00:00" + "time": "2022-07-25T15:08:16+00:00" }, { "name": "laminas/laminas-servicemanager", - "version": "3.10.0", + "version": "3.15.1", "source": { "type": "git", "url": "https://github.com/laminas/laminas-servicemanager.git", - "reference": "e52b985909e0940bf22d34f322eb3f48bbef6bd1" + "reference": "216f972b179191b14c33a79337947b63bf7808ff" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laminas/laminas-servicemanager/zipball/e52b985909e0940bf22d34f322eb3f48bbef6bd1", - "reference": "e52b985909e0940bf22d34f322eb3f48bbef6bd1", + "url": "https://api.github.com/repos/laminas/laminas-servicemanager/zipball/216f972b179191b14c33a79337947b63bf7808ff", + "reference": "216f972b179191b14c33a79337947b63bf7808ff", "shasum": "" }, "require": { - "container-interop/container-interop": "^1.2", "laminas/laminas-stdlib": "^3.2.1", "php": "~7.4.0 || ~8.0.0 || ~8.1.0", "psr/container": "^1.0" }, "conflict": { + "ext-psr": "*", "laminas/laminas-code": "<3.3.1", "zendframework/zend-code": "<3.3.1", "zendframework/zend-servicemanager": "*" }, "provide": { - "container-interop/container-interop-implementation": "^1.2", "psr/container-implementation": "^1.0" }, + "replace": { + "container-interop/container-interop": "^1.2.0" + }, "require-dev": { "composer/package-versions-deprecated": "^1.0", - "laminas/laminas-coding-standard": "~2.2.1", - "laminas/laminas-container-config-test": "^0.3", + "laminas/laminas-coding-standard": "~2.3.0", + "laminas/laminas-container-config-test": "^0.6", "laminas/laminas-dependency-plugin": "^2.1.2", "mikey179/vfsstream": "^1.6.10@alpha", "ocramius/proxy-manager": "^2.11", "phpbench/phpbench": "^1.1", "phpspec/prophecy-phpunit": "^2.0", "phpunit/phpunit": "^9.5.5", - "psalm/plugin-phpunit": "^0.16.1", + "psalm/plugin-phpunit": "^0.17.0", "vimeo/psalm": "^4.8" }, "suggest": { @@ -324,6 +288,9 @@ ], "type": "library", "autoload": { + "files": [ + "src/autoload.php" + ], "psr-4": { "Laminas\\ServiceManager\\": "src/" } @@ -357,7 +324,7 @@ "type": "community_bridge" } ], - "time": "2021-09-18T20:19:36+00:00" + "time": "2022-07-20T09:48:45+00:00" }, { "name": "laminas/laminas-stdlib", From d1bf971b8c1f79595c2d4157b32dddcca75837ff Mon Sep 17 00:00:00 2001 From: George Steel Date: Mon, 25 Jul 2022 17:18:07 +0100 Subject: [PATCH 3/6] Suppress phpcs issues with aliased Interop\Container class name Signed-off-by: George Steel --- phpcs.xml | 4 ++-- src/Annotation/BuilderAbstractFactory.php | 2 +- src/ElementFactory.php | 2 +- src/FormAbstractServiceFactory.php | 3 ++- src/FormElementManager.php | 2 +- src/FormElementManagerFactory.php | 2 +- test/Annotation/BuilderAbstractFactoryTest.php | 2 +- test/ElementFactoryTest.php | 2 +- test/FormElementManagerFactoryTest.php | 2 +- test/TestAsset/CustomCreatedFormFactory.php | 2 +- test/TestAsset/FieldsetWithDependencyFactory.php | 2 +- 11 files changed, 13 insertions(+), 12 deletions(-) diff --git a/phpcs.xml b/phpcs.xml index f190969c8..b372225a3 100644 --- a/phpcs.xml +++ b/phpcs.xml @@ -9,7 +9,7 @@ - + src @@ -17,4 +17,4 @@ - \ No newline at end of file + diff --git a/src/Annotation/BuilderAbstractFactory.php b/src/Annotation/BuilderAbstractFactory.php index 7c3f0609a..cd228fd2c 100644 --- a/src/Annotation/BuilderAbstractFactory.php +++ b/src/Annotation/BuilderAbstractFactory.php @@ -4,7 +4,7 @@ namespace Laminas\Form\Annotation; -use Interop\Container\ContainerInterface; +use Interop\Container\ContainerInterface; // phpcs:disable WebimpressCodingStandard.PHP.CorrectClassNameCase use Laminas\EventManager\EventManagerInterface; use Laminas\EventManager\ListenerAggregateInterface; use Laminas\Form\Factory; diff --git a/src/ElementFactory.php b/src/ElementFactory.php index 0a073c145..09406cd63 100644 --- a/src/ElementFactory.php +++ b/src/ElementFactory.php @@ -4,7 +4,7 @@ namespace Laminas\Form; -use Interop\Container\ContainerInterface; +use Interop\Container\ContainerInterface; // phpcs:disable WebimpressCodingStandard.PHP.CorrectClassNameCase use Laminas\ServiceManager\Factory\FactoryInterface; use function array_pop; diff --git a/src/FormAbstractServiceFactory.php b/src/FormAbstractServiceFactory.php index 4e34301e1..5b31e17b8 100644 --- a/src/FormAbstractServiceFactory.php +++ b/src/FormAbstractServiceFactory.php @@ -4,7 +4,8 @@ namespace Laminas\Form; -use Interop\Container\ContainerInterface; +use Interop\Container\ContainerInterface; // phpcs:disable WebimpressCodingStandard.PHP.CorrectClassNameCase +use Laminas\Filter\FilterPluginManager; use Laminas\InputFilter\InputFilterInterface; use Laminas\ServiceManager\Factory\AbstractFactoryInterface; diff --git a/src/FormElementManager.php b/src/FormElementManager.php index 23e49f19d..11a2cceac 100644 --- a/src/FormElementManager.php +++ b/src/FormElementManager.php @@ -4,7 +4,7 @@ namespace Laminas\Form; -use Interop\Container\ContainerInterface; +use Interop\Container\ContainerInterface; // phpcs:disable WebimpressCodingStandard.PHP.CorrectClassNameCase use Laminas\Form\Exception; use Laminas\ServiceManager\AbstractPluginManager; use Laminas\ServiceManager\Exception\InvalidServiceException; diff --git a/src/FormElementManagerFactory.php b/src/FormElementManagerFactory.php index 4ebefb61d..f40001360 100644 --- a/src/FormElementManagerFactory.php +++ b/src/FormElementManagerFactory.php @@ -4,7 +4,7 @@ namespace Laminas\Form; -use Interop\Container\ContainerInterface; +use Interop\Container\ContainerInterface; // phpcs:disable WebimpressCodingStandard.PHP.CorrectClassNameCase use Laminas\ServiceManager\AbstractPluginManager; use Laminas\ServiceManager\Config; use Laminas\ServiceManager\Factory\FactoryInterface; diff --git a/test/Annotation/BuilderAbstractFactoryTest.php b/test/Annotation/BuilderAbstractFactoryTest.php index 4788bde70..7c055d7a6 100644 --- a/test/Annotation/BuilderAbstractFactoryTest.php +++ b/test/Annotation/BuilderAbstractFactoryTest.php @@ -4,7 +4,7 @@ namespace LaminasTest\Form\Annotation; -use Interop\Container\ContainerInterface; +use Interop\Container\ContainerInterface; // phpcs:disable WebimpressCodingStandard.PHP.CorrectClassNameCase use Laminas\EventManager\EventManagerInterface; use Laminas\EventManager\ListenerAggregateInterface; use Laminas\Form\Annotation\AnnotationBuilder; diff --git a/test/ElementFactoryTest.php b/test/ElementFactoryTest.php index a1c06e71a..46507f555 100644 --- a/test/ElementFactoryTest.php +++ b/test/ElementFactoryTest.php @@ -5,7 +5,7 @@ namespace LaminasTest\Form; use Generator; -use Interop\Container\ContainerInterface; +use Interop\Container\ContainerInterface; // phpcs:disable WebimpressCodingStandard.PHP.CorrectClassNameCase use Laminas\Form\ElementFactory; use Laminas\ServiceManager\ServiceLocatorInterface; use LaminasTest\Form\TestAsset\ArgumentRecorder; diff --git a/test/FormElementManagerFactoryTest.php b/test/FormElementManagerFactoryTest.php index bfb15b658..01df6f036 100644 --- a/test/FormElementManagerFactoryTest.php +++ b/test/FormElementManagerFactoryTest.php @@ -4,7 +4,7 @@ namespace LaminasTest\Form; -use Interop\Container\ContainerInterface; +use Interop\Container\ContainerInterface; // phpcs:disable WebimpressCodingStandard.PHP.CorrectClassNameCase use Laminas\Form\Element\Number; use Laminas\Form\ElementInterface; use Laminas\Form\FormElementManager; diff --git a/test/TestAsset/CustomCreatedFormFactory.php b/test/TestAsset/CustomCreatedFormFactory.php index 65874d589..9fd8702ff 100644 --- a/test/TestAsset/CustomCreatedFormFactory.php +++ b/test/TestAsset/CustomCreatedFormFactory.php @@ -5,7 +5,7 @@ namespace LaminasTest\Form\TestAsset; use DateTime; -use Interop\Container\ContainerInterface; +use Interop\Container\ContainerInterface; // phpcs:disable WebimpressCodingStandard.PHP.CorrectClassNameCase use Laminas\ServiceManager\Factory\FactoryInterface; class CustomCreatedFormFactory implements FactoryInterface diff --git a/test/TestAsset/FieldsetWithDependencyFactory.php b/test/TestAsset/FieldsetWithDependencyFactory.php index fd77c5be1..44166b81e 100644 --- a/test/TestAsset/FieldsetWithDependencyFactory.php +++ b/test/TestAsset/FieldsetWithDependencyFactory.php @@ -4,7 +4,7 @@ namespace LaminasTest\Form\TestAsset; -use Interop\Container\ContainerInterface; +use Interop\Container\ContainerInterface; // phpcs:disable WebimpressCodingStandard.PHP.CorrectClassNameCase use Laminas\ServiceManager\Factory\FactoryInterface; class FieldsetWithDependencyFactory implements FactoryInterface From e7ac0b460fcaf7f810c3e46e297cf8ae393772b5 Mon Sep 17 00:00:00 2001 From: George Steel Date: Mon, 25 Jul 2022 17:21:31 +0100 Subject: [PATCH 4/6] Use FQCNs for plugin managers, hydrators and input filters, this lines up with the service names used in input filter and improves type inference Signed-off-by: George Steel --- src/FormAbstractServiceFactory.php | 18 +++++++++++------ test/FormAbstractServiceFactoryTest.php | 26 ++++++++++++------------- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/FormAbstractServiceFactory.php b/src/FormAbstractServiceFactory.php index 5b31e17b8..ec7f90b73 100644 --- a/src/FormAbstractServiceFactory.php +++ b/src/FormAbstractServiceFactory.php @@ -7,7 +7,9 @@ use Interop\Container\ContainerInterface; // phpcs:disable WebimpressCodingStandard.PHP.CorrectClassNameCase use Laminas\Filter\FilterPluginManager; use Laminas\InputFilter\InputFilterInterface; +use Laminas\InputFilter\InputFilterPluginManager; use Laminas\ServiceManager\Factory\AbstractFactoryInterface; +use Laminas\Validator\ValidatorPluginManager; use function is_array; use function is_string; @@ -102,8 +104,8 @@ protected function getFormFactory(ContainerInterface $container): Factory } $elements = null; - if ($container->has('FormElementManager')) { - $elements = $container->get('FormElementManager'); + if ($container->has(FormElementManager::class)) { + $elements = $container->get(FormElementManager::class); } $this->factory = new Factory($elements); @@ -133,9 +135,9 @@ protected function marshalInputFilter(array &$config, ContainerInterface $contai if ( is_string($config['input_filter']) - && $container->has('InputFilterManager') + && $container->has(InputFilterPluginManager::class) ) { - $inputFilters = $container->get('InputFilterManager'); + $inputFilters = $container->get(InputFilterPluginManager::class); if ($inputFilters->has($config['input_filter'])) { $config['input_filter'] = $inputFilters->get($config['input_filter']); return; @@ -143,7 +145,11 @@ protected function marshalInputFilter(array &$config, ContainerInterface $contai } $inputFilterFactory = $formFactory->getInputFilterFactory(); - $inputFilterFactory->getDefaultFilterChain()->setPluginManager($container->get('FilterManager')); - $inputFilterFactory->getDefaultValidatorChain()->setPluginManager($container->get('ValidatorManager')); + $inputFilterFactory->getDefaultFilterChain()->setPluginManager( + $container->get(FilterPluginManager::class) + ); + $inputFilterFactory->getDefaultValidatorChain()->setPluginManager( + $container->get(ValidatorPluginManager::class) + ); } } diff --git a/test/FormAbstractServiceFactoryTest.php b/test/FormAbstractServiceFactoryTest.php index 331c6eea0..a401a0568 100644 --- a/test/FormAbstractServiceFactoryTest.php +++ b/test/FormAbstractServiceFactoryTest.php @@ -34,13 +34,11 @@ protected function setUp(): void $inputFilters = new InputFilterPluginManager($services); $validators = new ValidatorPluginManager($services); - $services->setService('FilterManager', $filters); - $services->setService('FormElementManager', $elements); - $services->setService('HydratorManager', $hydrators); - $services->setService('InputFilterManager', $inputFilters); - $services->setService('ValidatorManager', $validators); - - $inputFilters->setInvokableClass('FooInputFilter', InputFilter::class); + $services->setService(FilterPluginManager::class, $filters); + $services->setService(FormElementManager::class, $elements); + $services->setService(HydratorPluginManager::class, $hydrators); + $services->setService(InputFilterPluginManager::class, $inputFilters); + $services->setService(ValidatorPluginManager::class, $validators); $forms = $this->forms = new FormAbstractServiceFactory(); $services->addAbstractFactory($forms); @@ -121,7 +119,7 @@ public function testPopulatedFormConfigIndicatesFormCanBeCreated(): void public function testFormCanBeCreatedViaInteractionOfAllManagers(): void { $formConfig = [ - 'hydrator' => 'ObjectPropertyHydrator', + 'hydrator' => ObjectPropertyHydrator::class, 'type' => Form::class, 'elements' => [ [ @@ -134,7 +132,7 @@ public function testFormCanBeCreatedViaInteractionOfAllManagers(): void ], ], ], - 'input_filter' => 'FooInputFilter', + 'input_filter' => InputFilter::class, ]; $config = ['forms' => ['Foo' => $formConfig]]; $this->services->setService('config', $config); @@ -149,8 +147,8 @@ public function testFormCanBeCreatedViaInteractionOfAllManagers(): void $inputFactory = $inputFilter->getFactory(); $this->assertInstanceOf(Factory::class, $inputFactory); - $filters = $this->services->get('FilterManager'); - $validators = $this->services->get('ValidatorManager'); + $filters = $this->services->get(FilterPluginManager::class); + $validators = $this->services->get(ValidatorPluginManager::class); $this->assertSame($filters, $inputFactory->getDefaultFilterChain()->getPluginManager()); $this->assertSame($validators, $inputFactory->getDefaultValidatorChain()->getPluginManager()); } @@ -158,7 +156,7 @@ public function testFormCanBeCreatedViaInteractionOfAllManagers(): void public function testFormCanBeCreatedViaInteractionOfAllManagersExceptInputFilterManager(): void { $formConfig = [ - 'hydrator' => 'ObjectPropertyHydrator', + 'hydrator' => ObjectPropertyHydrator::class, 'type' => Form::class, 'elements' => [ [ @@ -199,8 +197,8 @@ public function testFormCanBeCreatedViaInteractionOfAllManagersExceptInputFilter $this->assertInstanceOf(InputFilter::class, $inputFilter); $inputFactory = $inputFilter->getFactory(); - $filters = $this->services->get('FilterManager'); - $validators = $this->services->get('ValidatorManager'); + $filters = $this->services->get(FilterPluginManager::class); + $validators = $this->services->get(ValidatorPluginManager::class); $this->assertSame($filters, $inputFactory->getDefaultFilterChain()->getPluginManager()); $this->assertSame($validators, $inputFactory->getDefaultValidatorChain()->getPluginManager()); } From 9c1bfa16647538339264a4078608bef986fb8ee9 Mon Sep 17 00:00:00 2001 From: George Steel Date: Mon, 25 Jul 2022 17:22:26 +0100 Subject: [PATCH 5/6] Baseline complaints of less specific return types for `getInputFilterSpecification` - a psalm type will need to be imported here from `inputfilter` Signed-off-by: George Steel --- psalm-baseline.xml | 154 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 139 insertions(+), 15 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index cadb69a26..84cd1e805 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -26,11 +26,6 @@ getAttributes - - - Attribute - - new $requestedName() @@ -76,14 +71,27 @@ $this + + + array + + gettype($captcha) + + array + is_object($captcha) + + + array + + $this->object instanceof Traversable @@ -113,7 +121,50 @@ bindValues + + + array + + + + + array + + + + + array + + + + + array + + + + + array + + + + + array + + + + + array + + + + + array + + + + array + $value @@ -121,6 +172,16 @@ static function ($value) use ($unselectedValue) { + + + array + + + + + array + + new $requestedName($name, $options) @@ -173,15 +234,19 @@ $childFieldset $filter + + $spec + $this $this $this - + $collectionInputFilter->get($name) $input $inputFilter + $spec $this->data @@ -491,10 +556,10 @@ $form - - - Annotation\AllowEmpty() - + + + array + @@ -506,11 +571,25 @@ $username - - - Annotation\AllowEmpty(true) - Annotation\ContinueIfEmpty(true) - + + + array + + + + + array + + + + + array + + + + + array + @@ -529,6 +608,16 @@ $this->view + + + array + + + + + array + + $name @@ -538,7 +627,15 @@ $dependency + + + array[] + + + + array[] + $name $options @@ -551,29 +648,56 @@ + + array[] + $name $options + + array[] + $name $options + + array[] + $name $options + + + array[] + + + + + array + + + + array[] + $name $options + + + array + + $storedValue From 676614172bfbfd1d1984a45f4b8b7c0685bb6aa9 Mon Sep 17 00:00:00 2001 From: George Steel Date: Mon, 25 Jul 2022 17:34:25 +0100 Subject: [PATCH 6/6] Removes expected error type and validate only the message Signed-off-by: George Steel --- test/Annotation/AbstractBuilderTestCase.php | 54 +++++++++++++-------- 1 file changed, 33 insertions(+), 21 deletions(-) diff --git a/test/Annotation/AbstractBuilderTestCase.php b/test/Annotation/AbstractBuilderTestCase.php index 136d4eaf1..0758eb407 100644 --- a/test/Annotation/AbstractBuilderTestCase.php +++ b/test/Annotation/AbstractBuilderTestCase.php @@ -4,7 +4,6 @@ namespace LaminasTest\Form\Annotation; -use Doctrine\Common\Annotations\AnnotationException; use Generator; use Laminas\Form\Annotation; use Laminas\Form\Element; @@ -23,6 +22,7 @@ use LaminasTest\Form\TestAsset\Annotation\InputFilter; use LaminasTest\Form\TestAsset\Annotation\InputFilterInput; use PHPUnit\Framework\TestCase; +use Throwable; use function getenv; @@ -407,37 +407,49 @@ public function testInputFilterAnnotationAllowsComposition(): void public function testLegacyComposedObjectAnnotation(): void { - $this->expectException(AnnotationException::class); - $this->expectExceptionMessageMatches('/Passing a single array .* is deprecated/'); - $entity = new TestAsset\Annotation\LegacyComposedObjectAnnotation(); - $builder = $this->createBuilder(); - $builder->createForm($entity); + try { + $entity = new TestAsset\Annotation\LegacyComposedObjectAnnotation(); + $builder = $this->createBuilder(); + $builder->createForm($entity); + self::fail('Neither a deprecation nor an exception were thrown'); + } catch (Throwable $error) { + self::assertMatchesRegularExpression('/Passing a single array .* is deprecated/', $error->getMessage()); + } } public function testLegacyStyleFilterAnnotations(): void { - $this->expectException(AnnotationException::class); - $this->expectExceptionMessageMatches('/Passing a single array .* is deprecated/'); - $entity = new TestAsset\Annotation\LegacyFilterAnnotation(); - $builder = $this->createBuilder(); - $builder->createForm($entity); + try { + $entity = new TestAsset\Annotation\LegacyFilterAnnotation(); + $builder = $this->createBuilder(); + $builder->createForm($entity); + self::fail('Neither a deprecation nor an exception were thrown'); + } catch (Throwable $error) { + self::assertMatchesRegularExpression('/Passing a single array .* is deprecated/', $error->getMessage()); + } } public function testLegacyStyleHydratorAnnotations(): void { - $this->expectException(AnnotationException::class); - $this->expectExceptionMessageMatches('/Passing a single array .* is deprecated/'); - $entity = new TestAsset\Annotation\LegacyHydratorAnnotation(); - $builder = $this->createBuilder(); - $builder->createForm($entity); + try { + $entity = new TestAsset\Annotation\LegacyHydratorAnnotation(); + $builder = $this->createBuilder(); + $builder->createForm($entity); + self::fail('Neither a deprecation nor an exception were thrown'); + } catch (Throwable $error) { + self::assertMatchesRegularExpression('/Passing a single array .* is deprecated/', $error->getMessage()); + } } public function testLegacyStyleValidatorAnnotations(): void { - $this->expectException(AnnotationException::class); - $this->expectExceptionMessageMatches('/Passing a single array .* is deprecated/'); - $entity = new TestAsset\Annotation\LegacyValidatorAnnotation(); - $builder = $this->createBuilder(); - $builder->createForm($entity); + try { + $entity = new TestAsset\Annotation\LegacyValidatorAnnotation(); + $builder = $this->createBuilder(); + $builder->createForm($entity); + self::fail('Neither a deprecation nor an exception were thrown'); + } catch (Throwable $error) { + self::assertMatchesRegularExpression('/Passing a single array .* is deprecated/', $error->getMessage()); + } } }