Symfony Console Input Testing

If you’re writing a Symfony Console application, you’ll likely be getting user input via the Question helper. The Symfony manual has an entry on expected input. Unfortunately until they update the docs (github issue #5246) with a better example, it creates brittle test cases that fail spectacularly, sitting in the middle of a PHPUnit run expecting user input. Which would ruin your whole test run when running in travis-ci or jenkins.

Thankfully there is a better way, which is to mock the question helper ask method. I’ve provided the ofbeaton/console-tester package on packagist so you can use it in your project.

Continue reading Symfony Console Input Testing