Sintaxis:assertDirectoryIsReadable (integer $directory, string $message = ``)
Parámetros: esta función toma dos parámetros como se muestra en la sintaxis anterior. Los parámetros se describen a continuación:
- $directorio: este parámetro es una cadena que representa la ruta del directorio.
- $mensaje: este parámetro toma un valor de cadena. Cuando el caso de prueba falló, este mensaje de cadena se mostró como un mensaje de error.
Los siguientes programas ilustran la función assertDirectoryIsReadable() en PHPUnit:
Programa 1: < tr> use
PHPUnitFrameworkTestCase;
clase
GeeksPhpunitTestCase
extiende
TestCase
{
public
función
testNegativeTestcaseForAssertDirectoryIsReadable() { $directoryPath = " / home / shivam / Documents / phpunit / notreadable "
;
// Afirmar una función para verificar si el
< dado code>
// la ruta del directorio existe y es legible
$this
-> assertDirectoryIsReadable (
$directoryPath
,
" directoryPath existe y se puede leer "
< código>);
} } ?> Resultado:PHPUnit 8.2.5 por Sebastian Bergmann y contribuyentes. F 1/1 (100 %) Tiempo: 89 ms, Memoria: 10,00 MB Hubo 1 error: 1) GeeksPhpunitTestCase::testNegativeTestcaseForAssertDirectoryIsReadable directoryPath existe y es legible Error al afirmar que existe el directorio "/home/shivam/Documents/ingeniero/pgp". /home/shivam/Documentos/ingeniero/phpunit/abc.php:13 ¡FALLAS! Pruebas: 1, Aserciones: 1, Fallos: 1.
Programa 2: use
PHPUnitFrameworkTestCase;
clase
GeeksPhpunitTestCase
extiende
TestCase
{
public
function
testPositiveTestcaseForAssertDirectoryIsReadable() { $directoryPath = " / home / shivam / Documentos/ingeniero "
;
// Afirmar una función para comprobar si
// la ruta del directorio existe y es legible
$this
-> assertDirectoryIsReadable (
$directoryPath
,
"directoryPath existe y se puede leer"
);< /código> } }
?> < b>Resultado:PHPUnit 8.2.5 por Sebastian Bergmann y colaboradores. ... 1/1 (100 %) Tiempo: 67 ms, Memoria: 10,00 MB OK (1 prueba, 1 aserción)
Nota: Para ejecutar casos de prueba con PHPUnit, siga los pasos de aquí . Además, assertDirectoryIsReadable() es compatible con phpunit 7 y versiones posteriores.