目录
controller
login.php
loginController.php
tests
loginTest.php
代码详情:
login
class login
{
// 测试工具PHPUnit要求一定要在这里给变量默认值,于是默认为空。
public function login($Sname = "",$Sage = "",$tableName = "") {
$con = mysqli_connect("localhost", "root", "root", "yoga_io");
if (!$con) {
die('连接失败:' . mysqli_error());
} else {
mysqli_query($con, "SET NAMES utf8");
$result = mysqli_query($con, "SELECT * FROM $tableName where Sname = $Sname and Sage = $Sage");
if (!$result || mysqli_num_rows($result) == 0) {
return "false";
} else {
$result_arr = mysqli_fetch_assoc($result);
return json_encode($result_arr, JSON_UNESCAPED_UNICODE);
}
}
}
}
loginTest
use PHPUnit\Framework\TestCase;
class loginTest extends TestCase
{
public function testLoginSuccess() {
$expected = '{"Sid":"1","Sname":"张三","Sage":"40","Sswx":"男"}';
$Sname = '张三';
$Sage = '40';
$tableName = 'teacher';
$lg = new Login();
$actual = $lg->login($Sname,$Sage,$tableName);
$this->assertEquals($expected,$actual);
}
function testLoginFail() {
$expected = 'false';
$Sname = '2';
$Sage = '56';
$tableName = 'teacher';
$lg = new Login();
$actual = $lg->login($Sname,$Sage,$tableName);
$this->assertEquals($expected,$actual);
}
}
错误信息:
PHPUnit 8.5.2 by Sebastian Bergmann and contributors.
Warning: Invocation with class name is deprecated
EE 2 / 2 (100%)
Time: 515 ms, Memory: 4.00 MB
There were 2 errors:
1) loginTest::testLoginSuccess
Error: Class 'Login' not found
C:\Users\Administrator\PhpstormProjects\untitled1\tests\loginTest.php:12
2) loginTest::testLoginFail
Error: Class 'Login' not found
C:\Users\Administrator\PhpstormProjects\untitled1\tests\loginTest.php:25
ERRORS!
Tests: 2, Assertions: 0, Errors: 2.
描述:就是不管换了多少个类做测试就是无法在测试类里面实例化其它类(T T哭了)
那位大佬遇到过这样的问题吗?能不能指点一下