You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The PHPUnit at() matcher, used to determine the order that methods are called on test doubles, has been deprecated. It will be removed in PHPUnit 10. You should refactor your tests to not rely on the order in which methods are invoked. The best replacement depends on how the method was used in the test previously:
Order of method calls
Where at() was used only to enforce the order of calls:
Testing specific call order with specific parameters
Where the order of calls is important and we have expectations about what is passed:
$this->messenger->expects($this->at(0))
->method('addError')
->with('no title given');
$this->messenger->expects($this->at(1))
->method('addError')
->with('element is invisible');
$this->messenger->expects($this->at(2))
->method('addError')
->with('this missing element is invalid');
$this->messenger->expects($this->at(3))
->method('addError')
->with('3 errors have been found: <ul-comma-list-mock><li-mock>Test 1</li-mock><li-mock>Test 2 & a half</li-mock><li-mock>Test 3</li-mock></ul-comma-list-mock>');
We can test for the correct number of calls and use withConsecutive():
$this->messenger->expects($this->exactly(4))
->method('addError')
->withConsecutive(
['no title given', FALSE],
['element is invisible', FALSE],
['this missing element is invalid', FALSE],
['3 errors have been found: <ul-comma-list-mock><li-mock>Test 1</li-mock><li-mock>Test 2 & a half</li-mock><li-mock>Test 3</li-mock></ul-comma-list-mock>', FALSE],
);
Testing specific call order with specific parameter and return values
Where both the passed arguments and return values are important:
https://www.drupal.org/node/3218874
Introduced in branch/version: 9.3.x / 9.3.0
The PHPUnit at() matcher, used to determine the order that methods are called on test doubles, has been deprecated. It will be removed in PHPUnit 10. You should refactor your tests to not rely on the order in which methods are invoked. The best replacement depends on how the method was used in the test previously:
Order of method calls
Where
at()
was used only to enforce the order of calls:We can just replace this with the number of times that the method should be called:
Different
with()
andwill()
used on a single methodWhere different
with()
andwill()
values were used on a single method, and the test does not strictly care about the order of the calls:We can convert this to
withReturnMap()
:Testing return values only for non-idempotent method calls
Where the order of the calls is important and we only have return values, e.g. we are testing two different sets of expectations in the same method:
We can test for the correct number of calls and use
willReturnOnConsecutiveCalls()
:Testing specific call order with specific parameters
Where the order of calls is important and we have expectations about what is passed:
We can test for the correct number of calls and use
withConsecutive()
:Testing specific call order with specific parameter and return values
Where both the passed arguments and return values are important:
We can combine
withConsecutive()
andwillReturnOnConsecutiveCalls()
:For more information please see the PHPUnit issue where the deprecation was introduced: sebastianbergmann/phpunit#4297
The text was updated successfully, but these errors were encountered: