Problem/Motivation

TestCase::getAnnotations() method was removed in phpunit 9.5: https://github.com/sebastianbergmann/phpunit/commit/68582043e149039cfa35... called in DrupalStandardsListenerTrait::checkValidCoversForTest().

Steps to reproduce

- Update to phpunit 9.5: composer update "phpunit/phpunit ^9" --with-dependencies
- Run any test using phpunit: vendor/bin/phpunit -c core/phpunit.xml.dist core/modules/action/tests/src/Unit

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#2 3186443-1.patch2.51 KBtuutti

Comments

tuutti created an issue. See original summary.

tuutti’s picture

StatusFileSize
new2.51 KB
longwave’s picture

Component: base system » phpunit
Status: Active » Needs review

Thanks! Queued on PHP 7.3 as well, as we are also compatible with PHPUnit 8 (which is used on PHP 7.3 only now) and so need the tests to still run there as well.

marcelovani’s picture

Found the same issue today

marcelovani’s picture

The patch worked fine, in the sense that it fixed the error message.

But it caused another issue:
FATAL Drupal\Tests\boxout\Functional\BoxoutTest: test runner returned a non-zero error code (2)

Steps to reproduce:
- Install Drupal 9
- Run tests without excluding deprecation i.e.

sudo -u www-data php web/core/scripts/run-tests.sh \
	    --php /usr/local/bin/php \
	    --verbose \
	    --keep-results \
	    --color \
	    --concurrency "32" \
	    --repeat "1" \
	    --types "Simpletest,PHPUnit-Unit,PHPUnit-Kernel,PHPUnit-Functional" \
	    --sqlite sites/default/files/.ht.sqlite \
	    --url http://localhost \
	    --directory "modules/contrib/boxout"'

Pre-requisites: the test must contain a check for response code i.e. $this->assertResponse(200, 'Test response');

The results will report this deprecation:

      1x: AssertLegacyTrait::assertResponse() is deprecated in drupal:8.2.0 and
    is removed from drupal:10.0.0. Use
    $this->assertSession()->statusCodeEquals() instead. See
    https://www.drupal.org/node/3129738
        1x in BoxoutTest::testBoxoutArticle from Drupal\Tests\boxout\Functional

Now, change $this->assertResponse() to $this->assertSession()->statusCodeEqual() and re-run the tests

The fatal error happens.

mondrake’s picture

Priority: Normal » Critical
Status: Needs review » Reviewed & tested by the community

Bumping to critical since now the PHP 7.4 and 8 tests are all failing.

IMHO we should consider to set the PHPUnit constraint in composer.json to limit the upper version, PHPUnit are very aggressive in removing internal methods and we may end up with failing tests at any PHPUnit minor.

alexpott’s picture

Version: 9.2.x-dev » 9.1.x-dev
Status: Reviewed & tested by the community » Fixed

@mondrake I think this is fine. I don't think we should have upper constraints here - it'll just stop us from fixing things like this.

@marcelovani the other reported in #5 is because the test is using deprecated code. You could either disable deprecation testing or fix it.

Committed and pushed 754b8ffab2 to 9.2.x and adc897b798 to 9.1.x. Thanks!

  • alexpott committed 754b8ff on 9.2.x
    Issue #3186443 by tuutti, marcelovani: PHPUnit 9.5 Call to undefined...

  • alexpott committed adc897b on 9.1.x
    Issue #3186443 by tuutti, marcelovani: PHPUnit 9.5 Call to undefined...
heddn’s picture

For anyone facing this while core 9.1.1 isn't released... simply dropping back to phpunit 9.4.3 is sufficient to get tests running again.

composer require --dev phpunit/phpunit:9.4.3 --with-all-dependencies

tyler36’s picture

@heddn That works.

Note: You have to be using composer >= 2 to use the --with-all-dependencies switch

Update composer with the following:
composer selfupdate --2

Status: Fixed » Closed (fixed)

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