phpunit icon indicating copy to clipboard operation
phpunit copied to clipboard

Exporter configuration - allow setting custom exporter implementation or limiting maximum depth

Open olsavmic opened this issue 3 years ago • 0 comments

Exporter implementation is right now hardcoded in Constraints and Comparators. This works fine in most cases but it becomes unusable in the case of large objects such as Doctrine entities.

When an assertion fails with such objects, the recursive dump may take a lot of time and memory (EntityManager is referenced by Doctrine entities which means pretty much whole identity map is a part of the result).

We're experiencing delays in order of minutes both locally (in PHPStorm, it seems like the TeamCity listener adds some delay when it generates diff) and on CI with raw output. The memory increase is also significant, our CI pods are sometimes killed due to running out of memory (caused only by such dump) which makes it very hard to debug which test/assertion caused the issue.

Surely tests should not fail and be always reproducible but that's simply not 100% true in real projects and it wastes developers time.

We mitigated the issue for most cases by overriding assertNull and providing our own comparator for entities with custom exporter but it does not cover all cases.

I'd very much appreciate a possibility to provide our own instance of exporter or at least provide a configuration option that would limit exporter depth when traversing objects.

Does any of these two options seem viable to you or do you have any other tips? Thank you

olsavmic avatar May 03 '22 13:05 olsavmic