我可以对不在类中的函数使用phpunit测试吗?

我可以对不在类中的函数使用phpunit测试吗?,php,phpunit,Php,Phpunit,我有一个小的.php文件,其中有一个函数,我在下面粘贴了这个函数。我想测试一下这个函数 有什么方法可以使用phpunit吗?我没有使用composer.json <?php public function LoginMe($a, $b) //nick, psw { require 'includes/mysql_connection.php'; require 'includes/config.php'; require 'i

我有一个小的
.php
文件,其中有一个函数,我在下面粘贴了这个函数。我想测试一下这个函数

有什么方法可以使用phpunit吗?我没有使用
composer.json

<?php public function LoginMe($a, $b) //nick, psw
        {
        require 'includes/mysql_connection.php';
        require 'includes/config.php';
        require 'includes/messages.php';
        require 'backend/LogsSystem.php';

                // Some code

                return false;
        } ?>

例如,如果您的脚本名为
authentication.php
,则这可能是测试提示:

<?php
use PHPUnit\Framework\TestCase;
include 'authentication.php';
class authenticationTest extends TestCase
{
    public function testAuthentication()
    {
    //your test here, call LoginMe with expected parameters
    }
}

我已经试过了,不起作用。我也在使用Linux,但在本地也不起作用。例如,linux错误:PHP致命错误:在第5行的/home/valkas1/public_html/testing.PHP中找不到类'PHPUnit\Framework\TestCase',我不明白我遗漏了什么是的,您可以使用PHPUnit为函数编写单元测试。这是为这个而做的。但是,它要求您首先设置Phpunit的工作版本。然后检查测试套件引导过程是否覆盖了所有需要的初始化(或使用setup-before-class方法),以便该函数可用。当您需要或包含文件时,请注意其副作用。正是这些副作用常常妨碍其他部分(这里是测试套件或运行程序)正常工作。调试这些问题是值得的,这样您就可以更轻松地了解副作用并解决它们。