-
-
Notifications
You must be signed in to change notification settings - Fork 616
PHP Config - profile formatters #1558
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
PHP Config - profile formatters #1558
Conversation
|
@carlos-granados I'm not that familiar with profile formatters feature. The documentation is not great about them. Do we have "verbose", "paths" and "snippets" options for all of them? |
|
@loic425 The options available for each formatter are: Pretty:
Progress:
Junit:
(other formatters out there may define other options). You can see these definitions in these classes: Please take into account that apart from these options, these formatters can also be enabled or disabled |
|
@loic425 it's essentially very flexible - each formatter can define its own options. There is a work-in-progress cookbook for adding a custom formatter at Behat/docs#149 - https://behat--149.org.readthedocs.build/en/149/cookbooks/custom_formatter.html#create-the-extension which adds a bit more detail on how formatters work / can be configured. |
|
In addition to the list @carlos-granados provided, I think every formatter array can also include For the pretty formatter, I believe:
I'd suggest perhaps instead of
I am fairly sure that enabling a formatter in YAML (e.g. providing And then probably provide an implementation of I might be tempted to implement these as named constructor arguments with the defaults matching the ones that are defined in the If we did that I'd suggest then having the XXXFormatterFactory reference those class defaults instead of redefining them, to keep them consistent over time. So we'd have something like: class PrettyFormatter implements FormatterConfigInterface {
public function __construct(
bool $timer = true,
bool $expand = false,
bool $paths = true,
bool $multiline = true
) {/*...*/}
public function withOutputPath(string $path) {
// Probably need withOutputPath, withOutputVerbosity, etc to be chained helpers as we don't want to specify values here by default
// We could perhaps implement these on a base `FormatterConfig` object that individual formatters extend from, as
// third-party formatters would also need to support these...
}
}And then this in PrettyFormatterFactory: $definition = new Definition('Behat\Testwork\Output\NodeEventListeningFormatter', array(
'pretty',
'Prints the feature as is.',
array(
'timer' => true,
'expand' => false,
'paths' => true,
'multiline' => true,
),Would become something more like: $definition = new Definition('Behat\Testwork\Output\NodeEventListeningFormatter', array(
PrettyFormatter::NAME, // probably need this as a const to make it easy to pass to ->disableFormatter()
'Prints the feature as is.',
(new PrettyFormatter())->toArray()What do you and @carlos-granados think? |
|
@acoulton I didn't see your previous comment before this new commit. I like your idea with "disableFormatter" |
|
@acoulton I've updated the PR with your suggested changes. |
acoulton
left a comment
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 looking good to me.
I think I'd still ideally like to see the FormatterFactory classes now taking their defaults from these classes, to avoid the risk a parameter gets added / changed in one place but not the other.
I've added a commit with that proposal (edit two commits) |
acoulton
left a comment
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.
Thanks, a couple of suggestions
src/Behat/Behat/Output/ServiceContainer/Formatter/JUnitFormatterFactory.php
Outdated
Show resolved
Hide resolved
src/Behat/Behat/Output/ServiceContainer/Formatter/PrettyFormatterFactory.php
Outdated
Show resolved
Hide resolved
src/Behat/Behat/Output/ServiceContainer/Formatter/ProgressFormatterFactory.php
Outdated
Show resolved
Hide resolved
|
One thing I've realised having now had a chance to test this is that with YAML, it actually is possible to do this: default:
formatters:
pretty:
expand: true
multiline: false
ci:
formatters:
pretty:
multiline: true
# This block is merged with the block from the `default` profile above
# So because expand is not specified here, it will inherit the customised `true` value,
# not the formatter default of `false`This is not possible with the current PHP implementation. Personally I think that's OK. I think it's much clearer to specify all the non-default formatter options in each separate profile, rather than relying on them being deep-merged implicitly. Especially because most other parts of the config are overwritten rather than merged. If people really want to avoid typing the parameters twice, since they're in PHP they have quite a lot of options to use variables or similar to explicitly share values between different profiles in their config file. I also think using constructor parameters for these is much easier for users to read and to discover the available / default options, and the benefit of that outweighs the loss. But just thought worth highlighting in case others think the internal deep-merge is an important feature. |
acoulton
left a comment
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.
@loic425 great, thanks!
If you have time to look at adding a short documentation for the parameters as #1558 (comment) that would be great. If not I think we can merge this and I can pick that up
Yes, I'll work on it on monday. |
carlos-granados
left a comment
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.
Overall looking great, nice job @loic425 just a few small questions
|
@carlos-granados I think everything is ok now :) |
|
@loic425 this is looking good to me. Would you be able to rebase onto latest master and potentially squash the commits? Thanks :) |
66fb45a to
3f20dd1
Compare
Yes, squashed & rebased. |
carlos-granados
left a comment
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.
All good now, thanks @loic425
Uh oh!
There was an error while loading. Please reload this page.