語法:assertDirectoryIsReadable(integer $directory, string $message = ``)
參數:這個函數有兩個參數,如上述語法所示。參數說明如下:
- $directory: 這個參數是一個字符串,表示目錄路徑。
- $message:這個參數接受一個字符串值。當測試用例失敗時,此字符串消息顯示為錯誤消息。
以下程序說明了 PHPUnit 中的 assertDirectoryIsReadable() 函數:
程序 1:< tr> <代碼> use
PHPUnitFrameworkTestCase;
class
GeeksPhpunitTestCase
extends
TestCase
{
public
function
testNegativeTestcaseForAssertDirectoryIsReadable()
代碼>
{
$directoryPath
=
"/home/shivam/ Documents / phpunit / notreadable "
;
//斷言一個函數檢查是否給定
//目錄路徑存在且可讀
$this
-> assertDirectoryIsReadable(
$directoryPath
,
" directoryPath 存在且可讀 "
<代碼>);
}
}
?>
輸出:PHPUnit 8.2.5 由 Sebastian Bergmann 和貢獻者。 F 1/1 (100%) 時間:89 毫秒,內存:10.00 MB 有 1 次失敗:1) GeeksPhpunitTestCase::testNegativeTestcaseForAssertDirectoryIsReadable directoryPath 存在且可讀 斷言目錄“/home/shivam/Documents/engineer/pgp”存在失敗。 /home/shivam/Documents/engineer/phpunit/abc.php:13 失敗!測試:1,斷言:1,失敗:1。
程序 2: use
PHPUnitFrameworkTestCase;
class
GeeksPhpunitTestCase
extends
TestCase
{
public
function
testPositiveTestcaseForAssertDirectoryIsReadable()
代碼>
{
$directoryPath
=
"/home/shivam/文檔/工程師 "
;
// 斷言一個函數來檢查是否
//目錄路徑存在且可讀
$this
->assertDirectoryIsReadable(
$directoryPath
,
"directoryPath 存在且可讀"
);
}
}
?>
< b>輸出:Sebastian Bergmann 和貢獻者的 PHPUnit 8.2.5。 ... 1/1 (100%) 時間:67 毫秒,內存:10.00 MB OK(1 個測試,1 個斷言)
注意: 要使用 PHPUnit 運行測試用例,請遵循 這裡。此外,phpunit 7 及更高版本支持 assertDirectoryIsReadable()。