【问题标题】:How to run a PHPUnit test in Windows?如何在 Windows 中运行 PHPUnit 测试?
【发布时间】:2012-01-08 00:01:28
【问题描述】:

所以我通过从 pear.phpunit.de 下载文件并将它们解压缩到 C:\PHP\PEAR 文件夹来手动安装 PHPUnit。我在包含路径中有 PEAR 文件夹。如何运行此测试?

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);
    }
}

PHPUnit目录下没有可执行的命令行工具。

【问题讨论】:

    标签: php phpunit


    【解决方案1】:

    在我的机器上,phpunit.bat 已添加到我的主 php 安装目录中。我通过调用

    来运行测试
    phpunit NameOfMyTestWithoutPhpExtension
    

    在包含测试的目录中。

    批处理文件简单地调用主 php 解释器,传递 phpunit 作为源文件并将其他参数附加到它的调用中。如果您没有批处理文件,请尝试运行

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

    【讨论】:

    • 这是一个 PHP 文件。没有 *.exe 文件,只有一个 *.bat 将 phpunit 传递给 php.exe
    • 好的,这行得通:php "c:\PHP\PEAR\phpunit.php" NameOfMyTestWithoutPhpExtension
    猜你喜欢
    • 2011-09-21
    • 2014-11-17
    • 2016-04-07
    • 2016-01-16
    • 1970-01-01
    • 1970-01-01
    • 2021-11-26
    • 2018-10-31
    • 1970-01-01
    相关资源
    最近更新 更多