diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index 6a0941d..278056d 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -8,7 +8,7 @@ jobs: strategy: matrix: - php-versions: ['7.3', '7.4', '8.0'] + php-versions: ['8.1', '8.2'] name: PHP ${{ matrix.php-versions }} steps: - uses: actions/checkout@v2 diff --git a/composer.json b/composer.json index c1e632d..c25f23c 100644 --- a/composer.json +++ b/composer.json @@ -5,28 +5,23 @@ "license": "MIT", "minimum-stability": "stable", "require": { - "php": "^7.3|^8.0", + "php": "^8.1", "hostnet/form-handler-component": "^1.7.3", - "symfony/expression-language": "^4.0|^5.0|^6.0", - "symfony/http-foundation": "^4.0|^5.0|^6.0" + "symfony/expression-language": "^6.4|^7.0", + "symfony/http-foundation": "^6.4|^7.0" }, "require-dev": { - "doctrine/annotations": "^1.0", "hostnet/phpcs-tool": "^9.1.0", "phpunit/phpunit": "^9.5.5", - "sensio/framework-extra-bundle": "3.*|^5.0|^6.0", - "symfony/browser-kit": "^4.0|^5.0|^6.0", - "symfony/finder": "^4.0|^5.0|^6.0", - "symfony/form": "^4.0|^5.0|^6.0", - "symfony/framework-bundle": "^4.0|^5.0|^6.0", - "symfony/http-kernel": "^4.0|^5.0|^6.0", - "symfony/phpunit-bridge": "^2.8|^3.0|^4.0|^5.0|^6.0", - "symfony/translation": "^4.0|^5.0|^6.0", - "symfony/validator": "^4.0|^5.0|^6.0", - "symfony/yaml": "^4.0|^5.0|^6.0" - }, - "suggest": { - "sensio/framework-extra-bundle": "To utilize form param converter." + "symfony/browser-kit": "^6.4|^7.0", + "symfony/finder": "^6.4|^7.0", + "symfony/form": "^6.4|^7.0", + "symfony/framework-bundle": "^6.4|^7.0", + "symfony/http-kernel": "^6.4|^7.0", + "symfony/phpunit-bridge": "^6.4|^7.0", + "symfony/translation": "^6.4|^7.0", + "symfony/validator": "^6.4|^7.0", + "symfony/yaml": "^6.4|^7.0" }, "autoload": { "psr-4": { diff --git a/src/DependencyInjection/Compiler/FormHandlerRegistryCompilerPass.php b/src/DependencyInjection/Compiler/FormHandlerRegistryCompilerPass.php deleted file mode 100644 index 02e443a..0000000 --- a/src/DependencyInjection/Compiler/FormHandlerRegistryCompilerPass.php +++ /dev/null @@ -1,48 +0,0 @@ -hasDefinition('form_handler.param_converter') - ) { - $register_with_param_converter = true; - } - - $tagged_services = array_keys($container->findTaggedServiceIds('form.handler')); - $handlers = []; - $legacy_handlers = []; - - foreach ($tagged_services as $id) { - $class = $container->getDefinition($id)->setPublic(true)->getClass(); - $handlers[] = [$id, $class]; - - if ($register_with_param_converter && is_subclass_of($class, FormHandlerInterface::class)) { - $legacy_handlers[$id] = $class; - } - } - - // Add handlers to registry - $container->getDefinition('hostnet.form_handler.registry')->replaceArgument(1, $handlers); - - if (count($legacy_handlers) > 0) { - $container->getDefinition('form_handler.param_converter')->replaceArgument(1, $legacy_handlers); - } - } -} diff --git a/src/FormHandlerBundle.php b/src/FormHandlerBundle.php deleted file mode 100644 index b4da557..0000000 --- a/src/FormHandlerBundle.php +++ /dev/null @@ -1,32 +0,0 @@ -load('services.yaml'); parent::build($container); - $container->addCompilerPass(new FormHandlerRegistryCompilerPass()); - - // If auto configuring is available, register tags for the Handler Types. - if (method_exists($container, 'registerForAutoconfiguration')) { - $container->registerForAutoconfiguration(FormHandlerInterface::class)->addTag('form.handler'); - $container->registerForAutoconfiguration(HandlerTypeInterface::class)->addTag('form.handler'); - } + $container->registerForAutoconfiguration(FormHandlerInterface::class)->addTag('form.handler'); + $container->registerForAutoconfiguration(HandlerTypeInterface::class)->addTag('form.handler'); } } diff --git a/src/ParamConverter/FormParamConverter.php b/src/ParamConverter/FormParamConverter.php deleted file mode 100644 index ac14a32..0000000 --- a/src/ParamConverter/FormParamConverter.php +++ /dev/null @@ -1,101 +0,0 @@ - $class] - */ - public function __construct(ContainerInterface $container, array $handlers = []) - { - $this->container = $container; - $this->handlers = $handlers; - } - - /** - * @param string $service_id - * @param string $class - */ - public function addFormClass($service_id, $class) - { - @trigger_error(sprintf( - 'Calling %s is deprecated as of 1.6 and will be removed in 2.0. Use the constructor argument instead.', - __METHOD__ - ), E_USER_DEPRECATED); - $this->handlers[$service_id] = $class; - } - - /** - * {@inheritdoc} - */ - public function apply(Request $request, ParamConverter $configuration) - { - $options = $configuration->getOptions(); - $service_id = $options['service_id'] ?? $this->getServiceIdForClassName($configuration); - $handler = $this->container->get($service_id); - $class = $this->handlers[$service_id]; - - if (!$handler instanceof FormHandlerInterface || get_class($handler) !== $class) { - return; - } - - $request->attributes->set($configuration->getName(), $handler); - } - - /** - * {@inheritdoc} - */ - public function supports(ParamConverter $configuration) - { - return in_array($configuration->getClass(), $this->handlers, true); - } - - /** - * @param ParamConverter $configuration - * @return string - */ - private function getServiceIdForClassName(ParamConverter $configuration) - { - $service_ids = []; - $class = $configuration->getClass(); - foreach ($this->handlers as $service_id => $service_class) { - if ($class === $service_class) { - $service_ids[] = $service_id; - } - } - if (count($service_ids) === 0) { - throw new \InvalidArgumentException( - sprintf('No service_id found for parameter converter %s.', $configuration->getName()) - ); - } - if (count($service_ids) > 1) { - throw new \InvalidArgumentException( - sprintf('More than one service_id found for parameter converter %s.', $configuration->getName()) - ); - } - - return $service_ids[0]; - } -} diff --git a/src/Registry/LegacyHandlerRegistry.php b/src/Registry/LegacyHandlerRegistry.php index f6d4211..4743ca1 100644 --- a/src/Registry/LegacyHandlerRegistry.php +++ b/src/Registry/LegacyHandlerRegistry.php @@ -10,6 +10,7 @@ use Hostnet\Component\FormHandler\Exception\InvalidHandlerTypeException; use Hostnet\Component\FormHandler\HandlerRegistryInterface; use Hostnet\Component\FormHandler\HandlerTypeAdapter; +use Hostnet\Component\FormHandler\HandlerTypeInterface; use Symfony\Component\DependencyInjection\ContainerInterface; final class LegacyHandlerRegistry implements HandlerRegistryInterface @@ -20,11 +21,11 @@ final class LegacyHandlerRegistry implements HandlerRegistryInterface private $container; /** - * @var array[] + * @var HandlerTypeInterface[] */ - private $handlers; + private iterable $handlers; - public function __construct(ContainerInterface $container, array $handlers) + public function __construct(ContainerInterface $container, iterable $handlers) { $this->handlers = $handlers; $this->container = $container; @@ -35,13 +36,11 @@ public function __construct(ContainerInterface $container, array $handlers) */ public function getType($class) { - foreach ($this->handlers as list($service_id, $handler_class)) { - if ($handler_class !== $class) { + foreach ($this->handlers as $handler) { + if ($handler::class !== $class) { continue; } - $handler = $this->container->get($service_id); - if ($handler instanceof FormHandlerInterface) { return new HandlerTypeAdapter($handler); } diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index 0e3cdda..e89b001 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -1,12 +1,4 @@ services: - form_handler.param_converter: - class: Hostnet\Bundle\FormHandlerBundle\ParamConverter\FormParamConverter - arguments: - - "@service_container" - - [] # inject from the compiler pass - tags: - - { name: request.param_converter, converter: form_information_converter } - form_handler.provider.simple: class: Hostnet\Component\Form\Simple\SimpleFormProvider arguments: @@ -16,7 +8,7 @@ services: class: Hostnet\Bundle\FormHandlerBundle\Registry\LegacyHandlerRegistry arguments: - "@service_container" - - [] # injected from the compiler pass + - !tagged_iterator form.handler hostnet.form_handler.factory: class: Hostnet\Component\FormHandler\HandlerFactory @@ -24,9 +16,5 @@ services: - "@form.factory" - "@hostnet.form_handler.registry" - Hostnet\Bundle\FormHandlerBundle\ParamConverter\FormParamConverter: '@form_handler.param_converter' - Hostnet\Bundle\FormHandlerBundle\Registry\LegacyHandlerRegistry: '@hostnet.form_handler.registry' Hostnet\Component\Form\FormProviderInterface: '@form_handler.provider.simple' - Hostnet\Component\Form\Simple\SimpleFormProvider: '@form_handler.provider.simple' - Hostnet\Component\FormHandler\HandlerFactory: '@hostnet.form_handler.factory' Hostnet\Component\FormHandler\HandlerFactoryInterface: '@hostnet.form_handler.factory' diff --git a/test/DependencyInjection/FormHandlerRegistryCompilerPassTest.php b/test/DependencyInjection/FormHandlerRegistryCompilerPassTest.php deleted file mode 100644 index d7d9539..0000000 --- a/test/DependencyInjection/FormHandlerRegistryCompilerPassTest.php +++ /dev/null @@ -1,59 +0,0 @@ -markTestSkipped( - 'Sensio Extra bundle is not installed.' - ); - } - } - - /** - * @dataProvider processDataProvider - */ - public function testProcess($service_name, $tagged_services): void - { - $container = new ContainerBuilder(); - $container->setDefinition($service_name, new Definition()); - $container->setDefinition('hostnet.form_handler.registry', new Definition(null, [null, null])); - - foreach ($tagged_services as $id => $tag) { - $container->register($id)->addTag($tag, ['tests']); - } - - $pass = new FormHandlerRegistryCompilerPass(); - $pass->process($container); - - self::assertCount( - \count($tagged_services), - $container->getDefinition('hostnet.form_handler.registry')->getArgument(1) - ); - } - - public function processDataProvider(): iterable - { - return [ - ['form_handler.param_converter', []], - [FormParamConverter::class, []], - ['form_handler.param_converter', ['test.service' => 'form.handler', 'test.phpunit' => 'form.handler']], - [FormParamConverter::class, ['test.service' => 'form.handler', 'test.phpunit' => 'form.handler']], - ]; - } -} diff --git a/test/FormHandlerBundleTest.php b/test/FormHandlerBundleTest.php deleted file mode 100644 index 67dfca1..0000000 --- a/test/FormHandlerBundleTest.php +++ /dev/null @@ -1,36 +0,0 @@ -assertTrue($bundle instanceof HostnetFormHandlerBundle); - } - - /** - * @group legacy - * @expectedDeprecation The %s is deprecated. Use %s instead. - */ - public function testIsDeprecated(): void - { - $container = new ContainerBuilder(); - $bundle = new FormHandlerBundle(); - - $bundle->build($container); - } -} diff --git a/test/Functional/AutoconfigureTest.php b/test/Functional/AutoconfigureTest.php index 10acf59..943392e 100644 --- a/test/Functional/AutoconfigureTest.php +++ b/test/Functional/AutoconfigureTest.php @@ -7,22 +7,17 @@ namespace Hostnet\Bundle\FormHandlerBundle\Functional; use Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\FullFormHandler; -use Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\Legacy\LegacyFormHandler; use Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\TestData; use Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\TestKernel; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; -use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\HttpKernel\KernelInterface; class AutoconfigureTest extends KernelTestCase { protected function setUp(): void { - if (Kernel::VERSION_ID < 30300) { - self::markTestSkipped(sprintf('Symfony version %s not supported by test', Kernel::VERSION)); - } static::bootKernel(['config_file' => 'autoconfigure.yml']); } @@ -45,23 +40,4 @@ public function testHandlerType(): void self::assertInstanceOf(RedirectResponse::class, $response); self::assertEquals('http://success.nl/', $response->getTargetUrl()); } - - /** - * @group legacy - * @expectedDeprecation Using %s is deprecated, use Hostnet\Component\FormHandler\HandlerTypeInterface instead. - */ - public function testFormHandler(): void - { - $container = self::$kernel->getContainer(); - $handler_factory = $container->get('hostnet.form_handler.factory'); - $request = Request::create('/', 'POST', ['test' => ['test' => 'foobar']]); - - $handler = $handler_factory->create(LegacyFormHandler::class); - $data = new TestData(); - - $response = $handler->handle($request, $data); - - self::assertInstanceOf(RedirectResponse::class, $response); - self::assertEquals('http://success.nl/foobar', $response->getTargetUrl()); - } } diff --git a/test/Functional/ControllerTest.php b/test/Functional/ControllerTest.php index b880523..223fd7b 100644 --- a/test/Functional/ControllerTest.php +++ b/test/Functional/ControllerTest.php @@ -7,8 +7,8 @@ namespace Hostnet\Bundle\FormHandlerBundle\Functional; use Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\TestKernel; +use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; -use Symfony\Component\HttpKernel\Kernel; use Symfony\Component\HttpKernel\KernelInterface; /** @@ -16,14 +16,11 @@ */ class ControllerTest extends WebTestCase { - private $test_client; + private KernelBrowser $test_client; - /** - * BC for current tests, new tests should get their own config. - */ protected function setUp(): void { - $this->test_client = static::createClient(['config_file' => TestKernel::getLegacyConfigFilename()]); + $this->test_client = static::createClient(['config_file' => 'autoconfigure.yml']); } protected static function createKernel(array $options = []): KernelInterface @@ -33,14 +30,6 @@ protected static function createKernel(array $options = []): KernelInterface public function testActionInterfaceDependencyInjection(): void { - if (Kernel::VERSION_ID < 30300) { - self::markTestSkipped(sprintf('Symfony version %s not supported by test', Kernel::VERSION)); - } - - if (!interface_exists('Sensio\Bundle\FrameworkExtraBundle\Request\ParamConverter\ParamConverterInterface')) { - $this->markTestSkipped('Sensio Extra bundle is not installed.'); - } - $crawler = $this->test_client->request('GET', '/'); self::assertSame('test', $crawler->text()); diff --git a/test/Functional/Fixtures/HandlerType/FullFormHandler.php b/test/Functional/Fixtures/HandlerType/FullFormHandler.php index 02bfb3f..e8bc992 100644 --- a/test/Functional/Fixtures/HandlerType/FullFormHandler.php +++ b/test/Functional/Fixtures/HandlerType/FullFormHandler.php @@ -24,6 +24,9 @@ public function configure(HandlerConfigInterface $config): void $config->registerActionSubscriber($this); } + /** + * @return string[] + */ public function getSubscribedActions() { return [ @@ -32,12 +35,12 @@ public function getSubscribedActions() ]; } - public function onSuccess(TestData $data, FormInterface $form, Request $request) + public function onSuccess(TestData $data, FormInterface $form, Request $request): RedirectResponse { return new RedirectResponse('http://success.nl/'); } - public function onFailure(TestData $data, FormInterface $form, Request $request) + public function onFailure(TestData $data, FormInterface $form, Request $request): RedirectResponse { return new RedirectResponse('http://failure.nl/'); } diff --git a/test/Functional/Fixtures/HandlerType/FullFormHandler27.php b/test/Functional/Fixtures/HandlerType/FullFormHandler27.php deleted file mode 100644 index 5ea511f..0000000 --- a/test/Functional/Fixtures/HandlerType/FullFormHandler27.php +++ /dev/null @@ -1,43 +0,0 @@ -setType('test'); - $config->registerActionSubscriber($this); - } - - public function getSubscribedActions() - { - return [ - HandlerActions::SUCCESS => 'onSuccess', - HandlerActions::FAILURE => 'onFailure', - ]; - } - - public function onSuccess(TestData $data, FormInterface $form, Request $request) - { - return new RedirectResponse('http://success.nl/'); - } - - public function onFailure(TestData $data, FormInterface $form, Request $request) - { - return new RedirectResponse('http://failure.nl/'); - } -} diff --git a/test/Functional/Fixtures/HandlerType/SimpleNotTaggedFormHandler.php b/test/Functional/Fixtures/HandlerType/SimpleNotTaggedFormHandler.php deleted file mode 100644 index e1db75c..0000000 --- a/test/Functional/Fixtures/HandlerType/SimpleNotTaggedFormHandler.php +++ /dev/null @@ -1,19 +0,0 @@ -setType(TestType::class); - } -} diff --git a/test/Functional/Fixtures/Legacy/LegacyFormHandler.php b/test/Functional/Fixtures/Legacy/LegacyFormHandler.php deleted file mode 100644 index 1e902cd..0000000 --- a/test/Functional/Fixtures/Legacy/LegacyFormHandler.php +++ /dev/null @@ -1,45 +0,0 @@ -data = new TestData(); - } - - public function getType() - { - return TestType::class; - } - - public function getData() - { - return $this->data; - } - - public function onSuccess(Request $request) - { - return new RedirectResponse('http://success.nl/' . $this->data->test); - } - - public function onFailure(Request $request) - { - return new RedirectResponse('http://failure.nl/' . $this->data->test); - } -} diff --git a/test/Functional/Fixtures/Legacy/LegacyFormVariableOptionsHandler.php b/test/Functional/Fixtures/Legacy/LegacyFormVariableOptionsHandler.php deleted file mode 100644 index 251403d..0000000 --- a/test/Functional/Fixtures/Legacy/LegacyFormVariableOptionsHandler.php +++ /dev/null @@ -1,52 +0,0 @@ -data = new TestData(); - } - - public function getOptions() - { - return ['attr' => ['class' => $this->data->test]]; - } - - public function getType() - { - return TestType::class; - } - - public function getData() - { - return $this->data; - } - - public function onSuccess(Request $request) - { - return new RedirectResponse('http://success.nl/' . $this->data->test); - } - - public function onFailure(Request $request) - { - return new RedirectResponse('http://failure.nl/' . $this->data->test); - } -} diff --git a/test/Functional/Fixtures/Legacy/LegacyNamedFormHandler.php b/test/Functional/Fixtures/Legacy/LegacyNamedFormHandler.php deleted file mode 100644 index 1a666db..0000000 --- a/test/Functional/Fixtures/Legacy/LegacyNamedFormHandler.php +++ /dev/null @@ -1,52 +0,0 @@ -data = new TestData(); - } - - public function getType() - { - return TestType::class; - } - - public function getName() - { - return 'foobar'; - } - - public function getData() - { - return $this->data; - } - - public function onSuccess(Request $request) - { - return new RedirectResponse('http://success.nl/' . $this->data->test); - } - - public function onFailure(Request $request) - { - return new RedirectResponse('http://failure.nl/' . $this->data->test); - } -} diff --git a/test/Functional/Fixtures/TestController.php b/test/Functional/Fixtures/TestController.php index b4ff052..a6d5151 100644 --- a/test/Functional/Fixtures/TestController.php +++ b/test/Functional/Fixtures/TestController.php @@ -7,10 +7,6 @@ namespace Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures; use Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\SimpleFormHandler; -use Hostnet\Bundle\FormHandlerBundle\ParamConverter\FormParamConverter; -use Hostnet\Bundle\FormHandlerBundle\Registry\LegacyHandlerRegistry; -use Hostnet\Component\Form\Simple\SimpleFormProvider; -use Hostnet\Component\FormHandler\HandlerFactory; use Hostnet\Component\FormHandler\HandlerFactoryInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -20,30 +16,14 @@ */ class TestController { - /** @var FormParamConverter */ - private $converter; - /** @var SimpleFormProvider */ - private $provider; - /** @var LegacyHandlerRegistry */ - private $registry; - /** @var HandlerFactory */ - private $handler; - public function __construct( - FormParamConverter $converter, - SimpleFormProvider $provider, - LegacyHandlerRegistry $registry, - HandlerFactory $handler + private readonly HandlerFactoryInterface $handler_factory, ) { - $this->converter = $converter; - $this->provider = $provider; - $this->registry = $registry; - $this->handler = $handler; } - public function action(Request $request, HandlerFactoryInterface $factory) + public function action(Request $request) { - $handler = $factory->create(SimpleFormHandler::class); + $handler = $this->handler_factory->create(SimpleFormHandler::class); $response = $handler->handle($request); if ($response instanceof Response) { return $response; diff --git a/test/Functional/Fixtures/TestData.php b/test/Functional/Fixtures/TestData.php index cbeee6c..78380b5 100644 --- a/test/Functional/Fixtures/TestData.php +++ b/test/Functional/Fixtures/TestData.php @@ -10,8 +10,6 @@ class TestData { - /** - * @Assert\NotBlank() - */ - public $test; + #[Assert\NotBlank] + public ?string $test; } diff --git a/test/Functional/Fixtures/TestKernel.php b/test/Functional/Fixtures/TestKernel.php index a164db1..7d42c26 100644 --- a/test/Functional/Fixtures/TestKernel.php +++ b/test/Functional/Fixtures/TestKernel.php @@ -22,24 +22,6 @@ public function __construct(array $options) ); } - public static function getLegacyConfigFilename() - { - if (Kernel::VERSION_ID >= 40200) { - return 'config_42.yml'; - } - - - if (Kernel::VERSION_ID >= 30300) { - return 'config_33.yml'; - } - - if (Kernel::VERSION_ID >= 30000) { - return 'config_32.yml'; - } - - return 'config_27.yml'; - } - public function getProjectDir(): string { return __DIR__; @@ -59,12 +41,12 @@ public function registerBundles(): iterable /** * {@inheritdoc} */ - public function registerContainerConfiguration(LoaderInterface $loader) + public function registerContainerConfiguration(LoaderInterface $loader): void { $loader->load(__DIR__."/config/{$this->config_file}"); } - protected function prepareContainer(ContainerBuilder $container) + protected function prepareContainer(ContainerBuilder $container): void { parent::prepareContainer($container); diff --git a/test/Functional/Fixtures/TestType27.php b/test/Functional/Fixtures/TestType27.php deleted file mode 100644 index 921cc23..0000000 --- a/test/Functional/Fixtures/TestType27.php +++ /dev/null @@ -1,31 +0,0 @@ -add('test', 'text'); - } - - public function configureOptions(OptionsResolver $resolver): void - { - $resolver->setDefaults([ - 'data_class' => TestData::class, - ]); - } - - public function getName() - { - return 'test'; - } -} diff --git a/test/Functional/Fixtures/config/autoconfigure.yml b/test/Functional/Fixtures/config/autoconfigure.yml index c33dc0c..8bc5a82 100644 --- a/test/Functional/Fixtures/config/autoconfigure.yml +++ b/test/Functional/Fixtures/config/autoconfigure.yml @@ -2,13 +2,12 @@ services: _defaults: autoconfigure: true autowire: true - public: false + public: true Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\: resource: '../HandlerType' - Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\Legacy\: - resource: '../Legacy' + Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\TestController: framework: test: true @@ -18,6 +17,11 @@ framework: resource: '%kernel.project_dir%/config/routing.yml' form: true validation: - enable_annotations: true + enable_attributes: true + email_validation_mode: html5 translator: fallback: en + http_method_override: false + handle_all_throwables: true + php_errors: + log: true diff --git a/test/Functional/Fixtures/config/config_27.yml b/test/Functional/Fixtures/config/config_27.yml deleted file mode 100644 index b02acee..0000000 --- a/test/Functional/Fixtures/config/config_27.yml +++ /dev/null @@ -1,50 +0,0 @@ -services: - app.handler.type.full_form: - class: Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\FullFormHandler - tags: - - { name: form.handler } - - app.handler.type.simple_form: - class: Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\SimpleFormHandler - tags: - - { name: form.handler } - - app.handler.type.simple_form_not_tagged: - class: Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\SimpleNotTaggedFormHandler - - app.handler.legacy.normal: - class: Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\Legacy\LegacyFormHandler - tags: - - { name: form.handler } - - app.handler.legacy.variable: - class: Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\Legacy\LegacyFormVariableOptionsHandler - tags: - - { name: form.handler } - - app.handler.legacy.named: - class: Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\Legacy\LegacyNamedFormHandler - tags: - - { name: form.handler } - - app.handler.type.full_27_form: - class: Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\FullFormHandler27 - tags: - - { name: form.handler } - - app.type.test: - class: Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\TestType27 - tags: - - { name: form.type, alias: test } - -framework: - test: true - secret: test - router: - utf8: true - resource: '%kernel.root_dir%/config/routing.yml' - form: true - validation: - enable_annotations: true - translator: - fallback: en diff --git a/test/Functional/Fixtures/config/config_32.yml b/test/Functional/Fixtures/config/config_32.yml deleted file mode 100644 index 596ceea..0000000 --- a/test/Functional/Fixtures/config/config_32.yml +++ /dev/null @@ -1,40 +0,0 @@ -services: - app.handler.type.full_form: - class: Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\FullFormHandler - tags: - - { name: form.handler } - - app.handler.type.simple_form: - class: Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\SimpleFormHandler - tags: - - { name: form.handler } - - app.handler.type.simple_form_not_tagged: - class: Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\SimpleNotTaggedFormHandler - - app.handler.legacy.normal: - class: Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\Legacy\LegacyFormHandler - tags: - - { name: form.handler } - - app.handler.legacy.variable: - class: Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\Legacy\LegacyFormVariableOptionsHandler - tags: - - { name: form.handler } - - app.handler.legacy.named: - class: Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\Legacy\LegacyNamedFormHandler - tags: - - { name: form.handler } - -framework: - test: true - secret: test - router: - utf8: true - resource: '%kernel.root_dir%/config/routing.yml' - form: true - validation: - enable_annotations: true - translator: - fallback: en diff --git a/test/Functional/Fixtures/config/config_33.yml b/test/Functional/Fixtures/config/config_33.yml deleted file mode 100644 index 4acf144..0000000 --- a/test/Functional/Fixtures/config/config_33.yml +++ /dev/null @@ -1,49 +0,0 @@ -services: - _defaults: - autoconfigure: true - autowire: true - - Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\: - resource: '../HandlerType' - - Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\Legacy\: - resource: '../Legacy' - - Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\SimpleNotTaggedFormHandler: - autoconfigure: false - - app.handler.type.full_form: - alias: 'Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\FullFormHandler' - public: true - - app.handler.type.simple_form: - alias: 'Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\SimpleFormHandler' - public: true - - app.handler.type.simple_form_not_tagged: '@Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\SimpleNotTaggedFormHandler' - app.handler.legacy.normal: - alias: 'Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\Legacy\LegacyFormHandler' - public: true - - app.handler.legacy.variable: - alias: 'Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\Legacy\LegacyFormVariableOptionsHandler' - public: true - - app.handler.legacy.named: - alias: 'Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\Legacy\LegacyNamedFormHandler' - public: true - - Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\TestController: - tags: ['controller.service_arguments'] - -framework: - test: true - secret: test - router: - utf8: true - resource: '%kernel.root_dir%/config/routing.yml' - form: true - validation: - enable_annotations: true - translator: - fallback: en diff --git a/test/Functional/Fixtures/config/config_42.yml b/test/Functional/Fixtures/config/config_42.yml deleted file mode 100644 index 261bc04..0000000 --- a/test/Functional/Fixtures/config/config_42.yml +++ /dev/null @@ -1,49 +0,0 @@ -services: - _defaults: - autoconfigure: true - autowire: true - - Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\: - resource: '../HandlerType' - - Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\Legacy\: - resource: '../Legacy' - - Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\SimpleNotTaggedFormHandler: - autoconfigure: false - - app.handler.type.full_form: - alias: 'Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\FullFormHandler' - public: true - - app.handler.type.simple_form: - alias: 'Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\SimpleFormHandler' - public: true - - app.handler.type.simple_form_not_tagged: '@Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\SimpleNotTaggedFormHandler' - app.handler.legacy.normal: - alias: 'Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\Legacy\LegacyFormHandler' - public: true - - app.handler.legacy.variable: - alias: 'Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\Legacy\LegacyFormVariableOptionsHandler' - public: true - - app.handler.legacy.named: - alias: 'Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\Legacy\LegacyNamedFormHandler' - public: true - - Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\TestController: - tags: ['controller.service_arguments'] - -framework: - test: true - secret: test - router: - utf8: true - resource: '%kernel.project_dir%/config/routing.yml' - form: true - validation: - enable_annotations: true - translator: - fallback: en diff --git a/test/Functional/HandlerTest.php b/test/Functional/HandlerTest.php index 350de6c..70b5960 100644 --- a/test/Functional/HandlerTest.php +++ b/test/Functional/HandlerTest.php @@ -7,7 +7,6 @@ namespace Hostnet\Bundle\FormHandlerBundle\Functional; use Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\FullFormHandler; -use Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\FullFormHandler27; use Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\TestData; use Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\TestKernel; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; @@ -23,7 +22,7 @@ class HandlerTest extends KernelTestCase */ protected function setUp(): void { - static::bootKernel(['config_file' => TestKernel::getLegacyConfigFilename()]); + static::bootKernel(['config_file' => 'autoconfigure.yml']); } protected static function createKernel(array $options = []): KernelInterface @@ -52,10 +51,6 @@ public function testValid(): void public function testInvalid(): void { - if (Kernel::VERSION_ID < 20800) { - self::markTestSkipped(sprintf('Symfony version %s not supported by test', Kernel::VERSION)); - } - $container = self::$kernel->getContainer(); $handler_factory = $container->get('hostnet.form_handler.factory'); $request = Request::create('/', 'POST', ['test' => ['test' => null]]); @@ -68,48 +63,4 @@ public function testInvalid(): void self::assertInstanceOf(RedirectResponse::class, $response); self::assertEquals('http://failure.nl/', $response->getTargetUrl()); } - - /** - * @group legacy - */ - public function testValid27(): void - { - if (Kernel::VERSION_ID >= 30000) { - self::markTestSkipped(sprintf('Symfony version %s not supported by test', Kernel::VERSION)); - } - - $container = self::$kernel->getContainer(); - $handler_factory = $container->get('hostnet.form_handler.factory'); - $request = Request::create('/', 'POST', ['test' => ['test' => 'foobar']]); - - $handler = $handler_factory->create(FullFormHandler27::class); - $data = new TestData(); - - $response = $handler->handle($request, $data); - - self::assertInstanceOf(RedirectResponse::class, $response); - self::assertEquals('http://success.nl/', $response->getTargetUrl()); - } - - /** - * @group legacy - */ - public function testInvalid27(): void - { - if (Kernel::VERSION_ID >= 30000) { - self::markTestSkipped(sprintf('Symfony version %s not supported by test', Kernel::VERSION)); - } - - $container = self::$kernel->getContainer(); - $handler_factory = $container->get('hostnet.form_handler.factory'); - $request = Request::create('/', 'POST', ['test' => ['test' => null]]); - - $handler = $handler_factory->create(FullFormHandler27::class); - $data = new TestData(); - - $response = $handler->handle($request, $data); - - self::assertInstanceOf(RedirectResponse::class, $response); - self::assertEquals('http://failure.nl/', $response->getTargetUrl()); - } } diff --git a/test/Functional/RegistryTest.php b/test/Functional/RegistryTest.php index b4cb5a7..c1b442c 100644 --- a/test/Functional/RegistryTest.php +++ b/test/Functional/RegistryTest.php @@ -8,24 +8,16 @@ use Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\FullFormHandler; use Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\SimpleFormHandler; -use Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\HandlerType\SimpleNotTaggedFormHandler; -use Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\Legacy\LegacyFormHandler; -use Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\Legacy\LegacyFormVariableOptionsHandler; -use Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\Legacy\LegacyNamedFormHandler; use Hostnet\Bundle\FormHandlerBundle\Functional\Fixtures\TestKernel; use Hostnet\Component\FormHandler\Exception\InvalidHandlerTypeException; -use Hostnet\Component\FormHandler\HandlerTypeAdapter; use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase; use Symfony\Component\HttpKernel\KernelInterface; class RegistryTest extends KernelTestCase { - /** - * BC for current tests, new tests should get their own config. - */ protected function setUp(): void { - static::bootKernel(['config_file' => TestKernel::getLegacyConfigFilename()]); + static::bootKernel(['config_file' => 'autoconfigure.yml']); } protected static function createKernel(array $options = []): KernelInterface @@ -39,27 +31,13 @@ public function test(): void $registry = $container->get('hostnet.form_handler.registry'); self::assertSame( - $container->get('app.handler.type.full_form'), + $container->get(FullFormHandler::class), $registry->getType(FullFormHandler::class) ); self::assertSame( - $container->get('app.handler.type.simple_form'), + $container->get(SimpleFormHandler::class), $registry->getType(SimpleFormHandler::class) ); - - // are the legacy variants wrapped? - self::assertEquals( - new HandlerTypeAdapter($container->get('app.handler.legacy.normal')), - $registry->getType(LegacyFormHandler::class) - ); - self::assertEquals( - new HandlerTypeAdapter($container->get('app.handler.legacy.variable')), - $registry->getType(LegacyFormVariableOptionsHandler::class) - ); - self::assertEquals( - new HandlerTypeAdapter($container->get('app.handler.legacy.named')), - $registry->getType(LegacyNamedFormHandler::class) - ); } public function testMissing(): void @@ -71,14 +49,4 @@ public function testMissing(): void $registry->getType(\stdClass::class); } - - public function testNotTagged(): void - { - $container = self::$kernel->getContainer(); - $registry = $container->get('hostnet.form_handler.registry'); - - $this->expectException(InvalidHandlerTypeException::class); - - $registry->getType(SimpleNotTaggedFormHandler::class); - } } diff --git a/test/HostnetFormHandlerBundleTest.php b/test/HostnetFormHandlerBundleTest.php index 0e11de8..7419cae 100644 --- a/test/HostnetFormHandlerBundleTest.php +++ b/test/HostnetFormHandlerBundleTest.php @@ -25,25 +25,10 @@ public function testBuild(): void $bundle = new HostnetFormHandlerBundle(); $bundle->build($container); - $found = false; - - foreach ($container->getCompilerPassConfig()->getBeforeOptimizationPasses() as $pass) { - if (!$pass instanceof FormHandlerRegistryCompilerPass) { - continue; - } - - $found = true; - break; - } - - self::assertTrue($found, 'Expected to find a compiler pass instance of the FormParamConverterCompilerPass.'); - - if (method_exists($container, 'getAutoconfiguredInstanceof')) { - $child_definitions = $container->getAutoconfiguredInstanceof(); - self::assertArrayHasKey(FormHandlerInterface::class, $child_definitions); - self::assertArrayHasKey(HandlerTypeInterface::class, $child_definitions); - self::assertArrayHasKey('form.handler', $child_definitions[HandlerTypeInterface::class]->getTags()); - self::assertArrayHasKey('form.handler', $child_definitions[FormHandlerInterface::class]->getTags()); - } + $child_definitions = $container->getAutoconfiguredInstanceof(); + self::assertArrayHasKey(FormHandlerInterface::class, $child_definitions); + self::assertArrayHasKey(HandlerTypeInterface::class, $child_definitions); + self::assertArrayHasKey('form.handler', $child_definitions[HandlerTypeInterface::class]->getTags()); + self::assertArrayHasKey('form.handler', $child_definitions[FormHandlerInterface::class]->getTags()); } } diff --git a/test/ParamConverter/FormParamConverterTest.php b/test/ParamConverter/FormParamConverterTest.php deleted file mode 100644 index 2d1bdda..0000000 --- a/test/ParamConverter/FormParamConverterTest.php +++ /dev/null @@ -1,169 +0,0 @@ -markTestSkipped('Sensio Extra bundle is not installed.'); - return; - } - - $this->container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock(); - $this->request = new Request(); - } - - /** - * @group legacy - * @expectedDeprecation Calling %s is deprecated as of 1.6 and will be removed in 2.0. Use %s instead. - */ - public function testApplyFromServiceIdHandlerNotFound(): void - { - $configuration = new ParamConverter(['class' => 'Test\Henk', 'options' => ['service_id' => 'test.henk']]); - $converter = new FormParamConverter($this->container); - $this->assertFalse($converter->supports($configuration)); - - $configuration = $this->buildParamConverter( - 'Hostnet\Bundle\FormHandlerBundle\ParamConverter\HandlerMock', - ['service_id' => 'test.henk'] - ); - - $converter->addFormClass('test.henk', 'Hostnet\Bundle\FormHandlerBundle\ParamConverter\HandlerMock'); - $this->assertTrue($converter->supports($configuration)); - - $converter->apply($this->request, $configuration); - } - - /** - * @group legacy - * @expectedDeprecation Calling %s is deprecated as of 1.6 and will be removed in 2.0. Use %s instead. - */ - public function testApplyFromServiceIdDeprecated(): void - { - $converter = new FormParamConverter($this->container); - $configuration = $this->buildParamConverter( - 'Hostnet\Bundle\FormHandlerBundle\ParamConverter\HandlerMock', - ['service_id' => 'test.henk'], - 'henk' - ); - - $converter->addFormClass('test.henk', 'Hostnet\Bundle\FormHandlerBundle\ParamConverter\HandlerMock'); - $this->assertTrue($converter->supports($configuration)); - - $handler = new HandlerMock(); - - $this->container - ->expects($this->once()) - ->method('get') - ->will($this->returnValue($handler)); - - $converter->apply($this->request, $configuration); - - $this->assertEquals($handler, $this->request->attributes->get('henk')); - } - - public function testApplyFromServiceId(): void - { - $converter = new FormParamConverter($this->container, [ - 'test.henk' => 'Hostnet\Bundle\FormHandlerBundle\ParamConverter\HandlerMock', - ]); - - $configuration = $this->buildParamConverter( - 'Hostnet\Bundle\FormHandlerBundle\ParamConverter\HandlerMock', - ['service_id' => 'test.henk'], - 'henk' - ); - - $this->assertTrue($converter->supports($configuration)); - - $handler = new HandlerMock(); - - $this->container - ->expects($this->once()) - ->method('get') - ->will($this->returnValue($handler)); - - $converter->apply($this->request, $configuration); - - $this->assertEquals($handler, $this->request->attributes->get('henk')); - } - - /** - * @group legacy - * @expectedDeprecation Calling %s is deprecated as of 1.6 and will be removed in 2.0. Use %s instead. - */ - public function testGetServiceIdForClassName(): void - { - $converter = new FormParamConverter($this->container); - $configuration = $this->buildParamConverter( - 'Hostnet\Bundle\FormHandlerBundle\ParamConverter\HandlerMock', - [], - 'henk' - ); - - $converter->addFormClass('test.henk', 'Hostnet\Bundle\FormHandlerBundle\ParamConverter\HandlerMock'); - $converter->apply($this->request, $configuration); - } - - public function testGetServiceIdForClassNameNoMatch(): void - { - $converter = new FormParamConverter($this->container); - $configuration = $this->buildParamConverter( - 'Hostnet\Bundle\FormHandlerBundle\ParamConverter\HandlerMock', - [], - 'henk' - ); - - $this->expectException(\InvalidArgumentException::class); - - $converter->apply($this->request, $configuration); - } - - /** - * @group legacy - * @expectedDeprecation Calling %s is deprecated as of 1.6 and will be removed in 2.0. Use %s instead. - */ - public function testGetServiceIdForClassNameTooManyClassesForOneService(): void - { - $converter = new FormParamConverter($this->container); - $configuration = $this->buildParamConverter( - 'Hostnet\Bundle\FormHandlerBundle\ParamConverter\HandlerMock', - [], - 'henk' - ); - - // too many for 1 class to automatically determine the service id by class - foreach (['test.henk', 'test.hans'] as $id) { - $converter->addFormClass($id, 'Hostnet\Bundle\FormHandlerBundle\ParamConverter\HandlerMock'); - } - - $this->expectException(\InvalidArgumentException::class); - - $converter->apply($this->request, $configuration); - } - - private function buildParamConverter($class, array $options = [], $name = null): ParamConverter - { - return new ParamConverter([ - 'class' => $class, - 'options' => $options, - 'name' => $name, - ]); - } -} diff --git a/test/ParamConverter/HandlerMock.php b/test/ParamConverter/HandlerMock.php deleted file mode 100644 index 5041197..0000000 --- a/test/ParamConverter/HandlerMock.php +++ /dev/null @@ -1,36 +0,0 @@ -