我正在创建此字符串
'Your maximum heart rate is ' . $int . ' Your body mass index is ' . $float . ' Your body fat percentage is ' . $float '%.'
并将其返回
我的断言是
$stringFormat = 'Your maximum heart rate is %d. Your body mass index is %f. Your body fat percentage is %f%.';
$this->assertStringMatchesFormat($stringFormat, $actualResultm, 'message');
当测试运行时,我收到此错误
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%.
现在我想象它必须与我告诉它期望一个unsigned int和两个浮点数并且它返回一个长字符串这一事实有关但是如果是这样的话我该如何测试像I这样的字符串已列出将有3个区域在不同情况下发生变化?如果不是那么我做错了什么?
答案 0 :(得分:4)
我认为你有双倍的空间。
$stringFormat = 'Your maximum heart rate is %d. Your body mass index is %f. Your body fat percentage is %f%.';
^ extra space