phpunit 测试

Warning “The attribute 'syntaxCheck' is not allowed.”#

报错详情如下

Copy Highlighter-hljs
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 操作啦。

Copy Highlighter-hljs
// 检查 $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.'); }
posted @   caibaotimes  阅读(90)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示
CONTENTS