phpunit 测试
Warning “The attribute 'syntaxCheck' is not allowed.”#
报错详情如下
Warning - The configuration file did not pass validation!
The following problems have been detected:
Line 11:
- Element 'phpunit', attribute 'syntaxCheck': The attribute 'syntaxCheck' is not allowed.
Test results may not be as expected.
意思就是phpunit下的syntaxCheck这个属性不允许存在(大概是这个意思),把这个属性删掉就可以了,其位置如下:
为什么先进行异常断言然后进行调用呢?#
因为异常发生时代码就终止往下运行了,所以你需要事先告诉测试框架 " 下面的代码可能会发生异常,请帮忙检查是否为我断言的样子”,测试框架就会进行 try catch 操作啦。
// 检查 $type 参数
public function testGetWeaherWithInvalidType()
{
$w = new Weather('mock-key');
// 断言会抛出此异常类
$this->expectException(InvalidArgumentException::class);
// 断言异常消息为 'Invalid type value(base/all): foo'
$this->expectExceptionMessage('Invalid type value(base/all): foo');
$w->getWeather('深圳', 'foo');
$this->fail('Failed to assert getWeather throw exception with invalid argument.');
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?