[PHP] hyperf单元测试模拟http请求
2023-02-18 15:41:28 时间
hyperf框架自带单元测试工具
安装完框架后
composer create-project hyperf/hyperf-skeleton
直接在test/Cases下编写单元测试代码
比如我的两个接口一个是 / , 一个是 /hello , 返回的必须都是json信息才可以,直接返回字符串,测试框架get方法得到的是null
在不启动服务的情况下就可以进行测试,也可以看到打印信息
测试/hello 接口
composer test -- --filter=testHello
<?php declare(strict_types=1); /** * This file is part of Hyperf. * * @link https://www.hyperf.io * @document https://hyperf.wiki * @contact group@hyperf.io * @license https://github.com/hyperf/hyperf/blob/master/LICENSE */ namespace HyperfTest\Cases; use HyperfTest\HttpTestCase; /** * @internal * @coversNothing */ class ExampleTest extends HttpTestCase { public function testExample() { $this->assertTrue(true); $res=$this->get('/'); var_dump($res); $this->assertTrue(is_array($res)); } public function testHello() { $res=$this->get("/hello"); var_dump($res); $this->assertSame(["hello","tsh"],$res); } }
相关文章
- SSM-用Spring+Druid+Mybatis错误:com.alibaba.druid.support.logging.JakartaCommonsLoggingImpl error
- Docker创建Redis容器模板命令
- SpringBoot+SpringData-Redis 操作 Redis(CRUD) 模板代码
- Docker高级篇:实战Redis集群!从3主3从变为4主4从
- CentOS7-命令-重启网卡命令(systemctl restart network)
- CSS Flex 弹性布局使用
- 【stars-one】JetBrains产品试用重置工具
- JB一键重置
- 修改阿里云DNS 解决蓝奏云无法访问问题
- IDEA无限试用插件
- 油猴脚本——快速引用某篇文章的标题和地址
- lzupdate
- 封装TornadoFx常用控件库
- 蓝奏云正则字符串
- stars-one的原创工具——文档生成器
- Tornadofx学习笔记(4)——IconTextFx开源库,整合5000+个字体图标
- rpc框架dubbo学习入门及环境搭建(spring boot+Kotlin)
- Tornadofx学习笔记(3)——使用Maven编译成jar包
- 探究Spring Boot中的接收参数问题与客户端发送请求传递数据
- 提问须知