Problem/Motivation

In order to be able to use Guzzle 6 on PHP 8.1 we need the ability to skip E_DEPRECATED deprecations so we can skip:
Return type of GuzzleHttp\Cookie\CookieJar::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Return type of GuzzleHttp\Cookie\CookieJar::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
Unfortunately it doesn't seem that the Guzzle team want to release a new version of Guzzle 6. We will upgrade to Guzzle 7 in Drupal 10 and might change our dependencies to allow Guzzle 7 with Drupal 9 but this is the easiest fix to do for PHP 8.1 compatibility in Drupal 9.3.

Steps to reproduce

Run (for example) Drupal\Tests\content_translation\Functional\ContentTranslationSettingsTest

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
FileSize
2.41 KB

Patch attached is from the meta. It allows us to skip deprecations caused by Guzzle and EasyRDF. EasyEDF has a PR to fix PHP 8.1 deprecations but that's not landed yet. If it does we can remove the skip.

I'm thinking about the best way to add a test for this. The fact that tests fail on PHP 8.1 is a kind of test but it might be good to have something explicit. User-land code is not allowed to do trigger_error('some text', E_DEPRECATED) - you get a warning... Warning: Uncaught ValueError: trigger_error(): Argument #2 ($error_level) must be one of E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE, or E_USER_DEPRECATED

alexpott’s picture

Here's a test. Seems okay to add this note it will only trigger the deprecation on PHP 8.1 so to prove it fails there you need to run the test manually at this point we still are triggering too many deprecation on PHP 8.1.

Here's the output of running the test without the changes to \Drupal\Tests\Listeners\DeprecationListenerTrait...

./vendor/bin/phpunit -v core/tests/Drupal/Tests/SkippedDeprecationTest.php 
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.1.0RC3-dev
Configuration: /Users/alex/dev/sites/drupal8alt.dev/phpunit.xml
Warning:       Your XML configuration validates against a deprecated schema.
Suggestion:    Migrate your XML configuration using "--migrate-configuration"!

Testing Drupal\Tests\SkippedDeprecationTest
...                                                                 3 / 3 (100%)

Time: 00:00.025, Memory: 10.00 MB

OK (3 tests, 3 assertions)

Remaining self deprecation notices (1)

  1x: Return type of PhpDeprecation::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
    1x in SkippedDeprecationTest::testSkippingPhpDeprecations from Drupal\Tests
alexpott’s picture

Arggh the mink deprecations get in the way...

andypost’s picture

Status: Needs review » Reviewed & tested by the community

Thank you, this patch makes it easy to run all other tests

Running test with test-only patch

vendor/bin/phpunit -c core/phpunit.xml.dist --colors=always --debug -v \
core/tests/Drupal/Tests/SkippedDeprecationTest.php
PHPUnit 8.5.21 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.1.0RC3
Configuration: /var/www/html/web/core/phpunit.xml.dist

Testing Drupal\Tests\SkippedDeprecationTest
Test 'Drupal\Tests\SkippedDeprecationTest::testSkippingDeprecations' started
Test 'Drupal\Tests\SkippedDeprecationTest::testSkippingDeprecations' ended
Test 'Drupal\Tests\SkippedDeprecationTest::testSkippingDeprecationsAgain' started
Test 'Drupal\Tests\SkippedDeprecationTest::testSkippingDeprecationsAgain' ended
Test 'Drupal\Tests\SkippedDeprecationTest::testSkippingPhpDeprecations' started
Test 'Drupal\Tests\SkippedDeprecationTest::testSkippingPhpDeprecations' ended


Time: 566 ms, Memory: 6.00 MB

OK (3 tests, 3 assertions)

Remaining self deprecation notices (1)

  1x: Return type of PhpDeprecation::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice
    1x in SkippedDeprecationTest::testSkippingPhpDeprecations from Drupal\Tests

using patch it pass

vendor/bin/phpunit -c core/phpunit.xml.dist --colors=always --debug -v \
core/tests/Drupal/Tests/SkippedDeprecationTest.php
PHPUnit 8.5.21 by Sebastian Bergmann and contributors.

Runtime:       PHP 8.1.0RC3
Configuration: /var/www/html/web/core/phpunit.xml.dist

Testing Drupal\Tests\SkippedDeprecationTest
Test 'Drupal\Tests\SkippedDeprecationTest::testSkippingDeprecations' started
Test 'Drupal\Tests\SkippedDeprecationTest::testSkippingDeprecations' ended
Test 'Drupal\Tests\SkippedDeprecationTest::testSkippingDeprecationsAgain' started
Test 'Drupal\Tests\SkippedDeprecationTest::testSkippingDeprecationsAgain' ended
Test 'Drupal\Tests\SkippedDeprecationTest::testSkippingPhpDeprecations' started
Test 'Drupal\Tests\SkippedDeprecationTest::testSkippingPhpDeprecations' ended


Time: 292 ms, Memory: 6.00 MB

OK (3 tests, 3 assertions)
andypost’s picture

Status: Reviewed & tested by the community » Needs review

ignore this comment

andypost’s picture

Running core/modules/content_translation/tests/src/Functional/ContentTranslationSettingsTest.php

OK (4 tests, 103 assertions)

Unsilenced deprecation notices (184)

  181x: strtolower(): Passing null to parameter #1 ($string) of type string is deprecated
    107x in ContentTranslationSettingsTest::testSettingsUI from Drupal\Tests\content_translation\Functional
    31x in ContentTranslationSettingsTest::testAccountLanguageSettingsUI from Drupal\Tests\content_translation\Functional
    31x in ContentTranslationSettingsTest::testFieldTranslatableSettingsUI from Drupal\Tests\content_translation\Functional
    12x in ContentTranslationSettingsTest::testNonTranslatableTranslationSettingsUI from Drupal\Tests\content_translation\Functional

  3x: htmlspecialchars(): Passing null to parameter #1 ($string) of type string is deprecated
    3x in ContentTranslationSettingsTest::testSettingsUI from Drupal\Tests\content_translation\Functional
daffie’s picture

Status: Needs review » Needs work

The testbot is failing for PHP 8.1 rc2 and it should be failing for the test only patch.

alexpott’s picture

Status: Needs work » Needs review

@daffie this is just part of the fixes. The test only patch is to help people run it locally without the fix.

This patch is ready and will help us have green functional tests once we've sorted out behat/mink.

daffie’s picture

Status: Needs review » Needs work

The patch looks good to me, just one remark for me:

+++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
@@ -76,6 +76,15 @@ public static function isDeprecationSkipped($message) {
+      // Skip Symfony deprecations for PHP 8.1 -  fixed by
+      // https://github.com/symfony/symfony/pull/42260.
+      '%Return type of Symfony\\\\Component\\\\.* should either be compatible with .*, or the #\[\\\\ReturnTypeWillChange\] attribute should be used to temporarily suppress the notice%',

This change should already be fixed in version v4.4.30 which is used in core now. See: https://github.com/symfony/symfony/pull/42260.

alexpott’s picture

Status: Needs work » Needs review
FileSize
1.26 KB
4.01 KB

@daffie great catch... nice one.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

Adds the suppressions of 2 from dependency packages coming deprecation warnings and a test suppressing deprecation warning from PHP itself.
Looks good to me.

  • catch committed f56323a on 9.3.x
    Issue #3240456 by alexpott, andypost, daffie: Allow E_DEPRECATED...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Looks good.

Committed f56323a and pushed to 9.3.x. Thanks!

Status: Fixed » Closed (fixed)

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