是否可以使用 PHPUnit 对除 class 文件之外的 php 文件进行单元测试?

Is it possible to unit test, php files other than class file using PHPUnit?

我是 PHPUnit 新手。我有 php 个文件,其中没有任何 class。我从阅读文档中了解到,PHPUnit 将 class 视为一个单元。 那么 PHPUnit 是否将 class 视为一个单元? 是否可以测试其中没有任何 class 的 php 文件?

当然,您完全可以测试其他 PHP 脚本。

class MyScriptTest extends PHPUnit_Framework_TestCase {
    public function testMyFunction() {
        include_once 'path/to/script.php';
        $result = someFunction();

        $this->assertEquals('expected result', $result);
    }
}

所以编写PHP单元测试类,并在测试中运行任何你想测试的代码并针对它做出断言。