assertNotEmpty("0")失败.为什么?

Gee*_*eek 1 php phpunit assertions

这样做assertNotEmpty("0")PHPUnit中失败.它不应该失败,因为它"0"是一个长度为1的字符串.

以下测试成功.

$this->assertEquals(1, strlen("0"));
$this->assertInternalType('string', "0");
Run Code Online (Sandbox Code Playgroud)

然后,为什么它说"0"是空的?assert语句是否在内部将其转换为整数以检查空虚?

Ioa*_*los 8

来自http://php.net/manual/en/function.empty.php

以下内容被认为是空的:

"" (an empty string)
0 (0 as an integer)
0.0 (0 as a float)
"0" (0 as a string)
NULL
FALSE
array() (an empty array)
$var; (a variable declared, but without a value)
Run Code Online (Sandbox Code Playgroud)