Skip to content

Deprecate configuring expectations using expects() on test stubs #5535

Closed
@sebastianbergmann

Description

@sebastianbergmann

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)

Metadata

Metadata

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions