Skip to content

Testing a Command that Expects Input #5246

Closed
@ofbeaton

Description

@ofbeaton

The documentation at: http://symfony.com/doc/current/components/console/helpers/questionhelper.html#testing-a-command-that-expects-input

Gives an example of using setInputStream to test command input.

This only works if you provide at minimum the amount of input that is expected. It does not work on failed tests.

If you do not provide enough input, then the input request will go to the console during the run of 'phpunit', which will look like it is hung, as it will be waiting for input until you provide it.

Externally effecting the test runner like this is not correct code.

Either the instruction are missing a step, or this is not how the testing should be done.

A blog post I found about the topic: http://marekkalnik.tumblr.com/post/32601882836/symfony2-testing-interactive-console-command

Recommends mock'ing the helper. Since we don't use Dialog helper anymore, it would be mocking the QuestionHelper instead, ask() method. The example in the article is bad though, because if you ask additional questions you get the same problem, but you should be able to make a mock that does a throw() on further calls or something...

To be honest I don't know what the correct solution is, that is why I came to the docs. I also in IRC and got one response but they couldn't help me. If my question about this on stackoverflow gets answered I'll update this thread:

http://stackoverflow.com/questions/30174946/testing-symfony2-console-commands-that-expect-input

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions