dongzhenju3015 2012-07-30 11:52
浏览 74

PHPUnit中的单元测试 - 处理多个条件

I want to write a test using PHPUnit which includes a check to make sure that a value is either a string or NULL.

AFAIK, I can write such a test like so:

if (is_string($value) || is_null($value)) { 
    $result = TRUE; 
} else { 
    $result = FALSE; 
} 

$this->assertTrue($result);

However, I've seen that PHPUnit has a logicalOr() method, which I don't know if I should be using to make a more 'native' test? And if I should be using it, I can't figure out how to do so...

  • 写回答

3条回答 默认 最新

  • douping7975 2012-07-30 16:47
    关注

    logicalOr returns an object that is used to build a condition that can be passed to assertThat. I can't check the syntax on my phone, but it should look something like this:

    self::assertThat(self::logicalOr(self::stringValue(), self::nullValue()));
    

    The method names are no doubt incorrect as I am used to Hamcrest, but I he structure is similar.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度