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>
</UnnecessaryVarAnnotation>
</file>
<file src="src/Test/CodeceptionModule.php">
<UnusedPsalmSuppress occurrences="1">
<code>NonInvariantDocblockPropertyType</code>
</UnusedPsalmSuppress>
</file>
</files>

View File

@ -13,7 +13,7 @@ class FormView implements \ArrayAccess, \IteratorAggregate, \Countable
* @psalm-suppress MixedArrayAssignment
* @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 = [
'value' => null,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -1,5 +1,5 @@
@symfony-form
Feature: Form events
@symfony-common
Feature: Form view
Background:
Given I have the following config
@ -14,6 +14,9 @@ Feature: Form events
<plugins>
<pluginClass class="Psalm\SymfonyPsalmPlugin\Plugin"/>
</plugins>
<issueHandlers>
<UnusedVariable errorLevel="info"/>
</issueHandlers>
</psalm>
"""
Scenario: FormView test
@ -38,12 +41,16 @@ Feature: Form events
$children = $view->children;
/** @psalm-trace $children */
$viewData = $view->vars['value'];
/** @psalm-trace $viewData */
// assert no errors
$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
| Type | Message |
| 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 | $attr: array<array-key, mixed> |
And I see no other errors