Php – How to run a PHPUnit test in Windows

PHPphpunit

So I have manually installed PHPUnit by downloading the files from pear.phpunit.de and extracting them to C:\PHP\PEAR folder. I have the PEAR folder in include path. How can I run this test?

class StackTest extends  PHPUnit_Framework_TestCase
{
    public function testEmpty()
    {
        $stack = array();
        $this->assertEmpty($stack);

        return $stack;
    }

    /**
     * @depends testEmpty
     */
    public function testPush(array $stack)
    {
        array_push($stack, 'foo');
        $this->assertEquals('foo', $stack[count($stack)-1]);
        $this->assertNotEmpty($stack);

        return $stack;
    }

    /**
     * @depends testPush
     */
    public function testPop(array $stack)
    {
        $this->assertEquals('foo', array_pop($stack));
        $this->assertEmpty($stack);
    }
}

There is no executable command line tool in the PHPUnit directory.

Best Answer

On my machine, phpunit.bat was added in my main php install directory. I run tests by calling

phpunit NameOfMyTestWithoutPhpExtension

in the directory containing the test.

The batch file simply invokes main php interpreter passing phpunit as the source file and appending other arguments to its invocation. If you don't have the batch file, try running

php "c:\PHP\PEAR\phpunit.php" NameOfMyTestWithoutPhpExtension