From b02d81a9ad903f305f3d41b3a4298e61812cdae6 Mon Sep 17 00:00:00 2001 From: Anthony Moutte Date: Mon, 24 Jun 2024 20:26:03 +0200 Subject: [PATCH 1/5] Add github action --- .github/workflows/build.yml | 63 +++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 .github/workflows/build.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..963ce1d --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,63 @@ +name: Build Symftony/form-handler +run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 +on: [ push ] +jobs: + Quality-check: + name: Run PHP quality check + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP + uses: shivammathur/setup-php@v2 + with: + php-version: '8.3' + coverage: xdebug + tools: php-cs-fixer, phpstan + + - name: Run PHPStan + run: phpstan analyse src + + - name: Run PHP CS fixer + run: php-cs-fixer + + Build: + name: PHP ${{ matrix.php-versions }} + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: [ '8.1', '8.2', '8.3' ] + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP ${{ matrix.php-versions }} + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + coverage: xdebug + tools: php-cs-fixer, phpunit, phpstan + + - name: "Composer -> Get cache directory" + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: "Composer -> Cache dependencies" + uses: actions/cache@v4 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: ${{ runner.os }}-composer- + + - name: "Composer -> Install dependencies" + run: composer install --no-progress --prefer-dist --optimize-autoloader + + - name: "Composer -> check platform requirements" + run: composer check-platform-reqs + + - name: "PHPStan -> Run" + run: phpstan analyse src + + - name: "PHPUnit -> Run" + run: phpunit --coverage-text From 1abcffb06cc13c6e5c179437cee3aad15927291e Mon Sep 17 00:00:00 2001 From: Anthony Moutte Date: Mon, 24 Jun 2024 21:01:20 +0200 Subject: [PATCH 2/5] add phpcsfixer and phpstan --- .gitignore | 1 + composer.json | 4 ++- phpstan.neon | 7 +++++ src/Exception/FormException.php | 4 +-- src/Exception/InvalidFormException.php | 1 + src/Exception/NotSubmittedFormException.php | 1 + .../TransformationFailedFormException.php | 1 + .../Invalid/Type/InvalidTypeExtension.php | 1 + .../Type/NotSubmittedTypeExtension.php | 1 + .../TransformationFailedTypeExtension.php | 1 + .../FormHandlerExtension.php | 1 + .../Normalizer/FormInvalidNormalizer.php | 20 ++++--------- src/FormHandler.php | 30 +++---------------- tests/FormHandlerTest.php | 2 +- 14 files changed, 31 insertions(+), 44 deletions(-) create mode 100644 phpstan.neon diff --git a/.gitignore b/.gitignore index 50b321e..15b94f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ vendor composer.lock .phpunit.result.cache +.php-cs-fixer.cache diff --git a/composer.json b/composer.json index cc9e48c..d675299 100644 --- a/composer.json +++ b/composer.json @@ -23,7 +23,9 @@ "phpspec/prophecy-phpunit": "^2.1", "symfony/translation": "^6.1", "symfony/contracts": "^3.5@dev", - "symfony/validator": "^6.1" + "symfony/validator": "^6.1", + "phpstan/phpstan": "2.0.x-dev", + "friendsofphp/php-cs-fixer": "dev-master" }, "suggest": { "symfony/dependency-injection": "^6.1", diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..4d98df7 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,7 @@ +parameters: + level: 8 + paths: + - src + ignoreErrors: + - identifier: 'missingType.iterableValue' + - identifier: 'missingType.generics' diff --git a/src/Exception/FormException.php b/src/Exception/FormException.php index 0d90148..1381709 100644 --- a/src/Exception/FormException.php +++ b/src/Exception/FormException.php @@ -1,4 +1,5 @@ isSubmitted() && !$data->isValid(); } - public function normalize($object, $format = null, array $context = []): float|int|bool|\ArrayObject|array|string|null + public function normalize(mixed $object, ?string $format = null, array $context = []): float|int|bool|\ArrayObject|array|string|null { return [ 'code' => $context['status_code'] ?? null, @@ -47,15 +46,12 @@ public function normalize($object, $format = null, array $context = []): float|i /** * This code has been taken from JMSSerializer. - * - * @param FormInterface $data - * - * @return array */ private function convertFormToArray(FormInterface $data): array { $form = $errors = []; foreach ($data->getErrors() as $error) { + // @phpstan-ignore-next-line $errors[] = $this->getErrorMessage($error); } if ($errors) { @@ -73,14 +69,10 @@ private function convertFormToArray(FormInterface $data): array return $form; } - /** - * @param FormError $error - * - * @return string - */ - private function getErrorMessage(FormError $error) + private function getErrorMessage(FormError $error): string { if (null !== $error->getMessagePluralization()) { + // @phpstan-ignore-next-line return $this->translator->transChoice($error->getMessageTemplate(), $error->getMessagePluralization(), $error->getMessageParameters(), 'validators'); } return $this->translator->trans($error->getMessageTemplate(), $error->getMessageParameters(), 'validators'); diff --git a/src/FormHandler.php b/src/FormHandler.php index 1a773a9..d05782c 100644 --- a/src/FormHandler.php +++ b/src/FormHandler.php @@ -1,4 +1,5 @@ formFactory = $formFactory; } - /** - * @param string $type - * @param null $name - * @param null $data - * @param array $options - * - * @return FormInterface - */ - public function createForm(string $type, $name = null, $data = null, array $options = []): FormInterface + public function createForm(string $type, string $name = null, mixed $data = null, array $options = []): FormInterface { if (null !== $name) { return $this->formFactory->createNamed($name, $type, $data, $options); @@ -35,15 +28,7 @@ public function createForm(string $type, $name = null, $data = null, array $opti return $this->formFactory->create($type, $data, $options); } - /** - * @param $request - * @param FormInterface $form - * - * @return mixed - * - * @throws mixed - */ - public function handleRequest(FormInterface $form, $request = null): mixed + public function handleRequest(FormInterface $form, mixed $request = null): mixed { $form->handleRequest($request); $formConfig = $form->getConfig(); @@ -60,13 +45,6 @@ public function handleRequest(FormInterface $form, $request = null): mixed return $this->postSubmit($form); } - /** - * @param FormInterface $form - * @param array $data - * @param bool $clearMissing - * - * @return mixed|null - */ public function handleData(FormInterface $form, array $data = [], bool $clearMissing = true): mixed { $formConfig = $form->getConfig(); @@ -85,7 +63,7 @@ public function handleData(FormInterface $form, array $data = [], bool $clearMis return $this->postSubmit($form); } - private function postSubmit(FormInterface $form,) + private function postSubmit(FormInterface $form): mixed { $formConfig = $form->getConfig(); if ($form->isSubmitted()) { diff --git a/tests/FormHandlerTest.php b/tests/FormHandlerTest.php index 0c35bf7..2a71c1b 100644 --- a/tests/FormHandlerTest.php +++ b/tests/FormHandlerTest.php @@ -25,7 +25,7 @@ class FormHandlerTest extends TestCase private FormConfigInterface|ObjectProphecy $formConfigMock; - private FormHandler|ObjectProphecy $formHandler; + private FormHandler $formHandler; public function setUp(): void { From 35fc6453eed5cb8cf9e17b45844a09617dfb030d Mon Sep 17 00:00:00 2001 From: Anthony Moutte Date: Mon, 24 Jun 2024 21:11:39 +0200 Subject: [PATCH 3/5] fixup CI --- .github/workflows/build.yml | 23 +++-------------------- 1 file changed, 3 insertions(+), 20 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 963ce1d..80affd4 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -2,26 +2,6 @@ name: Build Symftony/form-handler run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 on: [ push ] jobs: - Quality-check: - name: Run PHP quality check - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v4 - - - name: Setup PHP - uses: shivammathur/setup-php@v2 - with: - php-version: '8.3' - coverage: xdebug - tools: php-cs-fixer, phpstan - - - name: Run PHPStan - run: phpstan analyse src - - - name: Run PHP CS fixer - run: php-cs-fixer - Build: name: PHP ${{ matrix.php-versions }} runs-on: ubuntu-latest @@ -56,6 +36,9 @@ jobs: - name: "Composer -> check platform requirements" run: composer check-platform-reqs + - name: "PHP cs fixer -> check" + run: php-cs-fixer check src + - name: "PHPStan -> Run" run: phpstan analyse src From 9ff15a68962d8955ec9023787ccfbf4f7a7507b9 Mon Sep 17 00:00:00 2001 From: Anthony Moutte Date: Mon, 24 Jun 2024 21:56:12 +0200 Subject: [PATCH 4/5] fixup CI --- .gitignore | 3 +++ composer.json | 2 +- phpunit.xml.dist | 26 ++++++++++++------- .../Compiler/FormHandlerCompilerPassTest.php | 4 +-- 4 files changed, 22 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 15b94f7..4091b78 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,7 @@ vendor composer.lock + +.phpunit.cache .phpunit.result.cache + .php-cs-fixer.cache diff --git a/composer.json b/composer.json index d675299..bcdf084 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,7 @@ "symfony/form": "^6.1" }, "require-dev": { - "phpunit/phpunit": "^9.1", + "phpunit/phpunit": "^10", "symfony/dependency-injection": "^6.1", "symfony/config": "^6.1", "symfony/http-kernel": "^6.1", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index efe96c0..af9bb53 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,15 +1,12 @@ - - - - src - - - src/Exception - src/*Bundle/Resources - - + @@ -18,4 +15,13 @@ tests + + + src + + + src/Exception + src/*Bundle/Resources + + diff --git a/tests/FormBundle/DependencyInjection/Compiler/FormHandlerCompilerPassTest.php b/tests/FormBundle/DependencyInjection/Compiler/FormHandlerCompilerPassTest.php index ccaab08..035c83e 100644 --- a/tests/FormBundle/DependencyInjection/Compiler/FormHandlerCompilerPassTest.php +++ b/tests/FormBundle/DependencyInjection/Compiler/FormHandlerCompilerPassTest.php @@ -30,7 +30,7 @@ public function testProcessThrowLogicException() $this->expectExceptionMessage('Form factory expected for "form.handler" tagged services.'); $this->containerBuilder->addDefinitions([ - 'my_custom_form_handler' => (new Definition())->addTag('form.handler') + 'my_custom_form_handler' => (new Definition())->addTag('form.handler'), ]); $this->formHandlerCompilerPass->process($this->containerBuilder); @@ -51,7 +51,7 @@ public function testProcess() $this->formHandlerCompilerPass->process($this->containerBuilder); $this->assertSame([ - ['setFormFactory', [$formFactoryDefinition]] + ['setFormFactory', [$formFactoryDefinition]], ], $def->getMethodCalls()); } } From 35d45aebe1f17c969dce6c72b9f7d07a7f35979d Mon Sep 17 00:00:00 2001 From: Anthony Moutte Date: Mon, 24 Jun 2024 22:05:43 +0200 Subject: [PATCH 5/5] add rector --- .github/workflows/build.yml | 24 ++++++--- composer.json | 5 +- examples/CustomFormHandler.php | 11 ++-- examples/custom-form-api.php | 30 +++++++---- examples/custom-form-web.php | 45 +++++++++++----- examples/default-return.php | 45 +++++++++++----- examples/exception-with-validator.php | 45 +++++++++++----- examples/exception.php | 45 +++++++++++----- examples/index.php | 4 +- examples/menu.php | 6 +++ phpunit.xml.dist | 5 ++ rector.php | 34 ++++++++++++ src/Exception/FormException.php | 4 +- src/Exception/InvalidFormException.php | 4 +- src/Exception/NotSubmittedFormException.php | 4 +- .../TransformationFailedFormException.php | 4 +- .../Invalid/Type/InvalidTypeExtension.php | 7 ++- .../Type/NotSubmittedTypeExtension.php | 7 ++- .../TransformationFailedTypeExtension.php | 7 ++- .../Compiler/FormHandlerCompilerPass.php | 20 +++---- .../FormHandlerExtension.php | 6 +-- src/FormBundle/FormHandlerBundle.php | 10 ++-- .../Normalizer/FormInvalidNormalizer.php | 23 +++++--- src/FormHandler.php | 5 +- .../Invalid/Type/InvalidTypeExtensionTest.php | 10 ++-- .../Type/NotSubmittedTypeExtensionTest.php | 10 ++-- .../TransformationFailedTypeExtensionTest.php | 16 +++--- .../Compiler/FormHandlerCompilerPassTest.php | 8 +-- tests/FormBundle/FormHandlerBundleTest.php | 10 ++-- tests/FormHandlerTest.php | 52 +++++++++---------- 30 files changed, 333 insertions(+), 173 deletions(-) create mode 100644 rector.php diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 80affd4..2e00f42 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,13 +1,16 @@ name: Build Symftony/form-handler -run-name: ${{ github.actor }} is testing out GitHub Actions 🚀 +run-name: 🧑‍💻${{ github.actor }} Run build. on: [ push ] jobs: Build: - name: PHP ${{ matrix.php-versions }} + name: PHP ${{ matrix.php-versions }} // composer ${{ matrix.composer-command }} runs-on: ubuntu-latest strategy: matrix: php-versions: [ '8.1', '8.2', '8.3' ] + composer-command: + - 'install' + - 'update --prefer-lowest' steps: - name: Checkout uses: actions/checkout@v4 @@ -17,7 +20,6 @@ jobs: with: php-version: ${{ matrix.php-versions }} coverage: xdebug - tools: php-cs-fixer, phpunit, phpstan - name: "Composer -> Get cache directory" id: composer-cache @@ -31,16 +33,24 @@ jobs: restore-keys: ${{ runner.os }}-composer- - name: "Composer -> Install dependencies" - run: composer install --no-progress --prefer-dist --optimize-autoloader + run: composer ${{ matrix.composer-command }} --no-progress --prefer-dist --optimize-autoloader + + - name: "Composer -> Show" + run: composer show - name: "Composer -> check platform requirements" run: composer check-platform-reqs +# - name: "Rector -> Run" +# run: rector --dry-run + - name: "PHP cs fixer -> check" - run: php-cs-fixer check src + run: vendor/bin/php-cs-fixer check src - name: "PHPStan -> Run" - run: phpstan analyse src + run: vendor/bin/phpstan analyse src - name: "PHPUnit -> Run" - run: phpunit --coverage-text + run: vendor/bin/phpunit --coverage-text + env: + XDEBUG_MODE: coverage diff --git a/composer.json b/composer.json index bcdf084..afa3e27 100644 --- a/composer.json +++ b/composer.json @@ -24,8 +24,9 @@ "symfony/translation": "^6.1", "symfony/contracts": "^3.5@dev", "symfony/validator": "^6.1", - "phpstan/phpstan": "2.0.x-dev", - "friendsofphp/php-cs-fixer": "dev-master" + "phpstan/phpstan": "^1.11", + "friendsofphp/php-cs-fixer": "dev-master", + "rector/rector": "dev-main" }, "suggest": { "symfony/dependency-injection": "^6.1", diff --git a/examples/CustomFormHandler.php b/examples/CustomFormHandler.php index 4663456..eb0ca92 100644 --- a/examples/CustomFormHandler.php +++ b/examples/CustomFormHandler.php @@ -1,5 +1,7 @@ createForm(ChoiceType::class, 'my-value', null, [ 'method' => 'GET', @@ -30,7 +29,7 @@ public function formChoice() ]); } - public function createFromRequest($request = null, $notSubmitted = true, $invalid = true) + public function createFromRequest(?mixed $request = null, $notSubmitted = true, $invalid = true) { $form = $this->createForm(ChoiceType::class, 'my-value', null, [ 'method' => 'GET', @@ -49,4 +48,4 @@ public function createFromRequest($request = null, $notSubmitted = true, $invali return $this->handleRequest($form, $request); } -} \ No newline at end of file +} diff --git a/examples/custom-form-api.php b/examples/custom-form-api.php index 6929448..049412c 100644 --- a/examples/custom-form-api.php +++ b/examples/custom-form-api.php @@ -1,9 +1,11 @@ addTypeExtension(new TransformationFailedTypeExtension()) ->addExtension(new ValidatorExtension(Validation::createValidator())) ->getFormFactory(); - // Initialize form handler $formHandler = new CustomFormHandler(); $formHandler->setFormFactory($formFactory); - // Create the form // Handle request $exception = null; try { $result = $formHandler->createFromRequest(); -} catch (FormException $e) { - $exception = $e; +} catch (FormException $formException) { + $exception = $formException; } ?> @@ -41,7 +40,9 @@ Form handler throw NotSubmitted/Invalid Exception example - +

Form handler will return default data when exception append

@@ -67,13 +68,22 @@

/!\ When you use the handler to do some API you dont need the form in your controller. You just need your data or Exception /!\

- $formHandler->handleRequest($form) : - - getMessage() ?> + $formHandler->handleRequest($form) : + + getMessage() ?> + +?>
+addTypeExtension(new TransformationFailedTypeExtension()) ->addExtension(new ValidatorExtension(Validation::createValidator())) ->getFormFactory(); - // Initialize form handler $formHandler = new CustomFormHandler(); $formHandler->setFormFactory($formFactory); - // Create the form $form = $formHandler->formChoice(); // Handle request $exception = null; try { $result = $formHandler->handleRequest($form); -} catch (FormException $e) { - $exception = $e; +} catch (FormException $formException) { + $exception = $formException; } ?> @@ -42,7 +41,9 @@ Form handler throw NotSubmitted/Invalid Exception example - +

Form handler will return default data when exception append

@@ -67,23 +68,41 @@
- $form->isSubmitted() : isSubmitted()) ?> - $form->isValid() : isSubmitted() &&var_export($form->isValid()) ?> + $form->isSubmitted() : isSubmitted()) ?> +?> + $form->isValid() : isSubmitted() &&var_export($form->isValid()) ?> +?> $form->getTransformationFailure() : - getTransformationFailure()): ?> + getTransformationFailure()): ?> getTransformationFailure()->getMessage(); ?> null + +?> - $form->getData() : getData()); ?> - $formHandler->handleRequest($form) : - + $form->getData() : getData()); +?> + $formHandler->handleRequest($form) : + getMessage() ?> + +?>
+addTypeExtension(new TransformationFailedTypeExtension()) ->addExtension(new ValidatorExtension(Validation::createValidator())) ->getFormFactory(); - // Initialize form handler $formHandler = new FormHandler(); $formHandler->setFormFactory($formFactory); - // Create the form $form = $formHandler->createForm(ChoiceType::class, 'my-value', null, [ 'method' => 'GET', @@ -46,13 +44,12 @@ 'handler_not_submitted' => 'not submitted return data', 'handler_transformation_failed' => 'transformation fail return data', ]); - // Handle request $exception = null; try { $result = $formHandler->handleRequest($form); -} catch (FormException $e) { - $exception = $e; +} catch (FormException $formException) { + $exception = $formException; } ?> @@ -60,7 +57,9 @@ Form handler throw NotSubmitted/Invalid Exception example - +

Form handler will return default data when exception append

@@ -85,23 +84,41 @@
- $form->isSubmitted() : isSubmitted()) ?> - $form->isValid() : isSubmitted() && var_export($form->isValid()) ?> + $form->isSubmitted() : isSubmitted()) ?> +?> + $form->isValid() : isSubmitted() && var_export($form->isValid()) ?> +?> $form->getTransformationFailure() : - getTransformationFailure()): ?> + getTransformationFailure() instanceof \Symfony\Component\Form\Exception\TransformationFailedException): ?> getTransformationFailure()->getMessage(); ?> null + +?> - $form->getData() : getData()); ?> - $formHandler->handleRequest($form) : - + $form->getData() : getData()); +?> + $formHandler->handleRequest($form) : + getMessage() ?> + +?>
+addTypeExtension(new InvalidTypeExtension()) ->addExtension(new ValidatorExtension(Validation::createValidator())) ->getFormFactory(); - // Initialize form handler $formHandler = new FormHandler(); $formHandler->setFormFactory($formFactory); - // Create the form $form = $formHandler->createForm(ChoiceType::class, 'my-value', null, [ 'method' => 'GET', @@ -44,13 +42,12 @@ 'handler_invalid' => true, 'handler_not_submitted' => true, ]); - // Handle request $exception = null; try { $result = $formHandler->handleRequest($form); -} catch (FormException $e) { - $exception = $e; +} catch (FormException $formException) { + $exception = $formException; } ?> @@ -58,7 +55,9 @@ Form handler throw NotSubmitted/Invalid Exception example - +

