[英]Can I use phpunit tests on functions that are not in class?
I have a small .php
file with that one function which I've pasted below.我有一个小的
.php
文件,其中包含我粘贴在下面的那个函数。 I would like to test that function.我想测试该功能。
Is there any way of how I can use phpunit?有什么办法可以使用phpunit吗? I'm not using
composer.json
.我没有使用
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;
} ?>
For example, if your script is called authentication.php
, this can be a hint for test:例如,如果您的脚本名为
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
}
}
You may find interesting this too: PHP Testing, for Procedural Code您可能也会发现有趣的: PHP 测试,用于程序代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.