Problem/Motivation

There are two mocking frameworks used in Drupal core. Both are shipped by PHPUnit. Prophecy is the modern one.

Personally, I prefer mocking with Prophecy. So I would suggest promoting Prophecy and stick with it in Drupal core.

In general:

  • Code writing in Prophecy is elegant than writing in PHPUnit mocks
  • Prophecy has better readability
  • Prophecy is extendable
  • New comers only need to know Prophecy, do not have to know both
  • For those who already get familiar with PHPUnit mocks, it should be easy switching to Prophecy even though it's new to them
  • If one of them is chosen by core, it means no other choice, at some times, no choice is the best choice.

Proposed resolution

  1. Deprecate PHPUnit mocks, and replace existed usages by using Prophecy.
  2. It's hard to have a proper scope, as this is kind of code refactoring. Maybe doing it module by module or component by component is better.

Remaining tasks

Needs discussion:

  1. Is this worthy doing?
  2. If it's worthy, what's the policy/scope for filing child issues?

User interface changes

API changes

Data model changes

Release notes snippet

Comments

jungle created an issue. See original summary.

mondrake’s picture

Just a note that while working on PHPUnit 9 support in #3127141: Use PHPUnit 9 for PHP 7.4+, while keeping support for PHPUnit 8.4 in PHP 7.3, we are coming across a deprecation

PHPUnit\Framework\TestCase::prophesize() is deprecated and will be removed in PHPUnit 10. Please use the trait provided by phpspec/prophecy-phpunit.

Do not know yet, but maybe that needs to be taken into account here.

jungle’s picture

@mondrake, thanks for your note!

phpspec/prophecy-phpunit as the replacement/workaround should be workable at that time when PHPUnit 10 is out. See the issue filed by the author of PHPUnit Make sure phpspec/prophecy-phpunit continues to work with PHPUnit 10 #4149

One more note:

IMHO a trait would be simpler

A trait cannot override verifyMockObjects().

-- https://github.com/sebastianbergmann/phpunit/issues/4141#issuecomment-60...

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

andypost’s picture

phpunit no longer depends on prophecy because it has weak support, see #3314632: upgrade phpspec/prophecy to 1.16.0 to support PHP 8.2

andypost’s picture

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

andypost’s picture

Looking back at PHP 8.3 compatibility and facing incompatibilities with PHP 8.4 (initial adoption) I'd better close it as wont fix

each time prophecy mocks are late for new PHP version compatibility https://github.com/phpspec/prophecy/issues/624

andypost’s picture

prophecy again is very slow on new PHP version compatibility

quietone’s picture

Status: Active » Closed (won't fix)

As @andypost points out in #12, PHPUnit has deprecated the use of prophecy. He also points out that Prophecy has been slow up updating to newer versions of PHP. Therefore, let's stay with PHPUnit mocks and not make conversions to prophecy.

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.