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

Conditionally include extensions on the command line #5519

Open
benholmen opened this issue Sep 20, 2023 · 2 comments
Open

Conditionally include extensions on the command line #5519

benholmen opened this issue Sep 20, 2023 · 2 comments
Labels
feature/extensions type/enhancement A new idea that should be implemented

Comments

@benholmen
Copy link

Hello, I've written an extension using the documentation and it works as expected when I enable it in my phpunit.xml <extensions> config. My extension is essentially a custom printer using the event system.

I would like users to be able to conditionally enable or disable it at run time, as it may not be desirable all of the time. Enabling and disabling via phpunit.xml is pretty burdensome, so I would like to be able to do it with a command line option.

I noticed that versions before 10.x included an --extensions command line option that is no longer present in 10.x. Is there a replacement?

Alternative: allow extensions to register valid command line options to control their behavior. This would allow me to run my extension, but only do the expected action if the user provided a particular --option flag.

Are any of these possible with the current implementation or would they be new features? Thanks for the help! And thanks most of all for PHPUnit!

@benholmen benholmen added the type/enhancement A new idea that should be implemented label Sep 20, 2023
@sebastianbergmann
Copy link
Owner

The design of the test runner currently assumes that an extension that is configured in the XML configuration file should always be loaded and registered. I did not think about a use case for disabling an extension that is configured in the XML configuration file using a CLI option. This use case could be supported by a --without-extension className CLI option where className is the name of the extension's bootstrap class that is configured in the XML configuration file.

Currently, you can only use the --no-extensions CLI option to disable the loading of all extensions that are configured in phpunit.xml.

I do not remember exactly how the --extensions CLI option worked in PHPUnit 8.5 and PHPUnit 9.6, but I am almost certain that it did not do what you think it does.

allow extensions to register valid command line options to control their behavior

In the long run: maybe. But this will not be trivial to get right.

@benholmen
Copy link
Author

Thanks for the response @sebastianbergmann! Can you think of a way I could allow users to conditionally enable (or disable) my extension on the command line? Maybe I'm not considering something or aware of a feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature/extensions type/enhancement A new idea that should be implemented
Projects
None yet
Development

No branches or pull requests

2 participants