如何 PHPUnit 断言函数

HowTo PHPUnit assertFunction(如何 PHPUnit 断言函数)
本文介绍了如何 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 断言函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)