Skip to content

Add "Writing a custom Behat formatter" cookbook #149

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

Merged
merged 8 commits into from
Mar 11, 2025

Conversation

jdeniau
Copy link
Contributor

@jdeniau jdeniau commented Oct 29, 2024

Fixes #143

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.

@jdeniau thanks very much for this, it's a great addition to the documentation.

I've made some suggestions for style / grammar things that it would be good to fix - I feel bad picking them out, as there's no way I could write anything like this in French!

If you're OK with my suggestions I'd be happy to apply them for you.

@jdeniau
Copy link
Contributor Author

jdeniau commented Nov 1, 2024

@acoulton do not feel bad, English is not my main language and I make a lot of errors. I make typos too 🙂

I'm OK with all your suggestions. I'm not on a computer right now, so if you want to make the changes yourself no problem for me. If not, I will commit this in the next days.

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.

Thanks @jdeniau I've added those edits for you.

@acoulton acoulton requested a review from ttomdewit November 1, 2024 07:58
Copy link

@ttomdewit ttomdewit left a comment

Choose a reason for hiding this comment

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

It's a really good addition. The only changes I'd request would be to replace "behat" with "Behat" and try and stay away from terms like "simple" when trying to explain a step. It's not a "must solve" on my end, but something that's simple to a lot of people might not be simple for others.

@acoulton
Copy link
Contributor

acoulton commented Nov 1, 2024

Thanks @ttomdewit I missed some of the [bB]ehat. That's very good advice on "simple".

I'll take another pass later unless @jdeniau gets there first.

@acoulton acoulton force-pushed the behat-formatter-cookbook branch from 8223594 to fb03842 Compare November 1, 2024 09:24
@acoulton acoulton requested a review from ttomdewit November 1, 2024 09:25
@acoulton
Copy link
Contributor

acoulton commented Nov 1, 2024

@ttomdewit I pulled it into my IDE to find and replace all the lowercase behat, and the spellchecker also highlighted a couple of typos I hadn't seen myself so I've fixed them too 😆


default:
extensions:
JDeniau\BehatReviewdogFormatter\ReviewdogFormatterExtension: ~
Copy link
Member

Choose a reason for hiding this comment

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

if you put your extension class in a ServiceContainer subnamespace, with a name matching the last section of your namespace, this unlocks using the shortcut.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi,
I do not understand what you mean here: is there a way to "magically" add an extension without being explicit in the configuration file ?

I read https://github.com/Behat/Behat/blob/610fa32937bf52bd79d812103464600ef4649e36/src/Behat/Testwork/ServiceContainer/ContainerLoader.php and https://github.com/Behat/Behat/blob/610fa32937bf52bd79d812103464600ef4649e36/src/Behat/Testwork/ServiceContainer/ExtensionManager.php source code, but I did not see anything about it 🤔

Copy link
Contributor

Choose a reason for hiding this comment

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

You got very close - the magic is here (and the method it calls)

Basically if you define your class named MyNamespace\MyPackage\ServiceContainer\MyPackageExtension then in the config file you can just use MyNamespace\MyPackage and Behat will find the class.

However I actually think now that we support php config files the short syntax is less useful (people can just add use statements like anywhere else) and we could probably deprecate it at some point.

So I wouldn't worry about it for this PR.

@carlos-granados
Copy link
Contributor

@jdeniau do you think you might work on adding the changes suggested by @stof ? This is a really nice piece of documentation and it would be great to be finally able to add it. Thanks!!

@jdeniau
Copy link
Contributor Author

jdeniau commented Feb 13, 2025

Oh I did though that it had been merged. I will try to change that 👍

@jdeniau jdeniau force-pushed the behat-formatter-cookbook branch from a1db0e6 to 2deede1 Compare February 17, 2025 10:45
@jdeniau
Copy link
Contributor Author

jdeniau commented Feb 17, 2025

@carlos-granados I did change according to @stof recommandations except for #149 (comment) that I did not understand.

The CI is failing due to lines too long, but those lines does contains links or are in bullets points, and I don't know how to split those lines.

@acoulton
Copy link
Contributor

Thanks for this @jdeniau I will take a look properly soon. There have been some improvements to Behat since you wrote it, I may be able to suggest a couple of changes to include them.

@carlos-granados
Copy link
Contributor

@carlos-granados I did change according to @stof recommandations except for #149 (comment) that I did not understand.

The CI is failing due to lines too long, but those lines does contains links or are in bullets points, and I don't know how to split those lines.

@jdeniau for the lines that contain links, you can define the links separately. See for example how it is done for the Business Readable, Domain Specific Language link in the gherkin.rst file

@jdeniau jdeniau force-pushed the behat-formatter-cookbook branch from c3cbc30 to 061d64e Compare March 10, 2025 13:56
@jdeniau
Copy link
Contributor Author

jdeniau commented Mar 10, 2025

@carlos-granados It should be good this time ! 🤞

@jdeniau jdeniau requested a review from carlos-granados March 10, 2025 13:57
Copy link
Contributor

@carlos-granados carlos-granados left a comment

Choose a reason for hiding this comment

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

@jdeniau this is looking good to me now. I know that @acoulton also wanted to take a look, so let's wait for his input

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.

Thanks @jdeniau this looks great to me. I've worked through the tutorial locally and it all works perfectly. Just one small suggestion to remind people not to expect a file if nothing failed - that caught me out for a moment. Let me know if you're happy with that & I can commit and merge.

I was also going to suggest migrating this to use the new PHP config and a custom formatter config object, but I think it'll be easiest if we merge as-is and then I can do a PR with those changes separately.

@jdeniau
Copy link
Contributor Author

jdeniau commented Mar 11, 2025

@acoulton thanks for running the tutorial completely !
I did commit your suggestion.

@jdeniau jdeniau force-pushed the behat-formatter-cookbook branch from be2cef4 to f1968d5 Compare March 11, 2025 10:34
@acoulton acoulton merged commit 1289537 into Behat:v3.0 Mar 11, 2025
4 checks passed
@acoulton
Copy link
Contributor

@jdeniau great, thanks :)

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.

Custom formatter extension documentation
5 participants