Form handler will throw NotSubmitted/Invalid exception

@@ -83,23 +82,41 @@
- $form->isSubmitted() : isSubmitted()) ?> - $form->isValid() : isSubmitted() && var_export($form->isValid()) ?> + $form->isSubmitted() : isSubmitted()) ?> +?> + $form->isValid() : isSubmitted() && var_export($form->isValid()) ?> +?> $form->getTransformationFailure() : - getTransformationFailure()): ?> + getTransformationFailure() instanceof \Symfony\Component\Form\Exception\TransformationFailedException): ?> getTransformationFailure()->getMessage(); ?> null + +?> - $form->getData() : getData()); ?> - $formHandler->handleRequest($form) : - + $form->getData() : getData()); +?> + $formHandler->handleRequest($form) : + getMessage() ?> + +?>
+addTypeExtension(new NotSubmittedTypeExtension()) ->addTypeExtension(new TransformationFailedTypeExtension()) ->getFormFactory(); - // Initialize form handler $formHandler = new FormHandler(); $formHandler->setFormFactory($formFactory); - // Create the form $form = $formHandler->createForm(ChoiceType::class, 'my-value', null, [ 'method' => 'GET', @@ -32,13 +30,12 @@ 'handler_not_submitted' => true, 'handler_transformation_failed' => true, ]); - // Handle request $exception = null; try { $result = $formHandler->handleRequest($form); -} catch (FormException $e) { - $exception = $e; +} catch (FormException $formException) { + $exception = $formException; } ?> @@ -46,7 +43,9 @@ Form handler will throw NotSubmitted/TransformationFailed exception - +

Form handler will throw NotSubmitted/TransformationFailed exception

@@ -67,23 +66,41 @@
- $form->isSubmitted() : isSubmitted()) ?> - $form->isValid() : isSubmitted() && var_export($form->isValid()) ?> + $form->isSubmitted() : isSubmitted()) ?> +?> + $form->isValid() : isSubmitted() && var_export($form->isValid()) ?> +?> $form->getTransformationFailure() : - getTransformationFailure()): ?> + getTransformationFailure() instanceof \Symfony\Component\Form\Exception\TransformationFailedException): ?> getTransformationFailure()->getMessage(); ?> null + +?> - $form->getData() : getData()); ?> - $formHandler->handleRequest($form) : - + $form->getData() : getData()); +?> + $formHandler->handleRequest($form) : + throw getMessage() ?> + +?>
+Form handler Basic - +

Form handler Basic

diff --git a/examples/menu.php b/examples/menu.php index 8e52c06..3f0194b 100644 --- a/examples/menu.php +++ b/examples/menu.php @@ -1,3 +1,8 @@ +
Basic @@ -85,3 +90,4 @@ } +src/*Bundle/Resources + + + + + diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..4f9fbf3 --- /dev/null +++ b/rector.php @@ -0,0 +1,34 @@ +withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->withPreparedSets( + deadCode: true, + codeQuality: true, + codingStyle: true, + typeDeclarations: true, + privatization: true, + naming: true, + instanceOf: true, + earlyReturn: true, + strictBooleans: true, + carbon: true, + rectorPreset: true, + phpunitCodeQuality: true, + doctrineCodeQuality: true, + symfonyCodeQuality: true, + symfonyConfigs: true, + ) + // uncomment to reach your current PHP version + ->withPhpSets() + ->withRules([ + AddVoidReturnTypeWhereNoReturnRector::class, + ]); diff --git a/src/Exception/FormException.php b/src/Exception/FormException.php index 1381709..becc9fc 100644 --- a/src/Exception/FormException.php +++ b/src/Exception/FormException.php @@ -16,9 +16,9 @@ public function __construct( protected FormInterface $form, string $message = 'Form exception.', int $code = 0, - \Exception $previous = null, + \Exception $exception = null, ) { - parent::__construct($message, $code, $previous); + parent::__construct($message, $code, $exception); } public function getForm(): FormInterface diff --git a/src/Exception/InvalidFormException.php b/src/Exception/InvalidFormException.php index c00ee1e..b7b974e 100644 --- a/src/Exception/InvalidFormException.php +++ b/src/Exception/InvalidFormException.php @@ -12,8 +12,8 @@ */ class InvalidFormException extends FormException { - public function __construct(FormInterface $form, string $message = 'Invalid form.', int $code = 0, \Exception $previous = null) + public function __construct(FormInterface $form, string $message = 'Invalid form.', int $code = 0, \Exception $exception = null) { - parent::__construct($form, $message, $code, $previous); + parent::__construct($form, $message, $code, $exception); } } diff --git a/src/Exception/NotSubmittedFormException.php b/src/Exception/NotSubmittedFormException.php index 13c6bac..39ee8b3 100644 --- a/src/Exception/NotSubmittedFormException.php +++ b/src/Exception/NotSubmittedFormException.php @@ -12,8 +12,8 @@ */ class NotSubmittedFormException extends FormException { - public function __construct(FormInterface $form, string $message = 'Not submitted form.', int $code = 0, \Exception $previous = null) + public function __construct(FormInterface $form, string $message = 'Not submitted form.', int $code = 0, \Exception $exception = null) { - parent::__construct($form, $message, $code, $previous); + parent::__construct($form, $message, $code, $exception); } } diff --git a/src/Exception/TransformationFailedFormException.php b/src/Exception/TransformationFailedFormException.php index b7d0456..7a258bf 100644 --- a/src/Exception/TransformationFailedFormException.php +++ b/src/Exception/TransformationFailedFormException.php @@ -12,8 +12,8 @@ */ class TransformationFailedFormException extends FormException { - public function __construct(FormInterface $form, string $message = 'Transformation form failed.', int $code = 0, \Exception $previous = null) + public function __construct(FormInterface $form, string $message = 'Transformation form failed.', int $code = 0, \Exception $exception = null) { - parent::__construct($form, $message, $code, $previous); + parent::__construct($form, $message, $code, $exception); } } diff --git a/src/Form/Extension/Invalid/Type/InvalidTypeExtension.php b/src/Form/Extension/Invalid/Type/InvalidTypeExtension.php index cf8e398..d0fbfcf 100644 --- a/src/Form/Extension/Invalid/Type/InvalidTypeExtension.php +++ b/src/Form/Extension/Invalid/Type/InvalidTypeExtension.php @@ -8,11 +8,14 @@ use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\OptionsResolver\OptionsResolver; +/** + * @see \Symftony\FormHandler\Tests\Form\Extension\Invalid\Type\InvalidTypeExtensionTest + */ class InvalidTypeExtension extends AbstractTypeExtension { - public function configureOptions(OptionsResolver $resolver): void + public function configureOptions(OptionsResolver $optionsResolver): void { - $resolver->setDefaults([ + $optionsResolver->setDefaults([ 'handler_invalid' => false, ]); } diff --git a/src/Form/Extension/NotSubmitted/Type/NotSubmittedTypeExtension.php b/src/Form/Extension/NotSubmitted/Type/NotSubmittedTypeExtension.php index 64b85dc..998ab23 100644 --- a/src/Form/Extension/NotSubmitted/Type/NotSubmittedTypeExtension.php +++ b/src/Form/Extension/NotSubmitted/Type/NotSubmittedTypeExtension.php @@ -8,11 +8,14 @@ use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\OptionsResolver\OptionsResolver; +/** + * @see \Symftony\FormHandler\Tests\Form\Extension\NotSubmitted\Type\NotSubmittedTypeExtensionTest + */ class NotSubmittedTypeExtension extends AbstractTypeExtension { - public function configureOptions(OptionsResolver $resolver): void + public function configureOptions(OptionsResolver $optionsResolver): void { - $resolver->setDefaults([ + $optionsResolver->setDefaults([ 'handler_not_submitted' => false, ]); } diff --git a/src/Form/Extension/TransformationFailed/Type/TransformationFailedTypeExtension.php b/src/Form/Extension/TransformationFailed/Type/TransformationFailedTypeExtension.php index 46d28df..bfa5225 100644 --- a/src/Form/Extension/TransformationFailed/Type/TransformationFailedTypeExtension.php +++ b/src/Form/Extension/TransformationFailed/Type/TransformationFailedTypeExtension.php @@ -8,11 +8,14 @@ use Symfony\Component\Form\Extension\Core\Type\FormType; use Symfony\Component\OptionsResolver\OptionsResolver; +/** + * @see \Symftony\FormHandler\Tests\Form\Extension\TransformationFailed\Type\TransformationFailedTypeExtensionTest + */ class TransformationFailedTypeExtension extends AbstractTypeExtension { - public function configureOptions(OptionsResolver $resolver): void + public function configureOptions(OptionsResolver $optionsResolver): void { - $resolver->setDefaults([ + $optionsResolver->setDefaults([ 'handler_transformation_failed' => false, ]); } diff --git a/src/FormBundle/DependencyInjection/Compiler/FormHandlerCompilerPass.php b/src/FormBundle/DependencyInjection/Compiler/FormHandlerCompilerPass.php index d34daf2..d15e5f5 100644 --- a/src/FormBundle/DependencyInjection/Compiler/FormHandlerCompilerPass.php +++ b/src/FormBundle/DependencyInjection/Compiler/FormHandlerCompilerPass.php @@ -1,26 +1,28 @@ findTaggedServiceIds('form.handler'); + $taggedServices = $containerBuilder->findTaggedServiceIds('form.handler'); - if (!$container->hasDefinition('form.factory') && 0 < count($taggedServices)) { + if (!$containerBuilder->hasDefinition('form.factory') && [] !== $taggedServices) { throw new \LogicException('Form factory expected for "form.handler" tagged services.'); } - $formFactory = $container->getDefinition('form.factory'); - foreach ($taggedServices as $id => $tags) { - $container->getDefinition($id)->addMethodCall('setFormFactory', [$formFactory]); + $definition = $containerBuilder->getDefinition('form.factory'); + foreach (array_keys($taggedServices) as $id) { + $containerBuilder->getDefinition($id)->addMethodCall('setFormFactory', [$definition]); } } } diff --git a/src/FormBundle/DependencyInjection/FormHandlerExtension.php b/src/FormBundle/DependencyInjection/FormHandlerExtension.php index d2f011a..f018f3e 100644 --- a/src/FormBundle/DependencyInjection/FormHandlerExtension.php +++ b/src/FormBundle/DependencyInjection/FormHandlerExtension.php @@ -18,9 +18,9 @@ class FormHandlerExtension extends Extension /** * {@inheritDoc} */ - public function load(array $configs, ContainerBuilder $container): void + public function load(array $configs, ContainerBuilder $containerBuilder): void { - $loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); - $loader->load('services.yml'); + $yamlFileLoader = new YamlFileLoader($containerBuilder, new FileLocator(__DIR__ . '/../Resources/config')); + $yamlFileLoader->load('services.yml'); } } diff --git a/src/FormBundle/FormHandlerBundle.php b/src/FormBundle/FormHandlerBundle.php index 3a51526..c1e783a 100644 --- a/src/FormBundle/FormHandlerBundle.php +++ b/src/FormBundle/FormHandlerBundle.php @@ -1,5 +1,7 @@ addCompilerPass(new FormHandlerCompilerPass()); + $containerBuilder->addCompilerPass(new FormHandlerCompilerPass()); } } diff --git a/src/FormBundle/Serializer/Normalizer/FormInvalidNormalizer.php b/src/FormBundle/Serializer/Normalizer/FormInvalidNormalizer.php index 84fc714..2d11dad 100644 --- a/src/FormBundle/Serializer/Normalizer/FormInvalidNormalizer.php +++ b/src/FormBundle/Serializer/Normalizer/FormInvalidNormalizer.php @@ -1,4 +1,7 @@ getErrors() as $error) { // @phpstan-ignore-next-line $errors[] = $this->getErrorMessage($error); } - if ($errors) { + + if ($errors !== []) { $form['errors'] = $errors; } + $children = []; foreach ($data->all() as $child) { if ($child instanceof FormInterface) { $children[$child->getName()] = $this->convertFormToArray($child); } } - if ($children) { + + if ($children !== []) { $form['children'] = $children; } + return $form; } - private function getErrorMessage(FormError $error): string + private function getErrorMessage(FormError $formError): string { - if (null !== $error->getMessagePluralization()) { + if (null !== $formError->getMessagePluralization()) { // @phpstan-ignore-next-line - return $this->translator->transChoice($error->getMessageTemplate(), $error->getMessagePluralization(), $error->getMessageParameters(), 'validators'); + return $this->translator->transChoice($formError->getMessageTemplate(), $formError->getMessagePluralization(), $formError->getMessageParameters(), 'validators'); } - return $this->translator->trans($error->getMessageTemplate(), $error->getMessageParameters(), 'validators'); + + return $this->translator->trans($formError->getMessageTemplate(), $formError->getMessageParameters(), 'validators'); } } diff --git a/src/FormHandler.php b/src/FormHandler.php index d05782c..d6ad8a6 100644 --- a/src/FormHandler.php +++ b/src/FormHandler.php @@ -10,6 +10,9 @@ use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; +/** + * @see \Symftony\FormHandler\Tests\FormHandlerTest + */ class FormHandler { protected FormFactoryInterface $formFactory; @@ -77,7 +80,7 @@ private function postSubmit(FormInterface $form): mixed } $transformationFailure = $form->getTransformationFailure(); - if ($transformationFailure && $formConfig->hasOption('handler_transformation_failed')) { + if ($transformationFailure instanceof \Symfony\Component\Form\Exception\TransformationFailedException && $formConfig->hasOption('handler_transformation_failed')) { $failed = $formConfig->getOption('handler_transformation_failed'); if (true === $failed) { throw new TransformationFailedFormException($form, 'Transformation form failed.', 0, $transformationFailure); diff --git a/tests/Form/Extension/Invalid/Type/InvalidTypeExtensionTest.php b/tests/Form/Extension/Invalid/Type/InvalidTypeExtensionTest.php index db7fb70..28e016b 100644 --- a/tests/Form/Extension/Invalid/Type/InvalidTypeExtensionTest.php +++ b/tests/Form/Extension/Invalid/Type/InvalidTypeExtensionTest.php @@ -10,7 +10,7 @@ use Symftony\FormHandler\Form\Extension\Invalid\Type\InvalidTypeExtension; use Symfony\Component\OptionsResolver\OptionsResolver; -class InvalidTypeExtensionTest extends TestCase +final class InvalidTypeExtensionTest extends TestCase { use ProphecyTrait; @@ -18,14 +18,14 @@ class InvalidTypeExtensionTest extends TestCase private InvalidTypeExtension $invalidTypeExtension; - public function setUp(): void + protected function setUp(): void { $this->optionsResolverMock = $this->prophesize(OptionsResolver::class); $this->invalidTypeExtension = new InvalidTypeExtension(); } - public function testConfigureOptions() + public function testConfigureOptions(): void { $this->optionsResolverMock ->setDefaults([ @@ -37,8 +37,8 @@ public function testConfigureOptions() $this->invalidTypeExtension->configureOptions($this->optionsResolverMock->reveal()); } - public function testGetExtendedType() + public function testGetExtendedType(): void { - $this->assertEquals([FormType::class], $this->invalidTypeExtension->getExtendedTypes()); + $this->assertSame([FormType::class], $this->invalidTypeExtension->getExtendedTypes()); } } diff --git a/tests/Form/Extension/NotSubmitted/Type/NotSubmittedTypeExtensionTest.php b/tests/Form/Extension/NotSubmitted/Type/NotSubmittedTypeExtensionTest.php index 5cd8d20..86f8732 100644 --- a/tests/Form/Extension/NotSubmitted/Type/NotSubmittedTypeExtensionTest.php +++ b/tests/Form/Extension/NotSubmitted/Type/NotSubmittedTypeExtensionTest.php @@ -10,7 +10,7 @@ use Symfony\Component\OptionsResolver\OptionsResolver; use Symftony\FormHandler\Form\Extension\NotSubmitted\Type\NotSubmittedTypeExtension; -class NotSubmittedTypeExtensionTest extends TestCase +final class NotSubmittedTypeExtensionTest extends TestCase { use ProphecyTrait; @@ -18,14 +18,14 @@ class NotSubmittedTypeExtensionTest extends TestCase private NotSubmittedTypeExtension $notSubmittedTypeExtension; - public function setUp(): void + protected function setUp(): void { $this->optionsResolverMock = $this->prophesize(OptionsResolver::class); $this->notSubmittedTypeExtension = new NotSubmittedTypeExtension(); } - public function testConfigureOptions() + public function testConfigureOptions(): void { $this->optionsResolverMock ->setDefaults([ @@ -37,8 +37,8 @@ public function testConfigureOptions() $this->notSubmittedTypeExtension->configureOptions($this->optionsResolverMock->reveal()); } - public function testGetExtendedType() + public function testGetExtendedType(): void { - $this->assertEquals([FormType::class], $this->notSubmittedTypeExtension->getExtendedTypes()); + $this->assertSame([FormType::class], $this->notSubmittedTypeExtension->getExtendedTypes()); } } diff --git a/tests/Form/Extension/TransformationFailed/Type/TransformationFailedTypeExtensionTest.php b/tests/Form/Extension/TransformationFailed/Type/TransformationFailedTypeExtensionTest.php index b43e77f..5d80836 100644 --- a/tests/Form/Extension/TransformationFailed/Type/TransformationFailedTypeExtensionTest.php +++ b/tests/Form/Extension/TransformationFailed/Type/TransformationFailedTypeExtensionTest.php @@ -10,22 +10,22 @@ use Symfony\Component\OptionsResolver\OptionsResolver; use Symftony\FormHandler\Form\Extension\TransformationFailed\Type\TransformationFailedTypeExtension; -class TransformationFailedTypeExtensionTest extends TestCase +final class TransformationFailedTypeExtensionTest extends TestCase { use ProphecyTrait; private OptionsResolver|ObjectProphecy $optionsResolverMock; - private TransformationFailedTypeExtension $notSubmittedTypeExtension; + private TransformationFailedTypeExtension $transformationFailedTypeExtension; - public function setUp(): void + protected function setUp(): void { $this->optionsResolverMock = $this->prophesize(OptionsResolver::class); - $this->notSubmittedTypeExtension = new TransformationFailedTypeExtension(); + $this->transformationFailedTypeExtension = new TransformationFailedTypeExtension(); } - public function testConfigureOptions() + public function testConfigureOptions(): void { $this->optionsResolverMock ->setDefaults([ @@ -34,11 +34,11 @@ public function testConfigureOptions() ->willReturn($this->optionsResolverMock->reveal()) ->shouldBeCalled(); - $this->notSubmittedTypeExtension->configureOptions($this->optionsResolverMock->reveal()); + $this->transformationFailedTypeExtension->configureOptions($this->optionsResolverMock->reveal()); } - public function testGetExtendedType() + public function testGetExtendedType(): void { - $this->assertEquals([FormType::class], $this->notSubmittedTypeExtension->getExtendedTypes()); + $this->assertSame([FormType::class], $this->transformationFailedTypeExtension->getExtendedTypes()); } } diff --git a/tests/FormBundle/DependencyInjection/Compiler/FormHandlerCompilerPassTest.php b/tests/FormBundle/DependencyInjection/Compiler/FormHandlerCompilerPassTest.php index 035c83e..62980e0 100644 --- a/tests/FormBundle/DependencyInjection/Compiler/FormHandlerCompilerPassTest.php +++ b/tests/FormBundle/DependencyInjection/Compiler/FormHandlerCompilerPassTest.php @@ -9,7 +9,7 @@ use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Definition; -class FormHandlerCompilerPassTest extends TestCase +final class FormHandlerCompilerPassTest extends TestCase { use ProphecyTrait; @@ -17,14 +17,14 @@ class FormHandlerCompilerPassTest extends TestCase private FormHandlerCompilerPass $formHandlerCompilerPass; - public function setUp(): void + protected function setUp(): void { $this->containerBuilder = new ContainerBuilder(); $this->formHandlerCompilerPass = new FormHandlerCompilerPass(); } - public function testProcessThrowLogicException() + public function testProcessThrowLogicException(): void { $this->expectException(\LogicException::class); $this->expectExceptionMessage('Form factory expected for "form.handler" tagged services.'); @@ -36,7 +36,7 @@ public function testProcessThrowLogicException() $this->formHandlerCompilerPass->process($this->containerBuilder); } - public function testProcess() + public function testProcess(): void { $formFactoryDefinition = new Definition(); diff --git a/tests/FormBundle/FormHandlerBundleTest.php b/tests/FormBundle/FormHandlerBundleTest.php index 38a86fb..e164e2d 100644 --- a/tests/FormBundle/FormHandlerBundleTest.php +++ b/tests/FormBundle/FormHandlerBundleTest.php @@ -8,26 +8,26 @@ use Symftony\FormHandler\FormBundle\FormHandlerBundle; use Symfony\Component\DependencyInjection\ContainerBuilder; -class FormHandlerBundleTest extends TestCase +final class FormHandlerBundleTest extends TestCase { private ContainerBuilder $containerBuilder; private FormHandlerBundle $formHandlerBundle; - public function setUp(): void + protected function setUp(): void { $this->containerBuilder = new ContainerBuilder(); $this->formHandlerBundle = new FormHandlerBundle(); } - public function testBuild() + public function testBuild(): void { $this->formHandlerBundle->build($this->containerBuilder); $containFormHandlerCompilerPass = false; - foreach ($this->containerBuilder->getCompilerPassConfig()->getPasses() as $passe) { - if ($passe instanceof FormHandlerCompilerPass) { + foreach ($this->containerBuilder->getCompilerPassConfig()->getPasses() as $compilerPass) { + if ($compilerPass instanceof FormHandlerCompilerPass) { $containFormHandlerCompilerPass = true; break; } diff --git a/tests/FormHandlerTest.php b/tests/FormHandlerTest.php index 2a71c1b..f5561a7 100644 --- a/tests/FormHandlerTest.php +++ b/tests/FormHandlerTest.php @@ -15,7 +15,7 @@ use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; -class FormHandlerTest extends TestCase +final class FormHandlerTest extends TestCase { use ProphecyTrait; @@ -27,7 +27,7 @@ class FormHandlerTest extends TestCase private FormHandler $formHandler; - public function setUp(): void + protected function setUp(): void { $this->formFactoryMock = $this->prophesize(FormFactoryInterface::class); $this->formConfigMock = $this->prophesize(FormConfigInterface::class); @@ -36,7 +36,7 @@ public function setUp(): void $this->formHandler = new FormHandler(); } - public function testCreateNamedForm() + public function testCreateNamedForm(): void { $this->formFactoryMock ->createNamed('my_fake_name', 'my_fake_type', 'my_fake_data', ['my_fake_options']) @@ -46,7 +46,7 @@ public function testCreateNamedForm() $this->formHandler->createForm('my_fake_type', 'my_fake_name', 'my_fake_data', ['my_fake_options']); } - public function testCreateForm() + public function testCreateForm(): void { $this->formFactoryMock ->create('my_fake_type', 'my_fake_data', ['my_fake_options']) @@ -56,7 +56,7 @@ public function testCreateForm() $this->formHandler->createForm('my_fake_type', null, 'my_fake_data', ['my_fake_options']); } - public function testHandleRequestThrowNotSubmittedFormException() + public function testHandleRequestThrowNotSubmittedFormException(): void { $this->expectException(NotSubmittedFormException::class); $this->expectExceptionMessage('Not submitted form.'); @@ -89,7 +89,7 @@ public function testHandleRequestThrowNotSubmittedFormException() $this->formHandler->handleRequest($this->formMock->reveal(), 'my_fake_request'); } - public function testHandleRequestNotSubmitted() + public function testHandleRequestNotSubmitted(): void { $this->formMock ->handleRequest('my_fake_request') @@ -116,10 +116,10 @@ public function testHandleRequestNotSubmitted() ->willReturn('my_fake_handler_not_submitted_data') ->shouldBeCalled(); - $this->assertEquals('my_fake_handler_not_submitted_data', $this->formHandler->handleRequest($this->formMock->reveal(), 'my_fake_request')); + $this->assertSame('my_fake_handler_not_submitted_data', $this->formHandler->handleRequest($this->formMock->reveal(), 'my_fake_request')); } - public function testHandleRequestThrowInvalidFormException() + public function testHandleRequestThrowInvalidFormException(): void { $this->expectException(InvalidFormException::class); $this->expectExceptionMessage('Invalid form'); @@ -157,7 +157,7 @@ public function testHandleRequestThrowInvalidFormException() $this->formHandler->handleRequest($this->formMock->reveal(), 'my_fake_request'); } - public function testHandleRequestInvalid() + public function testHandleRequestInvalid(): void { $this->formMock ->handleRequest('my_fake_request') @@ -189,10 +189,10 @@ public function testHandleRequestInvalid() ->willReturn('my_fake_handler_invalid_data') ->shouldBeCalled(); - $this->assertEquals('my_fake_handler_invalid_data', $this->formHandler->handleRequest($this->formMock->reveal(), 'my_fake_request')); + $this->assertSame('my_fake_handler_invalid_data', $this->formHandler->handleRequest($this->formMock->reveal(), 'my_fake_request')); } - public function testHandleRequestThrowTransformationFailedFormException() + public function testHandleRequestThrowTransformationFailedFormException(): void { $this->expectException(TransformationFailedFormException::class); $this->expectExceptionMessage('Transformation form failed.'); @@ -235,7 +235,7 @@ public function testHandleRequestThrowTransformationFailedFormException() $this->formHandler->handleRequest($this->formMock->reveal(), 'my_fake_request'); } - public function testHandleRequestTransformationFailed() + public function testHandleRequestTransformationFailed(): void { $this->formMock ->handleRequest('my_fake_request') @@ -273,10 +273,10 @@ public function testHandleRequestTransformationFailed() ->willReturn('my_fake_handler_transformation_failed_data') ->shouldBeCalled(); - $this->assertEquals('my_fake_handler_transformation_failed_data', $this->formHandler->handleRequest($this->formMock->reveal(), 'my_fake_request')); + $this->assertSame('my_fake_handler_transformation_failed_data', $this->formHandler->handleRequest($this->formMock->reveal(), 'my_fake_request')); } - public function testHandleRequest() + public function testHandleRequest(): void { $this->formMock ->handleRequest('my_fake_request') @@ -308,10 +308,10 @@ public function testHandleRequest() ->willReturn('my_fake_form_data') ->shouldBeCalled(); - $this->assertEquals('my_fake_form_data', $this->formHandler->handleRequest($this->formMock->reveal(), 'my_fake_request')); + $this->assertSame('my_fake_form_data', $this->formHandler->handleRequest($this->formMock->reveal(), 'my_fake_request')); } - public function testHandleDataThrowNotSubmittedFormException() + public function testHandleDataThrowNotSubmittedFormException(): void { $this->expectException(NotSubmittedFormException::class); $this->expectExceptionMessage('Not submitted form.'); @@ -339,7 +339,7 @@ public function testHandleDataThrowNotSubmittedFormException() $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_request']); } - public function testHandleDataNotSubmitted() + public function testHandleDataNotSubmitted(): void { $this->formMock->getConfig() ->willReturn($this->formConfigMock) @@ -361,10 +361,10 @@ public function testHandleDataNotSubmitted() ->willReturn('my_fake_handler_not_submitted_data') ->shouldBeCalled(); - $this->assertEquals('my_fake_handler_not_submitted_data', $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_request'])); + $this->assertSame('my_fake_handler_not_submitted_data', $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_request'])); } - public function testHandleDataThrowInvalidFormException() + public function testHandleDataThrowInvalidFormException(): void { $this->expectException(InvalidFormException::class); $this->expectExceptionMessage('Invalid form.'); @@ -408,7 +408,7 @@ public function testHandleDataThrowInvalidFormException() $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_key' => 'my_fake_request_value'], true); } - public function testHandleDataInvalid() + public function testHandleDataInvalid(): void { $this->formMock->getConfig() ->willReturn($this->formConfigMock) @@ -446,10 +446,10 @@ public function testHandleDataInvalid() ->willReturn('my_fake_handler_invalid_data') ->shouldBeCalled(); - $this->assertEquals('my_fake_handler_invalid_data', $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_key' => 'my_fake_request_value'], true)); + $this->assertSame('my_fake_handler_invalid_data', $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_key' => 'my_fake_request_value'], true)); } - public function testHandleDataThrowTransformationFailedFormException() + public function testHandleDataThrowTransformationFailedFormException(): void { $this->expectException(TransformationFailedFormException::class); $this->expectExceptionMessage('Transformation form failed.'); @@ -497,7 +497,7 @@ public function testHandleDataThrowTransformationFailedFormException() $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_key' => 'my_fake_request_value'], true); } - public function testHandleDataTransformationFailed() + public function testHandleDataTransformationFailed(): void { $this->formMock->getConfig() ->willReturn($this->formConfigMock) @@ -539,10 +539,10 @@ public function testHandleDataTransformationFailed() ->willReturn('my_fake_handler_transformation_failed_data') ->shouldBeCalled(); - $this->assertEquals('my_fake_handler_transformation_failed_data', $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_key' => 'my_fake_request_value'], true)); + $this->assertSame('my_fake_handler_transformation_failed_data', $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_key' => 'my_fake_request_value'], true)); } - public function testHandleData() + public function testHandleData(): void { $this->formMock->getConfig() ->willReturn($this->formConfigMock) @@ -580,6 +580,6 @@ public function testHandleData() ->willReturn('my_fake_form_data') ->shouldBeCalled(); - $this->assertEquals('my_fake_form_data', $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_key' => 'my_fake_request_value'], true)); + $this->assertSame('my_fake_form_data', $this->formHandler->handleData($this->formMock->reveal(), ['my_fake_key' => 'my_fake_request_value'], true)); } }