HowTo PHPUnit assertFunction(如何 PHPUnit 断言函数)
问题描述
我想知道如何验证类"是否具有函数.assertClassHasAttribute 不起作用,这是正常的,因为 Function 不是 Attribute.
I was wondering if how I can verify if a 'class' has a Function. assertClassHasAttribute does not work, it's normal since a Function is not an Attribute.
推荐答案
当 PHPUnit 没有提供断言方法时,我要么创建它,要么使用带有详细消息的低级断言之一:
When there's not an assertion method provided by PHPUnit I either create it or use one of the lower-level assertions with a verbose message:
$this->assertTrue(
method_exists($myClass, 'myFunction'),
'Class does not have method myFunction'
);
assertTrue()
是最基础的.它提供了很大的灵活性,因为您可以使用任何内置的 php 函数来为您的测试返回 bool 值.因此,当测试失败时,错误/失败消息根本没有帮助.类似 Failed asserting that <FALSE>为真
.这就是为什么将第二个参数传递给 assertTrue()
来详细说明测试失败的原因很重要.
assertTrue()
is as basic as you can get. It allows a great deal of flexibility because you can use any built-in php function that returns a bool value for your test. Consequently, when the test fails the error/failure message isn't helpful at all. Something like Failed asserting that <FALSE> is TRUE
. That's why it's important to pass the second param to assertTrue()
detailing why the test failed.
这篇关于如何 PHPUnit 断言函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何 PHPUnit 断言函数


基础教程推荐
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何替换eregi() 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01