Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate support for doubling multiple interfaces #3955

Closed
sebastianbergmann opened this issue Nov 24, 2019 · 1 comment
Closed

Deprecate support for doubling multiple interfaces #3955

sebastianbergmann opened this issue Nov 24, 2019 · 1 comment
Assignees
Milestone

Comments

@sebastianbergmann
Copy link
Owner

The methods

  • getMockBuilder()
  • createMock()
  • createConfiguredMock()
  • createPartialMock()

currently support the creation of test doubles that implement multiple interfaces that are passed as an array of interface names for their first argument.

This functionality should be deprecated as "having to use it" is almost always a symptom of bad design. More importantly, though, the support for the creation of test doubles that implement multiple interfaces resulted in code that is hard to maintain.

@someniatko
Copy link

@sebastianbergmann I think this feature should stay. For example, there could be an interface which extends Traversable. However, if you mock this interface only, you have no option of actually implementing its Traversable behavior. Therefore, your mock must implement both the given interface, AND either Iterator or IteratorAggregate.

Second reason for this to stay is that in future PHP will most probably have intersection types (it already has union types in PHP 8.0)

fabpot added a commit to symfony/symfony that referenced this issue Sep 7, 2020
…bus)

This PR was merged into the 4.4 branch.

Discussion
----------

Don't call createMock with an array of interfaces

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | #37564
| License       | MIT
| Doc PR        | N/A

PHPUnit 8 allows us to pass an array of interfaces to `createMock()`. The result was a mock object that implemented all of the given interfaces. This feature has sadly been removed (see sebastianbergmann/phpunit#3955), which forces us to create dummy classes that can be mocked instead. I've done this already on the 3.4 branch with #37566.

This PR fixes all affected tests (that I could find) on the 4.4 branch.

Commits
-------

a8e762d Don't call createMock with an array of interfaces.
nickvergessen added a commit to nextcloud/server that referenced this issue Apr 20, 2021
2) Test\Support\Subscription\RegistryTest::testDelegateIsHardUserLimitReachedWithoutSupportAppAndUserCount with data set #0 (35, 15, 2, false)
Cannot stub or mock class or interface "Test\Support\Subscription\UserInterface" which does not exist

3) Test\Support\Subscription\RegistryTest::testDelegateIsHardUserLimitReachedWithoutSupportAppAndUserCount with data set #1 (35, 45, 15, false)
Cannot stub or mock class or interface "Test\Support\Subscription\UserInterface" which does not exist

4) Test\Support\Subscription\RegistryTest::testDelegateIsHardUserLimitReachedWithoutSupportAppAndUserCount with data set #2 (35, 45, 5, true)
Cannot stub or mock class or interface "Test\Support\Subscription\UserInterface" which does not exist

5) Test\Support\Subscription\RegistryTest::testDelegateIsHardUserLimitReachedWithoutSupportAppAndUserCount with data set #3 (35, 45, 55, false)
Cannot stub or mock class or interface "Test\Support\Subscription\UserInterface" which does not exist

Had to use the Database user backend, as using multiple interfaces is deprecated:
sebastianbergmann/phpunit#3955
> This functionality should be deprecated as "having to use it" is almost always a symptom of bad design.
> More importantly, though, the support for the creation of test doubles that implement multiple interfaces
> resulted in code that is hard to maintain.

Signed-off-by: Joas Schilling <coding@schilljs.com>
Spea added a commit to rebuy-de/serializer-jms-adapter that referenced this issue Jun 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants