com php-src: Expand FTP delete basic test with "unknown file" coverage: ext/ftp/tests/ftp_delete.phpt ext/ftp/tests/server.inc

From: Date: Sun, 10 Feb 2019 19:41:08 +0000
Subject: com php-src: Expand FTP delete basic test with "unknown file" coverage: ext/ftp/tests/ftp_delete.phpt ext/ftp/tests/server.inc
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-104520@lists.php.net to get a copy of this message
Commit: f9d66caddf0931432ddab51dae6cdc46e5eb1233 Author: Ward Cappelle <ward.cappelle@studioemma.com> Sun, 10 Feb 2019 14:15:49 +0100 Committer: Peter Kokot <peterkokot@gmail.com> Sun, 10 Feb 2019 20:41:08 +0100 Parents: e94d98e2887fee2dcfc37294a882df107d5ce3ee Branches: PHP-7.4 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=f9d66caddf0931432ddab51dae6cdc46e5eb1233 Log: Expand FTP delete basic test with "unknown file" coverage A port of the original https://github.com/phpcommunity/phptestfest-php-src/pull/148 pull request, created earlier during #PHPTestFest (User Group: PHP-WVL & PHPGent). Expands the existing FTP delete command test with coverage for deletion of non-existing files (which returns a 550 status code). Changed paths: M ext/ftp/tests/ftp_delete.phpt M ext/ftp/tests/server.inc Diff: diff --git a/ext/ftp/tests/ftp_delete.phpt b/ext/ftp/tests/ftp_delete.phpt index 2883aa5..cb3c65e 100644 --- a/ext/ftp/tests/ftp_delete.phpt +++ b/ext/ftp/tests/ftp_delete.phpt @@ -2,6 +2,8 @@ Testing ftp_delete basic functionality --CREDITS-- Gabriel Caruso (carusogabriel34@gmail.com) +Contributed by Ward Cappelle <wardcappelle@gmail.com> +User Group: PHP-WVL & PHPGent #PHPTestFest --SKIPIF-- <?php require 'skipif.inc'; ?> --FILE-- @@ -12,7 +14,18 @@ $ftp = ftp_connect('127.0.0.1', $port); ftp_login($ftp, 'user', 'pass'); $ftp or die("Couldn't connect to the server"); -var_dump(ftp_delete($ftp, 'file')); +echo "Test case #1: removal of existing file from FTP, should return true:", PHP_EOL; +var_dump(ftp_delete($ftp, 'file1')); + +echo "Test case #2: removal of non-existent file from FTP, should return false:", PHP_EOL; +var_dump(ftp_delete($ftp, 'false-file.boo')); + +ftp_close($ftp); ?> ---EXPECT-- +--EXPECTF-- +Test case #1: removal of existing file from FTP, should return true: bool(true) +Test case #2: removal of non-existent file from FTP, should return false: + +Warning: ftp_delete(): No such file or directory in %s on line %d +bool(false) diff --git a/ext/ftp/tests/server.inc b/ext/ftp/tests/server.inc index 5350106..285377e 100644 --- a/ext/ftp/tests/server.inc +++ b/ext/ftp/tests/server.inc @@ -464,9 +464,12 @@ if ($pid) { } elseif (preg_match('/^SITE CHMOD/', $buf, $matches)) { fputs($s, "200 OK\r\n"); - } elseif (preg_match('/^DELE/', $buf, $matches)) { - fputs($s, "250 OK\r\n"); - + } elseif (preg_match('/^DELE ([\w\h]+)/', $buf, $matches)) { + if (isset($matches[1]) && in_array($matches[1], ['file1', "file\nb0rk"])){ + fputs($s, "250 Delete successful\r\n"); + } else { + fputs($s, "550 No such file or directory\r\n"); + } } elseif (preg_match('/^ALLO (\d+)/', $buf, $matches)) { fputs($s, "200 " . $matches[1] . " bytes allocated\r\n");

« previous php.cvs (#104520) next »