Answer the question
In order to leave comments, you need to log in
How to properly test a CLI application in PHP using PHPUnit?
Hey!
I have a simple PHP command line application. What is the best way to test it with PHPunit?
The first thing that came to mind:
class HelloTest extends \PHPUnit_Framework_TestCase
{
public function testHello()
{
$expect = "<<HelloWorld>>";
$result = shell_exec("php command HelloWorld");
$result = trim($result);
$this->assertEquals($result, $expect);
}
}
Answer the question
In order to leave comments, you need to log in
Why would you want to emit a console?
Unit testing, as far as I remember, is unit testing.
Check like this:
class HelloTest extends \PHPUnit_Framework_TestCase
{
public function testHello()
{
$expect = "HelloWorld";
$command = new Command();
$result = $command->helloWorld();
$this->assertEquals($result, $expect);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question