This package is a pure PHP alternative to expect, the Unix tool. This package doesn't depend on the PECL package either.
Expect lets you script interactions with interactive terminal applications.
The original author wrote this "because I wrote an interactive CLI program and needed to write automated tests for it. Apparently people use the real expect for scripting ftp and telnet workflows, so I guess you could use it for that too."
I have modified this for my own uses.
For now, copy the Expect.php file to your own project and use include_once with the path of the file to add it
This version does not support chaining of commands. It follows the program flow as defined within your php application.
Spawn a new instance of expect for the given command. You can optionally specify a working directory and a PSR compatible logger to use.
expect(string $output, $timeout = 9999999)
Expect the given text to show up on stdout. Expect will block and keep checking the stdout buffer until your expectation shows up or the timeout is reached, whichever comes first.
You can use shell wildcards to match parts of output.
send(string $msg)
Send the given text on stdin. A newline is added to each string to simulate pressing enter. If you want to just send enter you can do send(PHP_EOL)
There is an example in the source file Expect.php