Skip to content

Standardize usages of PHPUnit's assertEquals()#1868

Merged
williamjallen merged 1 commit intoKitware:masterfrom
sbelsk:fix-assertequals-args-order
Dec 10, 2023
Merged

Standardize usages of PHPUnit's assertEquals()#1868
williamjallen merged 1 commit intoKitware:masterfrom
sbelsk:fix-assertequals-args-order

Conversation

@sbelsk
Copy link
Collaborator

@sbelsk sbelsk commented Dec 6, 2023

According to the PHPUnit docs for assertEquals(), the first argument to the function should be the expected output, and the second argument should be the actual value as produced by the test. Currently, we have multiple places in the codebase where this ordering of the arguments is not respected. Calling this function with the arguments swapped can lead to confusion when debugging failed tests, as PHPUnit's error messages present failed comparisons in terms of an "expected" and an "actual" value.

The changes in this PR correct the instances where we use the wrong ordering (except for the file tests/Feature/Monitor.php which is being improved in PR #1826).

There are many other PHPUnit assertion functions that follow this argument format and are used in our test suites. Future PRs will correct the cases for those functions where the argument ordering is not respected as well.

It would also be nice if we could add tools to automatically enforce this, in order to prevent this from happening in the future and improve our development experience.

@sbelsk sbelsk requested a review from williamjallen December 6, 2023 18:04
@sbelsk sbelsk marked this pull request as ready for review December 6, 2023 19:40
@sbelsk sbelsk force-pushed the fix-assertequals-args-order branch from 0b5cacb to 61bf790 Compare December 10, 2023 01:41
@sbelsk sbelsk requested a review from williamjallen December 10, 2023 01:42
@williamjallen williamjallen added this pull request to the merge queue Dec 10, 2023
Merged via the queue into Kitware:master with commit 8ea02ce Dec 10, 2023
@sbelsk sbelsk deleted the fix-assertequals-args-order branch December 14, 2023 18:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Comments