-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Console] Add auto-completion to debug:event-dispatcher #43859
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
[Console] Add auto-completion to debug:event-dispatcher #43859
Conversation
Hi @stephenkhoo, as mentioned by @wouterj, you can can add tests for completion support only. Do you need help to finish this PR? |
Let me try to do one without the test tonight. |
664fcae
to
f5cf873
Compare
if ($input->mustSuggestOptionValuesFor('dispatcher')) { | ||
$suggestions->suggestValues(array_merge( | ||
$this->dispatchers->getServiceIds(), | ||
$this->dispatchers->getAliases() |
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.
Not quite sure the dispatchers will be an instance of Container or ContainerBuilder?
Will there be aliases need to be supported on the completion?
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.
The Psalm CI job might fail on getServiceIds
and getAliases
. Maybe you can attach XDebug to your CLI job?
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.
$dispatchers
is an instance of Symfony\Contracts\Service\ServiceProviderInterface
. The method getProvidedServices()
can be used after checking its availability.
https://github.com/symfony/symfony/pull/43850/files#diff-5508b4b757a2fd5f0cb21419dd4dbd1478196d16183e023f10696e81af02e9e9R116-R140 could help you in adding a test. |
f5cf873
to
84fc5f6
Compare
I think for completion test part I've no problem, but I'm not sure what is the best way to inject the $dispatchers which is a class that has interface of Container. |
I think I'll need some help on direction to write test for the completion. I think if I have clue on how to pass the required parameter for |
5bd2469
to
a62b897
Compare
I've added the tests, there're still a few doubt. Do we need to update the Type in the Command class? |
*/ | ||
public function testComplete(array $input, array $expectedSuggestions) | ||
{ | ||
$tester = $this->createCommandCompletionTester(); |
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.
Did you think about only mocking the ContainerInterface
here (so no kernel, no application)?
$dispatchers = $this->createMock(ContainerInterface::class);
$dispatchers->method('get')->willReturn($dispatcher);
$dispatchers->method('has')->willReturn(true);
// ...
$command = new EventDispatcherDebugCommand($dispatchers);
$tester = new CommandCompletionTester($command);
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.
Let me try this out
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.
But container interface don't have another method required
getServiceIds
, getAliases
Will mocking this interface able to make method for methods not on the interface?
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.
Thank you for your time on this PR and all your attempts to add tests. In order to finish this one before the release of 5.4, I made a PR on your repository. After reviewing, you can merge it and squash the commits. GromNaN@5b66228
$listeners = $dispatcher->getListeners(); | ||
$eventNames = array_keys($listeners); | ||
$listenersName = []; | ||
foreach ($listeners as $listOfListener) { | ||
$listenersName = array_merge($listenersName, $listOfListener); | ||
} | ||
$suggestions->suggestValues(array_merge( | ||
$eventNames, | ||
$listenersName, | ||
)); |
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.
Why listeners are added to the list of suggested event names? The argument get values like kernel.response
or Symfony\Component\Mailer\Event\MessageEvent
. I did some tests and listener names are not accepted (ex: Symfony\Component\HttpKernel\EventListener\ResponseListener::onKernelResponse
)
$listeners = $dispatcher->getListeners(); | |
$eventNames = array_keys($listeners); | |
$listenersName = []; | |
foreach ($listeners as $listOfListener) { | |
$listenersName = array_merge($listenersName, $listOfListener); | |
} | |
$suggestions->suggestValues(array_merge( | |
$eventNames, | |
$listenersName, | |
)); | |
$suggestions->suggestValues(array_keys($dispatcher->getListeners())); |
if ($input->mustSuggestOptionValuesFor('dispatcher')) { | ||
$suggestions->suggestValues(array_merge( | ||
$this->dispatchers->getServiceIds(), | ||
$this->dispatchers->getAliases() |
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.
$dispatchers
is an instance of Symfony\Contracts\Service\ServiceProviderInterface
. The method getProvidedServices()
can be used after checking its availability.
Adding completion for debug:event-dispatcher.
Test for