Skip to content
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

Allow to print Junit report in human-readable format #154

Closed

Conversation

llaville
Copy link

@llaville llaville commented Jul 7, 2024

Fixes #153

@llaville
Copy link
Author

llaville commented Jul 7, 2024

Introducing the new class ShipMonk\ComposerDependencyAnalyser\Result\AbstractXmlFormatter is in goal context to propose a checkstyle output format support

@JanTvrdik
Copy link
Member

I don't think we need such option. We should just always pretty-print the output.

@llaville
Copy link
Author

llaville commented Jul 8, 2024

I don't think we need such option. We should just always pretty-print the output.

I don't agree with you : my opinion is that

  • even if pretty print format has a ratio size to 20% greater than compact version, it's only used for debugging purpose by a human.
  • when you use with a third-party tool/platform, machine-readable (compact) version is enough.

"ext-json": "*",
"ext-libxml": "*",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep those only soft-required. I dont want to force everybody to have those. Majority uses only console output.

Just detect presence only when junit formatter is used and emit error if not.

use DOMElement;
use ShipMonk\ComposerDependencyAnalyser\Printer;

abstract class AbstractXmlFormatter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently useless.

@@ -245,7 +245,7 @@ public function initFormatter(CliOptions $options): ResultFormatter
throw new InvalidConfigException("Cannot use 'junit' format with '--dump-usages' option.");
}

return new JunitFormatter($this->cwd, $this->stdOutPrinter);
return new JunitFormatter($this->cwd, $this->stdOutPrinter, $options->verbose);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make it always pretty. Thank you.

return $xml;
$failure = $this->document->createElement(
'failure',
$this->escape(implode('\n', $this->createUsages($usagesPerClassname, $maxShownUsages)))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should be "\n", otherwise it outputs the backslash.

Yes, it was buggy even before your change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same above

/**
* @var DOMElement
*/
protected $rootElement;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep only other services inside formatter service. This state is not needed as property as it is needed only for format method execution.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for $document.

@@ -168,7 +169,7 @@ private function prettyPrintXml(string $inputXml): string
{
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->formatOutput = true;
$dom->formatOutput = true; // always in human-readable format
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can now compare it 1:1 without altering the real output. It should just match the passed expected string.

@@ -177,9 +178,13 @@ private function prettyPrintXml(string $inputXml): string
return trim($outputXml);
}

/**
* @throws DOMException
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exceptions from other namespaces should never bubble up. Catch it at the lowest possible level and wrap to some our exception. That one can be propagated.

Doing that, you benefit from PHPStan exception analysis, see checkedExceptionClasses


$this->printer->print($xml);
if ($xmlString === false) {
$xmlString = '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isnt this hiding some failure? I think this should be some exception.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you need something like this to get proper exception message.

Not sure tho...

@llaville
Copy link
Author

Closing this PR because we do not have the same vision of reporting format and usage.
@janedbal Thanks to spent time for code review

BTW, there are other enhancement that should be fixed first, to allow re-usability of your reports, otherwise no integration with third-party tools may be thinking .

@llaville llaville closed this Jul 16, 2024
@janedbal
Copy link
Member

Ok

there are other enhancement that should be fixed first, to allow re-usability of your reports

Anything else beside #156 and things you already reported?

@llaville
Copy link
Author

Yes and #157 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to print Junit report in human-readable format
3 participants