Skip to content

Conversation

@carlos-granados
Copy link
Contributor

The JSON and JUnit formatters were using a very simple management of the printed file paths. This PR replaces this with the ConfigurablePathPrinter that the other formatter use. This brings a couple of advantages:

  • It uses the %paths.base% to calculate relative paths, this is more correct than using cwd as those formatters were doing
  • It allows us to use the options offered by that printer

The editorUrl option of that printer is not appropriate for these formatters, which cannot use the link added to the paths, so I added a flag to mark if this option needs to be applied or not

Adds tests that check the correct working of the printer options in these formatters


$outputPrinter->extendFeatureAttributes([
'name' => $this->currentFeature->getTitle(),
'name' => $this->currentFeature->getTitle() ?? '',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed that this can be null and if that is the case we need to print an empty string

Copy link
Contributor

Choose a reason for hiding this comment

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

Or I suppose we could make the name element nullable in the JSON schema?

But I think you're probably right that it's simpler for end-users if we coalesce to an empty string - I doubt there's a usecase for being able to explicitly tell whether a feature name was provided..

private readonly ResultToStringConverter $resultConverter,
private readonly JUnitOutlineStoreListener $outlineStoreListener,
private readonly ?JUnitDurationListener $durationListener = null,
private readonly ?ConfigurablePathPrinter $configurablePathPrinter = null,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This needs to be made nullable to keep BC

@carlos-granados
Copy link
Contributor Author

@acoulton as promised here is the implementation of what we discussed yesterday

Copy link
Contributor

@acoulton acoulton left a comment

Choose a reason for hiding this comment

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

Great work, thanks @carlos-granados


$outputPrinter->extendFeatureAttributes([
'name' => $this->currentFeature->getTitle(),
'name' => $this->currentFeature->getTitle() ?? '',
Copy link
Contributor

Choose a reason for hiding this comment

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

Or I suppose we could make the name element nullable in the JSON schema?

But I think you're probably right that it's simpler for end-users if we coalesce to an empty string - I doubt there's a usecase for being able to explicitly tell whether a feature name was provided..

$testCaseAttributes['file'] =
str_starts_with($file, $cwd) ?
ltrim(substr($file, strlen($cwd)), DIRECTORY_SEPARATOR) : $file;
if ($file && $this->configurablePathPrinter instanceof ConfigurablePathPrinter) {
Copy link
Contributor

Choose a reason for hiding this comment

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

So if someone has somehow created a JUnitScenarioPrinter outside our DI container (without the path printer) we will just stop including a file attribute in the junit.

I think that's unlikely to happen, and the file attribute was already optional so the report is still schema-valid, so I think this is OK.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that was my thinking

@acoulton
Copy link
Contributor

We'll need to note in the changelog that the junit file paths by default will now be relative to %paths.base% rather than cwd - in most cases I'd expect that to be the same but it could produce a diff for people who are using tooling to aggregate/compare junit reports across multiple runs.

@carlos-granados carlos-granados force-pushed the use-configurable-path-printer-in-file-formatters branch from 18d20ac to 1a76cb2 Compare October 24, 2025 08:13
@carlos-granados carlos-granados merged commit 2dae5c0 into Behat:master Oct 24, 2025
19 checks passed
@carlos-granados carlos-granados deleted the use-configurable-path-printer-in-file-formatters branch October 24, 2025 08:27
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.

2 participants