HowTo PHPUnit assertFunction [英] HowTo PHPUnit assertFunction

查看:130
本文介绍了HowTo PHPUnit assertFunction的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何验证'class'是否具有Function。
assertClassHasAttribute不起作用,因为函数不是属性是正常的。

解决方案

如果没有断言方法由PHPUnit提供,我可以创建它或使用其中一个较低级别的断言和详细消息:

  $ this-> assertTrue(
method_exists($ myClass,'myFunction'),
'类没有方法myFunction'
);

assertTrue()与您一样基本可以得到。它允许很大的灵活性,因为您可以使用任何内置的php函数返回测试的bool值。因此,当测试失败时,错误/失败消息根本没有帮助。像之类的东西无法断言< FALSE>是TRUE 。这就是为什么将第二个参数传递给 assertTrue(),这对于测试失败的原因很重要。

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.

解决方案

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() 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.

这篇关于HowTo PHPUnit assertFunction的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