Resolve PHPStan Errors and PHPUnit 10 Compatibility Issues in Drupal 11+

Created on 27 January 2025, 4 months ago

Problem/Motivation

PHPStan analysis in the Drupal 11 codebase reveals several errors, primarily caused by:

  • Usage of deprecated functions, such as views_field_default_views_data().
  • Non-static data provider methods, which are no longer supported in PHPUnit 10.
  • Invalid @covers annotations with non-fully qualified method names.

Resolving these errors is essential for maintaining compatibility with Drupal 12 and ensuring clean, functional code.

Steps to reproduce

  1. Run PHPStan using the configuration file located at: /builds/project/og/web/modules/custom/og/phpstan.neon.
  2. Observe the reported errors, such as:
    • Deprecated function calls (e.g., views_field_default_views_data()).
    • PHPUnit 10-specific issues like non-static data providers.
    • Invalid @covers annotations.

Proposed resolution

  1. Replace deprecated function calls with their recommended alternatives. For example:
    • Use:
      \Drupal::service('views.field_data_provider')->defaultFieldImplementation($field_storage);
              

      instead of views_field_default_views_data().

  2. Update PHPUnit test cases to meet the requirements of PHPUnit 10:
    • Make all data provider methods static.
    • Ensure @covers annotations reference fully qualified method names.
    • Fix or remove invalid @dataProvider references.
  3. Run PHPStan and PHPUnit to verify all issues are resolved.

Remaining tasks

  • Identify all deprecated function calls and replace them with supported alternatives.
  • Fix all PHPUnit-related issues in the test files.
  • Verify changes by running PHPStan and PHPUnit.
๐Ÿ“Œ Task
Status

Active

Version

1.0

Component

og.module

Created by

๐Ÿ‡จ๐Ÿ‡ฆCanada joelpittet Vancouver

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024