thinkphp5单元测试

本文介绍了如何在ThinkPHP5中进行单元测试,包括安装测试依赖包,解决PHP7.2中each函数弃用的问题,编写及修改测试代码,排查报错,并提供了正确响应结果的预期。遇到错误如HTTP 500,可能需检查全局变量和测试入口文件。更多详情可参考TP5单元测试官方文档。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

单元测试,tp5的单元测试

单元测试官方文档地址:https://phpunit.readthedocs.io/zh_CN/latest/writing-tests-for-phpunit.html

1. 安装单元测试依赖包

我的thinkphp版本为 5.0.23
如果直接使用

composer require topthink/think-testing

会报错

Using version ^2.0 for topthink/think-testing
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

官方文档有一句
https://www.kancloud.cn/manual/thinkphp5/182511

官方的5.0版本的扩展库版本号都是1.*,2.0版本均为ThinkPHP5.1版本专用。

我们指定版本号 v1.0,命令如下,然后安装完成

composer require topthink/think-testing 1.*

2. 编写测试代码

2.1 修改测试代码

测试文件路径 : tp5/tests/

更改:TestCase.php

protected $baseUrl = 'http://www.test.com'; //更换成你本地的host域名

更改 ExampleTest.php

public function testBasicExample()
{
   
   
    $this->vis
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值