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

runCommand(): use CommandTester (Enhancement) #219

Closed
Aerendir opened this issue Jan 14, 2016 · 6 comments
Closed

runCommand(): use CommandTester (Enhancement) #219

Aerendir opened this issue Jan 14, 2016 · 6 comments
Labels

Comments

@Aerendir
Copy link

I'm trying to use the WebTestCase::runCommand() method.

I have yet implemented my unit test to test command, but, as I've anyway extend WebTestBundle to load fixtures, I like to also use other useful methods that the bundle provides.
So II'd like to rewrite my tests to use those methods.

Now I'm working on a command and seen the code of the method WebTestCase::runCommand().

I noted it doesn't use the helpful Symfony\Component\Console\Tester\CommandTester() class: is there a reason for this? Or may be the CommandTester class were released after the WebTestCase::runCommand()?

Can someone help me understand?

@Aerendir Aerendir changed the title How to use runCommand()? runCommand(): use CommandTester Jan 15, 2016
@Aerendir Aerendir changed the title runCommand(): use CommandTester runCommand(): use CommandTester (Enhancement) Jan 17, 2016
@lsmith77
Copy link
Contributor

yes WebTestCase::runCommand() was created years before Symfony\Component\Console\Tester\CommandTester()

@Aerendir
Copy link
Author

I'll work on it ASAP...

@giosh94mhz
Copy link

giosh94mhz commented Oct 10, 2016

This would be a cool addition, since with the current runCommand there is no status code returned.

Here's what I did:

    $tester = new CommandTester($this->command);
    $this->assertEquals($this->command->getName(), 'my:name');
    $this->assertEquals(0, $tester->execute([]));
    $output = $tester->getOutput();
    $normOutput = $tester->getDisplay()

@magnetik
Copy link
Contributor

I've gave it a go in the PR above.

@lsmith77 lsmith77 closed this as completed Nov 9, 2018
@martiis
Copy link

martiis commented Nov 22, 2018

I recently updated and got some issues. CommandTester does not dispatch console events and some tests started failing. Is there a solution?

@Jean85
Copy link
Contributor

Jean85 commented Nov 22, 2018

Are you sure that you're not referencing a different kernel?

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

No branches or pull requests

6 participants