-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make exporter configurable #5773
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5773 +/- ##
============================================
- Coverage 90.14% 90.06% -0.08%
- Complexity 6585 6598 +13
============================================
Files 693 696 +3
Lines 19943 19966 +23
============================================
+ Hits 17977 17983 +6
- Misses 1966 1983 +17 ☔ View full report in Codecov by Sentry. |
while I agree that a configurable exporter can have benefit for specific use-cases, I would expect the "default exporter" to be fast enough, so I don't need to structure my unit test arround a "limitation" of phpunit, that objects/arrays in data-providers are not efficient enough. no offense on this end - just my point of view. |
None taken.
Sure! As I said before, I am not doing this for performance. sebastianbergmann/exporter#55 is likely a more appropriate solution for performance issues. |
Isn't it better architecture here to have a Factory where one can add multiple exporters (in a config file, probably? or a bootstrap file?) that are called for each type? E.g. class ExporterFactory
{
public function addExporter(ExporterInterface $exporter) { ... }
public function getExporterForValue(mixed $value) {
foreach($this->exporters as $exporter) {
if($exporter->supports($value)) return $exporter;
}
return $this->defaultExporter;
}
} That way doctrine can create their own exporter, I can make my own, etc. |
@BladeMF I wanted to keep this as simple as possible, but will ponder your suggestion. |
In this implementation I have two questions:
|
That is what I mean by "Make alternative implementation of PHPUnit\Util\Exporter configurable via PHPUnit's XML configuration file" in #5773 (comment).
Currently not, but I will ponder that. |
Thanks for looking into it. |
|
I just created |
I slept on it and now think that |
Agree. I also wonder whether all callsites of |
Here is a proof-of-concept change for |
Sounds reasonable. |
PHPUnit uses
SebastianBergmann\Exporter\Exporter
fromsebastian/exporter
to export variables as strings, for instance when generating comparison failure messages or when creating immutable value objects representing tests and their data (from data providers) that are passed through the event system to internal as well as third-party subscribers.In order to allow for the customization of the textual representation of comparison failures, to improve performance (using
SebastianBergmann\Exporter\Exporter
is expensive when large data structures are involved), and for other use cases it would be nice ifSebastianBergmann\Exporter\Exporter
could be swapped for a different implementation.PHPUnit\Util\Exporter
interfacePHPUnit\Util\DefaultExporter
as the default implementation ofPHPUnit\Util\Exporter
that simply wrapsSebastianBergmann\Exporter\Exporter
PHPUnit\Util\ExporterFacade
that usesPHPUnit\Util\DefaultExporter
by default, but can be configured to use an alternative implementation ofPHPUnit\Util\Exporter
PHPUnit\Util\ExporterChain
for chainingPHPUnit\Util\Exporter
implementationsExporterFacade::instance()->export()
instead ofSebastianBergmann\Exporter\Exporter::export()
PHPUnit\Util\Exporter
configurable via PHPUnit's XML configuration fileSebastianBergmann\Exporter\Exporter::shortenedRecursiveExport()
andSebastianBergmann\Exporter\Exporter::shortenedExport
should also be wrappedSebastianBergmann\Exporter\Exporter
insebastian/comparator
should also be configurable