dongyuan2652 2013-10-13 01:14
浏览 105
已采纳

如何用phpunit测试一个字符串

I am creating this string

'Your maximum heart rate is ' . $int . ' Your body mass index is ' . $float . ' Your body fat percentage is ' . $float '%.'

and returning it

My assertion is

$stringFormat = 'Your maximum heart rate is %d. Your body mass index is %f.  Your body fat percentage is %f%.';

        $this->assertStringMatchesFormat($stringFormat, $actualResultm, 'message');

and when the test runs I get this error

FatControllerTest::testBodyInfo
message
Failed asserting that format description matches text.
--- Expected
+++ Actual
@@ @@
-Your maximum heart rate is %d. Your body mass index is %f.  Your body fat percentage is %f%.
+Your maximum heart rate is 193. Your body mass index is 43.181818181818. Your body fat percentage is 6.32302%.

Now I imagine it must have something to do with the fact that I am telling it to expect an unsigned int and two floats and it is returning one long string but if that is the case how do I test for a string like I have listed that is going to have 3 areas that change from case to case? If it is not that then what have I done wrong?

  • 写回答

1条回答 默认 最新

  • duanjiu1003 2013-10-13 01:33
    关注

    I think you got double space.

    $stringFormat = 'Your maximum heart rate is %d. Your body mass index is %f.  Your body fat percentage is %f%.';
                                                                                ^ extra space
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机