2

我正在创建这个字符串

'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%.

现在我想它一定与我告诉它期待一个无符号整数和两个浮点数并且它返回一个长字符串但如果是这种情况我如何测试我列出的字符串的事实有关将有 3 个区域因情况而异?如果不是这样,那我做错了什么?

4

1 回答 1

4

我想你有双倍空间。

$stringFormat = 'Your maximum heart rate is %d. Your body mass index is %f.  Your body fat percentage is %f%.';
                                                                            ^ extra space
于 2013-10-13T01:33:20.770 回答