Fixes showing files changed in JSON formatter#7808
Fixes showing files changed in JSON formatter#7808peterfox wants to merge 3 commits intorectorphp:mainfrom
Conversation
|
|
||
| public function testReportShouldShowNumberOfChangesWithNoDiffs(): void | ||
| { | ||
| ob_start(); |
There was a problem hiding this comment.
This seems a bit hacky and error prone. Any chance to test output directly without it?
There was a problem hiding this comment.
The output formatter is echo directly, so the only way to get output is via buffer
and the content read will be mixed on phpunit side expected output check.
The other way is by use \n over PHP_EOL on echo, and normalize the rest.
There was a problem hiding this comment.
Okay, I got it, removed the ob_start() hack and fix with trim and re-add PHP_EOL during parent::expectOutputString($expectedOutput) 👍 e1d3d99
There was a problem hiding this comment.
Maybe there could a factory service that creates and returns string and that tested with assertSame()
There was a problem hiding this comment.
The parent::expectOutputString() is simpler imo, see implementation on last commit e1d3d99
no more ob_start() thing as handled in phpunit itself that handle the buffer output internally.
Just added the tweak do to the PHP_EOL enforcement on the echo, so that needs the trim and re-add the PHP_EOL
There was a problem hiding this comment.
Overriding protected method seems extra complexity I struggle to read.
I still prefer simple return string
There was a problem hiding this comment.
the method name is different: expectOsOutputString vs expectOutputString
should be private instead :), will update and clear the logic :)
There was a problem hiding this comment.
I've clean up unnecessary new method and just directly normalize it on $this->expectOutputString() 9cc1408 👍
should be ok now 👍
There was a problem hiding this comment.
@TomasVotruba I created alternative PR for use of JsonOutputFactory for testing:
|
This turned into a bit of mess. @peterfox Can you force-push your last changes? I'll look into it to get this finished .) |
9cc1408 to
908372a
Compare
This reverts commit e9b5a0f.
908372a to
66a267b
Compare
|
@TomasVotruba I've rebased and force pushed the original code |
|
Thank you 👍 I'll look into it and finish it |
|
@TomasVotruba just for note, this also may need check on see my note at separate PR |
Changes
Why
Currently running
./vendor/bin/rector --output-format=json --no-diffsyou will only get the count of how many files changed. This change will show the list as well.{ "totals": { "changed_files": 1, "errors": 0 }, "changed_files": [ "some/file.php", ], }See discussion in #7807
Notes
Rushed this one together, if I can improve the test or the way we determine to show the diff when it's an empty string, feedback would be greatly appreciated.