Problem/Motivation

PHPUnit 12.5.0+ is changing the way that mock objects work:

  • Mock objects that do not configure expectations should be converted to stubs. Otherwise, they throw a notice: No expectations were configured for the mock object for \Drupal\comment\CommentManagerInterface. You should refactor your test code and use a test stub instead.
  • $this->any() is deprecated. It was equivalent to having no expectation, in which case the object should be a stub (see the previous bullet) or a more exact number of expectations should be added.
  • with() is deprecated for stubs because it was deemed to be equally pointless.

Steps to reproduce

  1. Require PHPUnit 12 with Composer.
  2. Fix compatibility issues with PHPUnit 12 by applying this patch.
  3. Run the Unit tests for a library with --display-phpunit-notices --display-phpunit-deprecations.
  4. Observe the PHPUnit notices that occur.

Proposed resolution

Fix notices in the tests for the following core libraries, which currently only represents 10 affected classes.

  • core/tests/Drupal/Tests/Core/Datetime/
  • core/tests/Drupal/Tests/Core/Utility/
  • core/tests/Drupal/Tests/Core/DrupalTest.php
  • core/tests/Drupal/Tests/Core/PrivateKeyTest.php
  • core/tests/Drupal/Tests/Core/UnroutedUrlTest.php
  • core/tests/Drupal/Tests/Core/UrlTest.php

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3579862

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dcam created an issue. See original summary.

dcam’s picture

Title: Convert expectation-less test mocks to stubs - Datetime library » Convert expectation-less test mocks to stubs - batch 7
Issue summary: View changes

dcam’s picture

Status: Active » Needs review
dcam’s picture

When running these tests without the MR from #3578904: Convert expectation-less test mocks to stubs - UnitTestCase applied I get 118 notices that are unfixed. When I apply the changes from #3578904 there are 0 notices.

dcam’s picture

Title: Convert expectation-less test mocks to stubs - batch 7 » Convert expectation-less test mocks to stubs - Datetime, Utility, and standalone library tests
dcam’s picture

FYI: the recently-committed UnitTestCase changes have been merged into this MR, so they do not need to be applied separately for testing.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Datetime = OK (135 tests, 523 assertions)
Utility = OK (127 tests, 313 assertions)
DrupalTest = OK (34 tests, 117 assertions)
PrivateKeyTest = OK (3 tests, 7 assertions)
UnroutedUrlTest = OK (79 tests, 81 assertions)
UrlTest = OK (109 tests, 241 assertions)

With regards to the variable name change that gets messy and think probably out of scope here. Plus we would have to go back to existing issues if we went that route.

catch’s picture

Status: Reviewed & tested by the community » Fixed

I'm OK with the method name mis-match, this is already a gargantuan task, we can open novice-friendly follow-ups to rename, maybe all at once?

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • catch committed 38040ff5 on main
    task: #3579862 Convert expectation-less test mocks to stubs - Datetime,...

Status: Fixed » Closed (fixed)

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