php找不到类,PHPunit:测试类里面调用其他类,命令行类一直提示找不到类

目录

controller

login.php

loginController.php

tests

loginTest.php

edf8086cb4fe8fb604c3a1d5d700e957.png

代码详情:

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哭了)

那位大佬遇到过这样的问题吗?能不能指点一下

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值