PHPUnit assertFileNotEquals()函数
assertFileNotEquals()函数是 PHPUnit 中的内置函数,用于断言实际文件内容是否与预期文件内容不同。如果预期文件内容不等于实际文件内容,则此断言将返回 true,否则返回 false。如果为真,则断言的测试用例通过,否则测试用例失败。
句法:
assertFileNotEquals(string $expected, string $actual[, string $message = ''])
参数:此函数接受三个参数,如上所述,如下所述:
- $expected:该参数是字符串类型,代表预期的文件路径。
- $actual:该参数为字符串类型,表示实际文件路径。
- $message:此参数采用字符串值。当测试用例失败时,此字符串消息显示为错误消息。
下面的程序说明了 PHPUnit 中的 assertFileNotEquals()函数:
示例 1:
PHP
assertFileNotEquals(
$expected,
$actual,
"actual file content is equals to expected file content"
);
}
}
?>
PHP
assertFileNotEquals(
$expected,
$actual,
"actual file content is equals to expected file content"
);
}
}
?>
输出:
PHPUnit 8.5.8 by Sebastian Bergmann and contributors.
F 1 / 1 (100%)
Time: 116 ms, Memory: 10.00 MB
There was 1 failure:
1) GeeksPhpunitTestCase::testNegativeTestcaseForassertFileNotEquals
actual file content is equals to expected file content
Failed asserting that file "/home/bittu/Documents" exists.
/home/lovely/Documents/php/test.php:17
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
示例 2:
PHP
assertFileNotEquals(
$expected,
$actual,
"actual file content is equals to expected file content"
);
}
}
?>
输出:
PHPUnit 8.5.8 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 91 ms, Memory: 10.00 MB
OK (1 test, 3 assertions)