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 configuring expectations using expects() on test stubs #5535

Closed
sebastianbergmann opened this issue Oct 8, 2023 · 0 comments
Closed
Assignees
Labels
feature/test-doubles Test Stubs and Mock Objects type/deprecation Something will be/is deprecated
Milestone

Comments

@sebastianbergmann
Copy link
Owner

sebastianbergmann commented Oct 8, 2023

PHPUnit\Framework\TestCase provides methods for dynamically creating two types of test doubles: test stubs and mock objects:

  • createStub()
  • createStubForIntersectionOfInterfaces()
  • createConfiguredStub()
  • createMock()
  • createMockForIntersectionOfInterfaces()
  • createConfiguredMock()
  • createPartialMock()

The methods for creating test stubs, createStub($type) for example, are documented to return Stub&$type whereas the methods for creating mock objects, createMock($type) for example, are documented to return MockObject&$type.

However, the methods for creating test stubs generate and return MockObject&$type for legacy reasons at the moment. This means that the expects() method is currently available on objects created using createStub(), for example. This allows the configuration of mock object expectations on objects that are created using a method where its name implies the intent of creating a test stub. However, expectations configured on test stubs created using createStub(), for example, are not verified.

Timeline

  • deprecation in PHPUnit 11 (calling expects() on a test double created using a method for creating test stubs triggers a deprecation)
  • removal in PHPUnit 12 (calling expects() on a test double created using a method for creating test stubs triggers an error)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/test-doubles Test Stubs and Mock Objects type/deprecation Something will be/is deprecated
Projects
None yet
Development

No branches or pull requests

1 participant