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

fix: Handle command defined with AsCommand php attribute #24

Closed
wants to merge 1 commit into from

Conversation

Cryde
Copy link

@Cryde Cryde commented Dec 24, 2024

It seems that the #[AsCommand] attribute make commands lazy
When using this phpunit helper lib I am unable to launch command from tests

@@ -56,6 +57,9 @@ public static function for(Command $command): self
public static function from(Application $application, string $cli): self
{
foreach ($application->all() as $commandObject) {
if ($commandObject instanceof LazyCommand) {
Copy link
Author

Choose a reason for hiding this comment

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

I'm not really sure if this is the right way to do it.

name: 'fixture:command',
description: 'zenstruck/console-test command for tests'
)]
final class FixtureAttributeCommand extends Command
Copy link
Author

@Cryde Cryde Dec 24, 2024

Choose a reason for hiding this comment

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

I have copy past your other FixtureCommand but without cleaning it
Maybe tests should be duplicated for this case (with #[AsCommand] attribute) ?

@Cryde
Copy link
Author

Cryde commented Jan 7, 2025

@kbond do you it's good ? Tell me if I can add something

@kbond kbond mentioned this pull request Jan 8, 2025
@kbond
Copy link
Member

kbond commented Jan 8, 2025

Sorry for the delay here... holidays :)

This is a great catch! I've simplified it a bit in #27. The root issue wasn't actually the attribute but having a default description on your command (Symfony uses the attribute to determine this). When you have a default description, Symfony marks the command as lazy (the default description is the trigger). FixtureCommand used the old way of defining a description so that's why it wasn't caught earlier. I've updated FixtureCommand to use the attribute now and confirmed your fix.

Thank you!

@kbond kbond closed this Jan 8, 2025
@Cryde
Copy link
Author

Cryde commented Jan 9, 2025

Hope you had great holidays !

Thank you for the clarification

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

Successfully merging this pull request may close these issues.

2 participants