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

--printer replacement in PHPUnit 10.x/11.x #5903

Open
BlairCooper opened this issue Jul 29, 2024 · 1 comment
Open

--printer replacement in PHPUnit 10.x/11.x #5903

BlairCooper opened this issue Jul 29, 2024 · 1 comment
Labels
type/enhancement A new idea that should be implemented

Comments

@BlairCooper
Copy link

With the removal of --printer, using PHPUnit with Eclipse has been broken. This isn’t your problem but I’ve been considering a solution. It seems that currently there isn’t a way to provide PHPUnit with an external printer/logger/event handler. Can you confirm that is the case, or am I missing something?

From what I have been able to glean from the code so far it seems like, if one could create a class with a constructor that takes a Printer and a Façade, this would be the start of returning the --printer functionality. Then Application::registerLogfileWriters() could check if a configuration exists (e.g. --eventListener), confirm that it refers to a class that implements an interface that defines that constructor, and if so then create an instance of the class. Having a constructor in an interface isn’t ideal but it seems it would be necessary in this case as otherwise you’d have no idea how to construct an instance.

Does this make any sense, or am I heading off in the wrong direction?

interface EventLoggerIntf
{
public static function createInstance(Printer $printer, Facade $facade);
}

@BlairCooper BlairCooper added the type/enhancement A new idea that should be implemented label Jul 29, 2024
BlairCooper added a commit to BlairCooper/phpunit that referenced this issue Jul 30, 2024
Added support for both XML and CLI definition of an external logger.
This --log-external option adds simialar functionality that existed with
the --printer option in 9.x and earlier.

Implementations of an external logger do need to implement the
\PHPUnit\Logger\ExternalLogger interface and must use the PHPUnit 10.x
and later event mechanism for capturing logging events.
@Bilge
Copy link
Contributor

Bilge commented Aug 3, 2024

You could write an extension that parses the command line ($_SERVER) and register the printer so parsed with PHPUnit\Runner\Extension\Facade. Your bigger problem is that any older printer would need to be rewritten to support the new extension architecture.

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

Successfully merging a pull request may close this issue.

2 participants