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 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?