Skip to content

Deprecate at() matcher #4297

@sebastianbergmann

Description

@sebastianbergmann

The behaviour of at() is confusing. Using at() leads to brittle tests at best and lying tests at worst. The documentation even states:

The $index parameter for the at() matcher refers to the index, starting at zero, in all method invocations for a given mock object. Exercise caution when using this matcher as it can lead to brittle tests which are too closely tied to specific implementation details.

Furthermore, the implementation of at() impedes improvements to other aspects of the test doubles support in PHPUnit, see #4291 (comment) for example.

We should therefore deprecate

  • PHPUnit\Framework\TestCase::at() (as well as the PHPUnit\Framework\at() wrapper)
  • PHPUnit\Framework\MockObject\Rule\InvokedAtIndex

in PHPUnit 9 and remove it in PHPUnit 10.

If we realize that a mechanism for specifying the order in which expected invocations occur then, and only then, shall we think about how to best implement this. A replacement for at() is explicitly outside the scope of this deprecation.

Metadata

Metadata

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions