Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Conversation

stephenkhoo
Copy link
Contributor

@stephenkhoo stephenkhoo commented Oct 31, 2021

Q A
Branch? 5.4
Bug fix? no
New feature? yes
Deprecations? no
Tickets Part of #43594
License MIT
Doc PR -

Adding completion for debug:event-dispatcher.

  • event
  • --dispatcher
  • --format

Test for

  • event
  • --dispatcher
  • --format

@carsonbot carsonbot added this to the 5.4 milestone Oct 31, 2021
@fabpot fabpot changed the title test for event dispatcher Add auto-completion to debug:event-dispatcher Nov 4, 2021
@fabpot fabpot changed the title Add auto-completion to debug:event-dispatcher [Console] Add auto-completion to debug:event-dispatcher Nov 4, 2021
@GromNaN
Copy link
Member

GromNaN commented Nov 9, 2021

Hi @stephenkhoo, as mentioned by @wouterj, you can can add tests for completion support only.

Do you need help to finish this PR?

@stephenkhoo
Copy link
Contributor Author

Let me try to do one without the test tonight.

@stephenkhoo stephenkhoo force-pushed the feat/debug-event-dispatcher-autocomplete branch from 664fcae to f5cf873 Compare November 10, 2021 14:45
if ($input->mustSuggestOptionValuesFor('dispatcher')) {
$suggestions->suggestValues(array_merge(
$this->dispatchers->getServiceIds(),
$this->dispatchers->getAliases()
Copy link
Contributor Author

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?

Copy link
Contributor

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?

Copy link
Member

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.

@rvanlaak
Copy link
Contributor

@stephenkhoo stephenkhoo force-pushed the feat/debug-event-dispatcher-autocomplete branch from f5cf873 to 84fc5f6 Compare November 10, 2021 14:49
@stephenkhoo
Copy link
Contributor Author

https://github.com/symfony/symfony/pull/43850/files#diff-5508b4b757a2fd5f0cb21419dd4dbd1478196d16183e023f10696e81af02e9e9R116-R140 could help you in adding a test.

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'll also need the container to have a few dispatchers so that it will be able to provide some suggestions.

@stephenkhoo
Copy link
Contributor Author

Hi @stephenkhoo, as mentioned by @wouterj, you can can add tests for completion support only.

Do you need help to finish this PR?

I think I'll need some help on direction to write test for the completion.
So far based on what I did on translation update I think they're mostly the same, just that when I need to DI for the dispatchers, I'm quite clueless.

I think if I have clue on how to pass the required parameter for EventDispatcherDebugCommand then I should be able to proceed on the completion test.

@stephenkhoo stephenkhoo force-pushed the feat/debug-event-dispatcher-autocomplete branch from 5bd2469 to a62b897 Compare November 10, 2021 16:29
@stephenkhoo
Copy link
Contributor Author

I've added the tests, there're still a few doubt.
Currently in order to get the dispatcher's name, will use getServiceIds, and getAliases which will not exists in Container interface.

Do we need to update the Type in the Command class?

*/
public function testComplete(array $input, array $expectedSuggestions)
{
$tester = $this->createCommandCompletionTester();
Copy link
Contributor

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);

Copy link
Contributor Author

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

Copy link
Contributor Author

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?

Copy link
Member

@GromNaN GromNaN left a 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

Comment on lines +135 to +144
$listeners = $dispatcher->getListeners();
$eventNames = array_keys($listeners);
$listenersName = [];
foreach ($listeners as $listOfListener) {
$listenersName = array_merge($listenersName, $listOfListener);
}
$suggestions->suggestValues(array_merge(
$eventNames,
$listenersName,
));
Copy link
Member

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)

Suggested change
$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()
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants