-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
call to member function get on a non object #12798
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
Comments
You will either have to register the command at an application or initialise the command's helper set manually. |
@xabbuh But it looks like his code sample is almost exactly what the docs state? |
@peterrehm Well, there is a placeholder at the top of the method indicating that there would be some more code. This is maybe not ideal in this chapter which doesn't talk about testing commands in general. @BardiaAfshin This looks like a documentation issue to me. Could you open an issue over there to improve the documentation here? |
@xabbuh sure thing, where is the documentation issue official home? |
@BardiaAfshin https://github.com/symfony/symfony-docs/issues |
Created issue |
I have just submitted the docs PR. If you want to initialize in an application you need to do the following: $application = new Application();
$application->add(new MyCommand());
$command = $application->find('my:command:name');
$commandTester = new CommandTester($command); However to manually set the HelperSet you can do the following: $command->setHelperSet(
new HelperSet(array(
new FormatterHelper(),
new DialogHelper(),
new ProgressHelper(),
new TableHelper(),
new DebugFormatterHelper(),
new ProcessHelper(),
new QuestionHelper(),
))
); I hope this makes it a bit more clear and the docs will be improved shortly. |
…with Helpers (peterrehm) This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #4582). Discussion ---------- Completed the needed context to successfully test commands with Helpers | Q | A | ------------- | --- | Doc fix? | yes | New docs? | no | Applies to | all | Fixed tickets | #4581 As mentioned in symfony/symfony#12798 the explanation about the initialization is not clear. Therefore I have added the needed context and a reference to the related cookbook article. Commits ------- a94bd71 Completed the needed context to successfully test commands
Following the example set at the bottom of this dialog helper page
http://symfony.com/doc/current/components/console/helpers/dialoghelper.html
When I attempt to run the following test
I get the following exception stack
on this specific line
It's calling the getHelper method on a object that doesn't have it, the command method instead of the dialogue method that's being utilized in the execute method implemented.
This code works, I've tested it from command line, the test doesn't reflect that though, the exception is correct, but the example needs to be updated to address this issue on the symfony 2 docs.
The text was updated successfully, but these errors were encountered: