Enforce strict types in tests

Created on 9 November 2023, 8 months ago
Updated 10 April 2024, 3 months ago

Problem/Motivation

Once all other tasks of 📌 Add declare(strict_types=1) to all tests Needs work are done we can enforce strict types in tests.

Steps to reproduce

N/A

Proposed resolution

Add the following to phpcs.xml.dist

  <rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
    <properties>
      <property name="spacesCountAroundEqualsSign" value="0" />
    </properties>
    <include-pattern>*/tests/*</include-pattern>
  </rule>

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Postponed

Version

11.0 🔥

Component
PHPUnit  →

Last updated about 8 hours ago

Created by

🇦🇺Australia mstrelan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @mstrelan
  • @mstrelan opened merge request.
  • 🇦🇺Australia mstrelan

    Current status (assuming Kernel tests gets in soon):

    <include-pattern>*/tests/*</include-pattern>
    <exclude-pattern>*/tests/modules/*</exclude-pattern>
    <exclude-pattern>*/tests/themes/*</exclude-pattern>
    <exclude-pattern>*/tests/*_test/*</exclude-pattern>
    <exclude-pattern>*/tests/*fixture*/*</exclude-pattern>
    
    • 📌 Add declare(strict_types=1) to all test modules Postponed should take care of the first two exclude patterns.
    • We need another issue for test themes, I think they are all in core/modules/system/tests/themes/
    • We need another issue for fixtures, although maybe we should continue to ignore them

    That leaves the following that need to be categorised:

    core/modules/comment/src/Tests/CommentTestTrait.php
    core/modules/contact/tests/drupal-7.contact.database.php
    core/modules/filter/tests/filter_test_plugin/src/Plugin/Filter/FilterSparkles.php
    core/modules/filter/tests/filter_test_plugin/src/Plugin/Filter/FilterTestStatic.php
    core/modules/menu_link_content/tests/menu_link_content_dynamic_route/src/Routes.php
    core/modules/migrate_drupal/src/Tests/StubTestTrait.php
    core/modules/node/tests/node_access_test_auto_bubbling/src/Controller/NodeAccessTestAutoBubblingController.php
    core/modules/system/tests/http.php
    core/modules/system/tests/https.php
    core/modules/views/src/Tests/AssertViewsCacheTagsTrait.php
    core/modules/views/src/Tests/TestHelperPlugin.php
    core/modules/views/src/Tests/ViewResultAssertionTrait.php
    core/modules/views/src/Tests/ViewTestData.php
    core/tests/bootstrap.php
    
    • Possibly the Traits and Views classes should move to the tests dir in each module, unless there is some reason they need to live in src/Tests instead.
    • We should make sure to capture filter_test_plugin, menu_link_content_dynamic_route and node_access_test_auto_bubbling in 📌 Add declare(strict_types=1) to all test modules Postponed , or move them to a test/modules directory first
    • Not too sure about the remaining non-class php files, I guess we should be ok to include them
Production build 0.69.0 2024