Enforce strict types in tests

Created on 9 November 2023, about 1 year ago
Updated 17 September 2024, 2 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>
    <exclude-pattern>*/fixtures/*</exclude-pattern>
  </rule>

Remaining tasks

  • Review changes to ViewResultAssertionTrait and SortDateTest
  • Review changes to http.php and https.php

User interface changes

API changes

Data model changes

Release notes snippet

📌 Task
Status

Fixed

Version

11.0 🔥

Component
PHPUnit 

Last updated about 2 hours ago

Created by

🇦🇺Australia mstrelan

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

Merge Requests

Comments & Activities

  • Issue created by @mstrelan
  • Merge request !5315Issue #3400434: Enforce strict types in tests → (Closed) created by mstrelan
  • Pipeline finished with Failed
    about 1 year ago
    Total: 164s
    #46686
  • 🇦🇺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
  • Status changed to Active 3 months ago
  • Pipeline finished with Failed
    3 months ago
    Total: 708s
    #264280
  • Pipeline finished with Failed
    3 months ago
    Total: 67s
    #264301
  • Pipeline finished with Failed
    3 months ago
    Total: 605s
    #264302
  • Pipeline finished with Success
    3 months ago
    Total: 546s
    #264315
  • Status changed to Needs review 3 months ago
  • Pipeline finished with Success
    3 months ago
    Total: 779s
    #264496
  • Status changed to RTBC 3 months ago
  • 🇺🇸United States smustgrave

    Yes! Very happy to see this is going to be mandatory now.

    Changes in MR seems fine to me.

    • catch committed f3a63b72 on 11.x
      Issue #3400434 by mstrelan: Enforce strict types in tests
      
  • 🇬🇧United Kingdom catch

    Committed/pushed to 11.x, thanks!

  • Status changed to Fixed 3 months ago
  • 🇳🇿New Zealand quietone

    Since this issue enabled strict types I moved the CR from the parent to here and published it.

  • 🇧🇪Belgium wim leers Ghent 🇧🇪🇪🇺

    Nice! 😄

  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024