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 module with --display-phpunit-notices --display-phpunit-deprecations.
  4. Observe the PHPUnit notices that occur.

Proposed resolution

Fix notices in the field and field_ui modules.

Remaining tasks

Information on how to review these issues and the types of changes you're likely to find in them is included in the parent issue's comments.

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3569420

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

Status: Active » Needs review
dcam’s picture

Issue summary: View changes
smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Kinda like the others I applied the MR
1. Checked that all instances of any() are gone - They are
2. Check the instances of createMock() to see if they can be stubs, there were 5 instances left in Field and they seem to be valid as they call specific functions with specific returns.

Think this one is good to go.

dcam’s picture

Status: Reviewed & tested by the community » Needs work

Needs work due to PHPUnit 12.5.11 and a new deprecation.

dcam’s picture

Issue summary: View changes
Status: Needs work » Needs review

New development: stubs cannot set with(). The IS and MR have been updated.

smustgrave’s picture

Status: Needs review » Needs work

Sorry appears to need a rebase, probably since a few landed this morning!!

dcam’s picture

Status: Needs work » Needs review

Rebased

smustgrave’s picture

Status: Needs review » Needs work

Followed the steps and without the MR I get
Tests: 19, Assertions: 77, PHPUnit Notices: 19.

Running with the MR I got 3 more notices
Test Triggered PHPUnit Notice (Drupal\Tests\field\Unit\FieldUninstallValidatorTest::testValidateDeleted)
Test Triggered PHPUnit Notice (Drupal\Tests\field\Unit\FieldUninstallValidatorTest::testValidateNoStorages)

dcam’s picture

Status: Needs work » Needs review

@smustgrave These additional notices are a result of mocks created by UnitTestCase::getStringTranslationStub(), which contrary to the name returns mock objects, not stubs. These notices will be fixed by #3578904: Convert expectation-less test mocks to stubs - UnitTestCase as they are among the over 500 notices caused by that class and warrant special attention.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Applied the MR from that issue and all notices go away. Thanks for pointing that out.

catch’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Fixed

Committed/pushed to main and 11.x, thanks!

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 456d6175 on 11.x
    task: #3569420 Convert expectation-less test mocks to stubs - Field...

  • catch committed 11f2057c on main
    task: #3569420 Convert expectation-less test mocks to stubs - Field...

  • catch committed fd48d100 on 11.x
    Revert "task: #3569420 Convert expectation-less test mocks to stubs -...
catch’s picture

Version: 11.x-dev » main

11.x wasn't happy with this. Leaving on main.

Status: Fixed » Closed (fixed)

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