I'm creating a library and I want to test a system that asks the user by input in the console. I use PHPUnit as a testing library but and I don't know how to execute readline
function and then print a text to answer the input to test it.
Here it is my test:
$app = new Application;
$i = null;
$app->registerCommand('test', function(Input $input) use(&$i){
// $input->getInput() asks the user and returns the value
$i = $input->getInput();
});
$this->expectOutputString("\n");
// Run the application, so asks the user to enter a value
$app->run();
// Here, I want force to enter a value by the code
$this->assertSame($i, 'test');
I've tested to replace readline
by fgets(STDIN)
but without results. I thought to solve the problem with asynchronous callables but I need guide for good libraries to use.
Here it is differents ways I've tested in
getInput
function:
return readline();
return trim(fgets(STDIN));
Thank for your help.