-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Modernize junit report #2964
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
Modernize junit report #2964
Conversation
+ use a generic PHP_CodeSniffer string as name in <testcase> if all sniffs passed + use the filename without extension as classname in <testcase> + move the full filepath from name to file in <testcase> + append line and column to message in <failure>
| echo $cachedData; | ||
| echo '</testsuites>'.PHP_EOL; | ||
|
|
||
| $dom = new \DOMDocument(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please be aware that the DOM extension can be disabled, so may not be available and is currently not a requirement for PHPCS.
The XMLWriter extension and the SimpleXML extension are requirements, so please consider if it's possible to use those instead.
Refs:
Lines 27 to 31 in ce62dee
"require": { "php": ">=5.4.0", "ext-tokenizer": "*", "ext-xmlwriter": "*", "ext-simplexml": "*" PHP_CodeSniffer/src/Runner.php
Lines 246 to 257 in ce62dee
$requiredExtensions = [ 'tokenizer', 'xmlwriter', 'SimpleXML', ]; $missingExtensions = []; foreach ($requiredExtensions as $extension) { if (extension_loaded($extension) === false) { $missingExtensions[] = $extension; } }
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please be aware that the DOM extension can be disabled, so may not be available and is currently not a requirement for PHPCS.
I see. This is my first time writing PHP, so I assumed everything that's on PHP.net is shipped as default.
The XMLWriter extension and the SimpleXML extension are requirements, so please consider if it's possible to use those instead.
That depends on whether you consider consistent indentation important or not.
- If indentation doesn't matter, then all the changes in
generate()can be dropped. - Otherwise, I looked through the docs for XMLWriter and SimpleXML several times but did not find ways to work with the partial XML that's emitted by
generateFileReport(). I couldn't figure out if implementing the echo within this function is essential or if I could just create a class member ofJunitholding the XMLWriter, append content to that during calls ofgenerateFileReport()and echo all of it at the end ofgenerate(). That would also ensure consistent indentation and likely not require DOM.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is my first time writing PHP
Oh wow, respect for taking something like this on straight off the bat in that case 👍
if I could just create a class member of Junit holding the XMLWriter, append content to that during calls of generateFileReport() and echo all of it at the end of generate()
If I remember correctly, the echo in generateFileReport() is needed with how things are set up in PHPCS now, but this may be a legacy from PHP 4 when PHP didn't have a proper object model. (this project is quite old).
The downside of saving it to a class property instead of to a file, would be the memory this would consume, which could be extensive on a large project with lots of violations.
I suppose you could just save the minimum information you need from each file in non-XML format, like is done for the Summary report, and then use the generate() method to parse the saved information and format it the way you want it to be.
Will be less efficient as the data is processed twice, but could possibly get you closer to the intended result.
|
Seeing as this has been open without more interaction or time from my side, I'll close the PR and leave the code online in case someone later wants to refer to it. For the record, we're using it internally because our setup already comes with the discussed optional dependencies. 👍 |
This PR improves on the existing Junit report by implementing further attributes of the spec. I have attached samples of the output as well as examples how the results are parsed by a consumer, in this case GitLab.
classnameandfileare added totestcaseelements--report-file).examples:
Before:


After: