Quantcast
Viewing all articles
Browse latest Browse all 296229

Fix strict type errors in unit tests

Problem/Motivation

This is a child issue of #3376057: [META] Add declare(strict_types = 1) to all tests. After adding enabling strict types to all tests there were around 3000 errors. Fixing them all in one issue will lead to an enormous merge request that's difficult to review, as per the issue scope guidelines.

Steps to reproduce

Create the rector.php file:

<?php

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;

return static function (RectorConfig $rectorConfig): void {
  $rectorConfig->rule(DeclareStrictTypesRector::class);
  $rectorConfig->skip([
    DeclareStrictTypesRector::class => [
      __DIR__ . '/core/tests/Drupal/Tests/Composer/ComposerIntegrationTrait.php',
      __DIR__ . '/core/tests/Drupal/Tests/Listeners/',
      __DIR__ . '/core/tests/Drupal/Tests/Component/DependencyInjection/Fixture/',
      __DIR__ . '/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/fixtures',
      __DIR__ . '/core/tests/Drupal/Tests/Traits',
    ],
  ]);
};

Process all unit tests:

composer require rector/rector --dev
find core/tests/Drupal/Tests/ -type d -mindepth 1 -maxdepth 1 | xargs php vendor/bin/rector process
find core -type d -path "core/*/tests/src/Unit" | xargs php vendor/bin/rector process

Run the test suite:

./vendor/bin/phpunit -c core/phpunit.xml.dist --bootstrap=core/tests/bootstrap.php --testsuite=unit

Proposed resolution

Remaining tasks

Review updated MR

User interface changes

API changes

Data model changes

Release notes snippet


Viewing all articles
Browse latest Browse all 296229

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>