简体   繁体   English

如何在Windows中运行PHPUnit测试?

[英]How to run a PHPUnit test in Windows?

So I have manually installed PHPUnit by downloading the files from pear.phpunit.de and extracting them to C:\\PHP\\PEAR folder. 所以我通过从pear.phpunit.de下载文件并将它们解压缩到C:\\ PHP \\ PEAR文件夹来手动安装PHPUnit。 I have the PEAR folder in include path. 我在包含路径中有PEAR文件夹。 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. PHPUnit目录中没有可执行的命令行工具。

On my machine, phpunit.bat was added in my main php install directory. 在我的机器上, phpunit.bat被添加到我的主要php安装目录中。 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. 批处理文件只调用主php解释器,将phpunit作为源文件传递,并将其他参数附加到其调用中。 If you don't have the batch file, try running 如果您没有批处理文件,请尝试运行

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM