Problem/Motivation

setUp() methods in tests need a void return type for D10 compatibility.

Proposed resolution

Add them.

Remaining tasks

  1. Wait until we no longer support versions of Drupal that run on versions of PHP that don't handle return types.
  2. Review / re-test.
  3. Commit.

User interface changes

N/A

API changes

Only in tests.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

pavnish created an issue. See original summary.

dww’s picture

Thanks for opening this.

Please combine all such "replace AssertLegacyTrait:*" into a single issue (here). We don't want/need separate issues for each kind of assertion.

Cheers,
-Derek

dww’s picture

(As a reasonable rule of thumb -- if core put all the changes in a single CR, all those changes can be fixed in a single issue in a contrib). ;)

Thanks again,
-Derek

pavnish’s picture

Title: Replace usages of AssertLegacyTrait::assertTitle, that is deprecated. » Replace usages of deprecated method, that is deprecated.
Issue summary: View changes
pavnish’s picture

Title: Replace usages of deprecated method, that is deprecated. » Replace usages of deprecated method in tests, that is deprecated.
pavnish’s picture

@dww sorry i have not found any "AssertLegacyTrait" deprecation I have found only these deprecation errors that is related to setup method i also apologies for was created the issue with wrong tittle it's was a confusion :

Could you please conform that we can change the issue title according to setup method:
I am adding the patch for the same.

6x: Declaring ::setUp without a void return typehint in Drupal\Tests\address\FunctionalJavascript\AddressDefaultWidgetTest is deprecated in drupal:9.0.0. Typehinting will be required before drupal:10.0.0. See https://www.drupal.org/node/3114724
6x in DrupalListener::startTest from Drupal\Tests\Listeners

5x: Declaring ::setUp without a void return typehint in Drupal\Tests\address\Unit\Plugin\Validation\Constraint\CountryConstraintValidatorTest is deprecated in drupal:9.0.0. Typehinting will be required before drupal:10.0.0. See https://www.drupal.org/node/3114724
5x in DrupalListener::startTest from Drupal\Tests\Listeners

4x: Declaring ::setUp without a void return typehint in Drupal\Tests\address\Functional\Views\AdministrativeAreaFilterTest is deprecated in drupal:9.0.0. Typehinting will be required before drupal:10.0.0. See https://www.drupal.org/node/3114724
4x in DrupalListener::startTest from Drupal\Tests\Listeners

4x: Declaring ::setUp without a void return typehint in Drupal\Tests\address\Kernel\Formatter\AddressDefaultFormatterTest is deprecated in drupal:9.0.0. Typehinting will be required before drupal:10.0.0. See https://www.drupal.org/node/3114724
4x in DrupalListener::startTest from Drupal\Tests\Listeners

2x: Declaring ::setUp without a void return typehint in Drupal\Tests\address\Functional\Views\CountrySortTest is deprecated in drupal:9.0.0. Typehinting will be required before drupal:10.0.0. See https://www.drupal.org/node/3114724
2x in DrupalListener::startTest from Drupal\Tests\Listeners

2x: Declaring ::setUp without a void return typehint in Drupal\Tests\address\Kernel\CountryNameTokenTest is deprecated in drupal:9.0.0. Typehinting will be required before drupal:10.0.0. See https://www.drupal.org/node/3114724
2x in DrupalListener::startTest from Drupal\Tests\Listeners

2x: Declaring ::setUp without a void return typehint in Drupal\Tests\address\Kernel\Formatter\AddressPlainFormatterTest is deprecated in drupal:9.0.0. Typehinting will be required before drupal:10.0.0. See https://www.drupal.org/node/3114724
2x in DrupalListener::startTest from Drupal\Tests\Listeners

1x: Declaring ::setUp without a void return typehint in Drupal\Tests\address\Kernel\Formatter\CountryDefaultFormatterTest is deprecated in drupal:9.0.0. Typehinting will be required before drupal:10.0.0. See https://www.drupal.org/node/3114724
1x in DrupalListener::startTest from Drupal\Tests\Listeners

1x: Declaring ::setUp without a void return typehint in Drupal\Tests\address\Kernel\ZoneItemTest is deprecated in drupal:9.0.0. Typehinting will be required before drupal:10.0.0. See https://www.drupal.org/node/3114724
1x in DrupalListener::startTest from Drupal\Tests\Listeners

dww’s picture

Title: Replace usages of deprecated method in tests, that is deprecated. » Add void return types to test setUp() methods for D10 compatibility
Issue summary: View changes
Status: Needs review » Postponed
Issue tags: -Needs issue rescope, -Needs issue summary update

@pavnish: Okay, thanks.

The issue summary template is useful. You got it by default when you created this issue, but you deleted it. ;)

Anyway, marking this postponed for now, and added this as the first remaining task:

  • Wait until we no longer support versions of Drupal that run on versions of PHP that don't handle return types.

I don't want to commit this now, since it'll break for sites trying to test on Drupal 8.8 with PHP 7.0.

Cheers,
-Derek

bojanz’s picture

Opened #3185437: Drop support for Drupal 8.8.x and PHP 7.0 for dropping 8.8 support. We now have a 1.9 release with 8.8 support, so the next one could be 8.9+.
I'm also fine with bumping the min PHP version to 7.1, since I believe 8.9 didn't do that.

bojanz’s picture

Title: Add void return types to test setUp() methods for D10 compatibility » Fix Drupal 9.1 deprecations
Status: Postponed » Active

Let's continue tackling the other failures here too.

Pushed a commit for the AssertLegacyTrait errors.

Build: https://www.drupal.org/pift-ci-job/1898641

Other messages:

Calling the Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch() method with a string event name as the first argument in AddressDefaultFormatterTest
Calling the Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch() method with a string event name as the first argument in AdministrativeAreaFilterTest

The AddressFieldTest::$modules property must be declared protected.
The AddressDefaultFormatterTest::$modules property must be declared protected.
The CountryDefaultFormatterTest::$modules property must be declared protected.
The CountryNameTokenTest::$modules property must be declared protected.
The DefaultValueTest::$modules property must be declared protected.
The ZoneItemTest::$modules property must be declared protected.

Current research:
Some $modules deprecations can't be fixed while we support D8. For example, the ZoneItemTest one since the test extends EntityKernelTestBase.

EventDispatcher deprecations are also tricky: https://www.drupal.org/node/3159012, probably best to leave for a D9-only future.

  • bojanz committed 3f0d579 on 8.x-1.x
    Issue #3163415 part 1: Fix Drupal 9.1 deprecations
    
bojanz’s picture

Pushed a commit for the $modules warnings, since, that's the time I'll have for the next 7 days.

That and the AssertLegacyTrait commit have brought us down from 12 to 9 failures: https://www.drupal.org/pift-ci-job/1898649

And here's the build for the setUp patch from #6: https://www.drupal.org/pift-ci-job/1898650

Looks like I forgot to fix $modules in CountryNameTokenTest, so that's an easy fix for next time.

Pooja Ganjage’s picture

Hi,

Creating a patch for this issue and added protected modifier that are missing.

Please review the patch.

Thanks.

Pooja Ganjage’s picture

Status: Active » Needs review
bojanz’s picture

Committed #3185437: Drop support for Drupal 8.8.x and PHP 7.0.

#12 can't work because it's modifying ZoneItemTest. Mentioned that in #9.

Here's a patch without that part.

bojanz’s picture

Can't touch CountryNameTokenTest either...

  • bojanz committed ccf9250 on 8.x-1.x authored by pavnish
    Issue #3163415 by bojanz, pavnish, dww: Fix Drupal 9.1 deprecations
    
bojanz’s picture

Status: Needs review » Fixed

We're down from 9 deprecation fails to 6 now. I think this is as far as we can get while still supporting Drupal 8.9.

Gave commit credit to pavnish since the commit is the same as their initial patch.

Status: Fixed » Closed (fixed)

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

yang_yi_cn’s picture

can we reopen this? at least needs a different branch / release that works with Drupal 9.1 / 9.2, currently it basically doesn't support Drupal 9.1 / 9.2.

dww’s picture

@yang_yi_cn: What do you mean? The deprecations here are things that will be removed in Drupal 10. This module absolutely works with Drupal core 9.1 and 9.2. If it generates some deprecation notices about D10, you can disable those messages or learn to ignore them. ;)

Cheers,
-Derek

yang_yi_cn’s picture

The auto test does show errors like this in D9.1 (and not in D8.9):

 7x: Calling the Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch() method with a string event name as the first argument is deprecated in drupal:9.1.0, an Event object will be required instead in drupal:10.0.0. See https://www.drupal.org/node/3154407

Basically https://www.drupal.org/node/3154407 says

The signature of Symfony\Component\EventDispatcher\EventDispatcherInterface::dispatch() has changed.

Before:

$event_dispatcher->dispatch($event_name, Event $event = NULL);

After:

$event_dispatcher->dispatch(Event $event, $event_name = NULL);

The order of $event and $event_name is switched, this is introduced in D9.1 / Symfony 4.x.

I actually confused this with another deprecation notice, which is about the Event class, that will be deprecated in D10 / Symfony 5.

But the dispatch event order thing I believe is something needs to be fixed now.