From 6d83daa2bf949d4440fcdec7a721ec23446c6655 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Sat, 6 Aug 2022 13:22:50 +0000 Subject: [PATCH 1/3] Add `errors` and `valid` to FormView stub --- src/Stubs/common/Component/Form/FormView.stubphp | 5 ++++- tests/acceptance/acceptance/forms/FormView.feature | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/Stubs/common/Component/Form/FormView.stubphp b/src/Stubs/common/Component/Form/FormView.stubphp index d92f09a9..d64973e1 100644 --- a/src/Stubs/common/Component/Form/FormView.stubphp +++ b/src/Stubs/common/Component/Form/FormView.stubphp @@ -3,6 +3,7 @@ namespace Symfony\Component\Form; use Symfony\Component\Form\Exception\BadMethodCallException; +use Symfony\Component\Form\FormErrorIterator; /** * @template T @@ -13,11 +14,13 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable * @psalm-suppress MixedArrayAssignment * @psalm-suppress InvalidArrayOffset * - * @psalm-var array{value: ?T, attr: array}&array + * @psalm-var array{value: ?T, attr: array, errors: ?FormErrorIterator, valid: bool}&array */ public array $vars = [ 'value' => null, 'attr' => [], + 'errors' => null, + 'valid' => false, ]; /** diff --git a/tests/acceptance/acceptance/forms/FormView.feature b/tests/acceptance/acceptance/forms/FormView.feature index 68dae868..3ca0f725 100644 --- a/tests/acceptance/acceptance/forms/FormView.feature +++ b/tests/acceptance/acceptance/forms/FormView.feature @@ -28,6 +28,12 @@ Feature: Form view $viewData = $view->vars['value']; /** @psalm-trace $viewData */ + $valid = $view->vars['valid']; + /** @psalm-trace $valid */ + + $errors = $view->vars['errors']; + /** @psalm-trace $errors */ + // assert no errors $view->vars['random'] = new \stdClass(); @@ -44,6 +50,8 @@ Feature: Form view | Trace | $parentView: Symfony\Component\Form\FormView\|null | | Trace | $children: array | | Trace | $viewData: User\|null | + | Trace | $valid: bool | + | Trace | $errors: Symfony\Component\Form\FormErrorIterator\|null | | Trace | $attr: array | And I see no other errors From 95b38cc081e9548e0ded97b26e1c2083646d9f1e Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Thu, 11 Aug 2022 12:06:04 +0000 Subject: [PATCH 2/3] Fix PHP-CS-Fixer complaints --- src/Handler/ContainerHandler.php | 1 + src/Test/CodeceptionModule.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Handler/ContainerHandler.php b/src/Handler/ContainerHandler.php index ce167fcc..d24df3a0 100644 --- a/src/Handler/ContainerHandler.php +++ b/src/Handler/ContainerHandler.php @@ -3,6 +3,7 @@ namespace Psalm\SymfonyPsalmPlugin\Handler; use function constant; + use PhpParser\Node\Arg; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Identifier; diff --git a/src/Test/CodeceptionModule.php b/src/Test/CodeceptionModule.php index 37bd9f44..68538e56 100644 --- a/src/Test/CodeceptionModule.php +++ b/src/Test/CodeceptionModule.php @@ -168,7 +168,7 @@ public function configureCommonPsalmconfig(string $configuration = ''): void XML -); + ); } private function loadTemplate(string $templateName, string $rootDirectory, string $cacheDirectory): void From 8a859ac72204fb9a89c5260ec8cff07577a55ab9 Mon Sep 17 00:00:00 2001 From: Matthias Pigulla Date: Thu, 8 Sep 2022 13:20:39 +0000 Subject: [PATCH 3/3] Add extra vars --- src/Handler/ContainerHandler.php | 1 - .../common/Component/Form/FormView.stubphp | 15 +++++- src/Test/CodeceptionModule.php | 2 +- .../acceptance/forms/FormView.feature | 49 +++++++++++++++++++ 4 files changed, 63 insertions(+), 4 deletions(-) diff --git a/src/Handler/ContainerHandler.php b/src/Handler/ContainerHandler.php index d24df3a0..ce167fcc 100644 --- a/src/Handler/ContainerHandler.php +++ b/src/Handler/ContainerHandler.php @@ -3,7 +3,6 @@ namespace Psalm\SymfonyPsalmPlugin\Handler; use function constant; - use PhpParser\Node\Arg; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Identifier; diff --git a/src/Stubs/common/Component/Form/FormView.stubphp b/src/Stubs/common/Component/Form/FormView.stubphp index d64973e1..19c9c2e7 100644 --- a/src/Stubs/common/Component/Form/FormView.stubphp +++ b/src/Stubs/common/Component/Form/FormView.stubphp @@ -14,13 +14,24 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable * @psalm-suppress MixedArrayAssignment * @psalm-suppress InvalidArrayOffset * - * @psalm-var array{value: ?T, attr: array, errors: ?FormErrorIterator, valid: bool}&array + * @psalm-var array{value: ?T, attr: array, errors: ?FormErrorIterator, valid: bool, data: ?mixed, required: bool, label_attr: array, help: ?string, help_attr: array, help_html: bool, help_translation_parameters: array, compound: bool, method: string, action: string, submitted: bool}&array */ public array $vars = [ 'value' => null, 'attr' => [], 'errors' => null, - 'valid' => false, + 'valid' => true, + 'data' => null, + 'required' => false, + 'label_attr' => [], + 'help' => null, + 'help_attr' => [], + 'help_html' => false, + 'help_translation_parameters' => [], + 'compound' => false, + 'method' => 'POST', + 'action' => '', + 'submitted' => false, ]; /** diff --git a/src/Test/CodeceptionModule.php b/src/Test/CodeceptionModule.php index 68538e56..37bd9f44 100644 --- a/src/Test/CodeceptionModule.php +++ b/src/Test/CodeceptionModule.php @@ -168,7 +168,7 @@ public function configureCommonPsalmconfig(string $configuration = ''): void XML - ); +); } private function loadTemplate(string $templateName, string $rootDirectory, string $cacheDirectory): void diff --git a/tests/acceptance/acceptance/forms/FormView.feature b/tests/acceptance/acceptance/forms/FormView.feature index 3ca0f725..50e9f5cf 100644 --- a/tests/acceptance/acceptance/forms/FormView.feature +++ b/tests/acceptance/acceptance/forms/FormView.feature @@ -3,6 +3,7 @@ Feature: Form view Background: Given I have Symfony plugin enabled + Scenario: FormView test Given I have the following code """ @@ -34,6 +35,42 @@ Feature: Form view $errors = $view->vars['errors']; /** @psalm-trace $errors */ + $valid = $view->vars['valid']; + /** @psalm-trace $valid */ + + $data = $view->vars['data']; + /** @psalm-trace $data */ + + $required = $view->vars['required']; + /** @psalm-trace $required */ + + $label_attr = $view->vars['label_attr']; + /** @psalm-trace $label_attr */ + + $help = $view->vars['help']; + /** @psalm-trace $help */ + + $help_attr = $view->vars['help_attr']; + /** @psalm-trace $help_attr */ + + $help_html = $view->vars['help_html']; + /** @psalm-trace $help_html */ + + $help_translation_parameters = $view->vars['help_translation_parameters']; + /** @psalm-trace $help_translation_parameters */ + + $compound = $view->vars['compound']; + /** @psalm-trace $compound */ + + $method = $view->vars['method']; + /** @psalm-trace $method */ + + $action = $view->vars['action']; + /** @psalm-trace $action */ + + $submitted = $view->vars['submitted']; + /** @psalm-trace $submitted */ + // assert no errors $view->vars['random'] = new \stdClass(); @@ -53,5 +90,17 @@ Feature: Form view | Trace | $valid: bool | | Trace | $errors: Symfony\Component\Form\FormErrorIterator\|null | | Trace | $attr: array | + | Trace | $valid: bool | + | Trace | $data: mixed\|null | + | Trace | $required: bool | + | Trace | $label_attr: array | + | Trace | $help: string\|null | + | Trace | $help_attr: array | + | Trace | $help_html: bool | + | Trace | $help_translation_parameters: array | + | Trace | $compound: bool | + | Trace | $method: string | + | Trace | $action: string | + | Trace | $submitted: bool | And I see no other errors