Fix tests and a var annotation (#166)

* Add tests and fix var

* Run form tests on ci

* Ignore unused errors

* Fix
This commit is contained in:
Vincent Langlet 2021-03-29 13:36:50 +02:00 committed by GitHub
parent 567d5d6e32
commit e363384dfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
42 changed files with 157 additions and 28 deletions

View File

@ -6,4 +6,9 @@
<code>string</code> <code>string</code>
</UnnecessaryVarAnnotation> </UnnecessaryVarAnnotation>
</file> </file>
<file src="src/Test/CodeceptionModule.php">
<UnusedPsalmSuppress occurrences="1">
<code>NonInvariantDocblockPropertyType</code>
</UnusedPsalmSuppress>
</file>
</files> </files>

View File

@ -13,7 +13,7 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
* @psalm-suppress MixedArrayAssignment * @psalm-suppress MixedArrayAssignment
* @psalm-suppress InvalidArrayOffset * @psalm-suppress InvalidArrayOffset
* *
* @psalm-var array<string, mixed>&array{value: ?T, attr: array<array-key, mixed>, string} * @psalm-var array{value: ?T, attr: array<array-key, mixed>}&array<string, mixed>
*/ */
public array $vars = [ public array $vars = [
'value' => null, 'value' => null,

View File

@ -19,7 +19,10 @@ use Twig\Loader\FilesystemLoader;
*/ */
class CodeceptionModule extends BaseModule class CodeceptionModule extends BaseModule
{ {
/** @var array<string,string> */ /**
* @var mixed[]
* @psalm-suppress NonInvariantDocblockPropertyType
*/
protected $config = [ protected $config = [
'default_dir' => 'tests/_run/', 'default_dir' => 'tests/_run/',
]; ];

View File

@ -13,6 +13,9 @@ Feature: AbstractController
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """

View File

@ -16,6 +16,9 @@ Feature: Annotation class
<containerXml>../../tests/acceptance/container.xml</containerXml> <containerXml>../../tests/acceptance/container.xml</containerXml>
</pluginClass> </pluginClass>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """

View File

@ -14,6 +14,9 @@ Feature: AuthenticatorInterface
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """

View File

@ -14,6 +14,9 @@ Feature: CacheInterface
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedClosureParam errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """

View File

@ -13,6 +13,9 @@ Feature: ConsoleArgument
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
And I have the following code preamble And I have the following code preamble

View File

@ -13,6 +13,10 @@ Feature: ConsoleOption
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedParam errorLevel="info"/>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
And I have the following code preamble And I have the following code preamble

View File

@ -13,6 +13,9 @@ Feature: ConstraintValidator
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """

View File

@ -16,6 +16,9 @@ Feature: ContainerDependency
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """

View File

@ -15,6 +15,9 @@ Feature: Container service
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """

View File

@ -17,6 +17,9 @@ Feature: Container XML config
<containerXml>../../tests/acceptance/container.xml</containerXml> <containerXml>../../tests/acceptance/container.xml</containerXml>
</pluginClass> </pluginClass>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """

View File

@ -15,6 +15,9 @@ Feature: Denormalizer interface
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """

View File

@ -14,6 +14,9 @@ Feature: Doctrine QueryBuilder
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
And I have the following code preamble And I have the following code preamble

View File

@ -14,6 +14,9 @@ Feature: Messenger Envelope
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
And I have the following code preamble And I have the following code preamble

View File

@ -14,6 +14,9 @@ Feature: Header get
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedFunctionCall errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
And I have the following code preamble And I have the following code preamble

View File

@ -13,6 +13,10 @@ Feature: InputBag get return type
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedFunctionCall errorLevel="info"/>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
And I have the following code preamble And I have the following code preamble

View File

@ -13,6 +13,9 @@ Feature: LockableTrait
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """

View File

@ -17,6 +17,9 @@ Feature: Naming conventions
<containerXml>../../tests/acceptance/container.xml</containerXml> <containerXml>../../tests/acceptance/container.xml</containerXml>
</pluginClass> </pluginClass>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """

View File

@ -13,6 +13,10 @@ Feature: PropertyAccessorInterface
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
<UnusedFunctionCall errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
And I have the following code preamble And I have the following code preamble

View File

@ -14,6 +14,10 @@ Feature: PropertyPathInterface
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedParam errorLevel="info"/>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
And I have the following code preamble And I have the following code preamble

View File

@ -14,13 +14,13 @@ Feature: RepositoryStringShortcut
<ignoreFiles> <directory name="../../vendor"/> </ignoreFiles> <ignoreFiles> <directory name="../../vendor"/> </ignoreFiles>
</projectFiles> </projectFiles>
<issueHandlers>
<UndefinedClass errorLevel="info" />
</issueHandlers>
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
<UndefinedClass errorLevel="info" />
</issueHandlers>
</psalm> </psalm>
""" """
And I have the following code preamble And I have the following code preamble

View File

@ -15,6 +15,9 @@ Feature: Request getContent
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedFunctionCall errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
And I have the following code preamble And I have the following code preamble

View File

@ -16,6 +16,9 @@ Feature: Annotation class
<containerXml>../../tests/acceptance/container.xml</containerXml> <containerXml>../../tests/acceptance/container.xml</containerXml>
</pluginClass> </pluginClass>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """

View File

@ -14,6 +14,9 @@ Feature: RouteCollection
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
And I have the following code preamble And I have the following code preamble

View File

@ -15,6 +15,9 @@ Feature: Serializer interface
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """

View File

@ -16,6 +16,9 @@ Feature: Service Subscriber
<containerXml>../../tests/acceptance/container.xml</containerXml> <containerXml>../../tests/acceptance/container.xml</containerXml>
</pluginClass> </pluginClass>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """

View File

@ -13,6 +13,9 @@ Feature: Tainting
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
And I have the following code preamble And I have the following code preamble

View File

@ -10,15 +10,16 @@ Feature: Test Container service
<directory name="."/> <directory name="."/>
</projectFiles> </projectFiles>
<issueHandlers>
<PropertyNotSetInConstructor errorLevel="info" />
</issueHandlers>
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin">
<containerXml>../../tests/acceptance/container.xml</containerXml> <containerXml>../../tests/acceptance/container.xml</containerXml>
</pluginClass> </pluginClass>
</plugins> </plugins>
<issueHandlers>
<PropertyNotSetInConstructor errorLevel="info" />
<UnusedFunctionCall errorLevel="info"/>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """

View File

@ -21,6 +21,9 @@ Feature: Twig tainting with analyzer
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin" /> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin" />
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
And I have the following code preamble And I have the following code preamble

View File

@ -21,6 +21,9 @@ Feature: Twig tainting with cached templates
<twigCachePath>/cache/twig</twigCachePath> <twigCachePath>/cache/twig</twigCachePath>
</pluginClass> </pluginClass>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
And I have the following code preamble And I have the following code preamble

View File

@ -14,6 +14,9 @@ Feature: Voter abstract class
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
And I have the following code preamble And I have the following code preamble

View File

@ -1,4 +1,4 @@
@symfony-form @symfony-common
Feature: FormType templates Feature: FormType templates
Background: Background:
@ -14,6 +14,9 @@ Feature: FormType templates
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
Scenario: Assert FormType is using nullable template value in methods Scenario: Assert FormType is using nullable template value in methods

View File

@ -1,4 +1,4 @@
@symfony-form @symfony-5
Feature: FormType templates Feature: FormType templates
Background: Background:
@ -14,6 +14,9 @@ Feature: FormType templates
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
Scenario: FormExtension::getExtendedTypes must return iterables of FormTypeInterface Scenario: FormExtension::getExtendedTypes must return iterables of FormTypeInterface

View File

@ -1,4 +1,4 @@
@symfony-form @symfony-4, @symfony-5
Feature: Form test Feature: Form test
Background: Background:
@ -14,6 +14,9 @@ Feature: Form test
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
Scenario: Assert that Form::getData() will return nullable type (empty_data failure) Scenario: Assert that Form::getData() will return nullable type (empty_data failure)

View File

@ -1,5 +1,5 @@
@symfony-form @symfony-common
Feature: Form events Feature: Form builder
Background: Background:
Given I have the following config Given I have the following config
@ -14,6 +14,9 @@ Feature: Form events
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
Scenario: Depending of typehinted form event, psalm will know type of data attached Scenario: Depending of typehinted form event, psalm will know type of data attached

View File

@ -1,5 +1,5 @@
@symfony-form @symfony-common
Feature: Form events Feature: Form config builder
Background: Background:
Given I have the following config Given I have the following config
@ -14,6 +14,9 @@ Feature: Form events
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
Scenario: Depending of typehinted form event, psalm will know type of data attached Scenario: Depending of typehinted form event, psalm will know type of data attached

View File

@ -1,5 +1,5 @@
@symfony-form @symfony-common
Feature: Form events Feature: Form config
Background: Background:
Given I have the following config Given I have the following config
@ -14,6 +14,9 @@ Feature: Form events
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
Scenario: FormConfigInterface::getData() will return ?T Scenario: FormConfigInterface::getData() will return ?T

View File

@ -1,5 +1,5 @@
@symfony-form @symfony-common
Feature: Form test Feature: Form factory
Background: Background:
Given I have the following config Given I have the following config
@ -14,6 +14,9 @@ Feature: Form test
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
Scenario: Test factory methods Scenario: Test factory methods

View File

@ -1,5 +1,5 @@
@symfony-form @symfony-common
Feature: Form events Feature: Form interface
Background: Background:
Given I have the following config Given I have the following config
@ -14,6 +14,9 @@ Feature: Form events
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
Scenario: FormInterface test Scenario: FormInterface test

View File

@ -1,5 +1,5 @@
@symfony-form @symfony-common
Feature: Form events Feature: Form view
Background: Background:
Given I have the following config Given I have the following config
@ -14,6 +14,9 @@ Feature: Form events
<plugins> <plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/> <pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins> </plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm> </psalm>
""" """
Scenario: FormView test Scenario: FormView test
@ -38,12 +41,16 @@ Feature: Form events
$children = $view->children; $children = $view->children;
/** @psalm-trace $children */ /** @psalm-trace $children */
$viewData = $view->vars['value']; $viewData = $view->vars['value'];
/** @psalm-trace $viewData */ /** @psalm-trace $viewData */
// assert no errors // assert no errors
$view->vars['random'] = new \stdClass(); $view->vars['random'] = new \stdClass();
$attr = $view->vars['attr'];
/** @psalm-trace $attr */
$view->vars['attr']['placeholder'] = 'test';
$savedValue = $view->vars['attr']['placeholder'];
} }
} }
""" """
@ -51,7 +58,8 @@ Feature: Form events
Then I see these errors Then I see these errors
| Type | Message | | Type | Message |
| Trace | $parentView: Symfony\Component\Form\FormView\|null | | Trace | $parentView: Symfony\Component\Form\FormView\|null |
| Trace | $children: list<Symfony\Component\Form\FormView> | | Trace | $children: array<string, Symfony\Component\Form\FormView> |
| Trace | $viewData: User\|null | | Trace | $viewData: User\|null |
| Trace | $attr: array<array-key, mixed> |
And I see no other errors And I see no other errors