One way is to use the backtick operator (`) to capture the output of the program, then examine that output. This works well under Unix/Linux-style OSes, as you can also capture error outputs like STDERR. (It is more painful under Windows, but can be done (especially using Cygwin).)
For example:
public function testHelp()
{
$output = `./add-event --help 2>&1`;
$this->assertRegExp( '/^usage:/m', $output, 'no help message?' );
$this->assertRegExp( '/where:/m', $output, 'no help message?' );
$this->assertNotRegExp( '/where event types are:/m', $output, 'no help message?' );
}
You can see that both STDOUT and STDERR were captured to $output, then regex assertions were used to test whether the output resembled the correct output.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…