comparator icon indicating copy to clipboard operation
comparator copied to clipboard

Expose ObjectComparator as non-internal

Open stof opened this issue 2 months ago • 1 comments

ObjectComparator has an inheritance-based extension point through its protected toArray method, which is a handy way of ignoring some properties when comparing objects (when that property is storing a cache for a computation for instance, and equality of object should not matter whether both objects have already run that computation at least once or not at all). See https://github.com/Behat/Gherkin/blob/d4a49d07c39c3bf4940b531849037fcdcbd0ac4b/tests/Cucumber/StepNodeComparator.php for such usage in the behat/gherkin testsuite.

If such usage is a supported use case (which would be nice), the ObjectComparator should not be an internal class but exposed in the public API.

stof avatar Oct 27 '25 16:10 stof

I have another use case in Prophecy that currently extends the ObjectComparator, but I think it could be implemented using composition instead. (as it overrides the assertEquals method to change the arguments passed to the parent).

Edit: this one has been refactored in Prophecy 1.23.1

stof avatar Oct 27 '25 16:10 stof