summaryrefslogtreecommitdiff
path: root/ext/ftp
diff options
context:
space:
mode:
authorWard Cappelle <ward.cappelle@studioemma.com>2019-02-10 14:15:49 +0100
committerPeter Kokot <peterkokot@gmail.com>2019-02-10 20:41:08 +0100
commitf9d66caddf0931432ddab51dae6cdc46e5eb1233 (patch)
treeeb832a91dcc7c00f0bcef56b08a6bb597b8a29b1 /ext/ftp
parente94d98e2887fee2dcfc37294a882df107d5ce3ee (diff)
downloadphp-git-f9d66caddf0931432ddab51dae6cdc46e5eb1233.tar.gz
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).
Diffstat (limited to 'ext/ftp')
-rw-r--r--ext/ftp/tests/ftp_delete.phpt17
-rw-r--r--ext/ftp/tests/server.inc9
2 files changed, 21 insertions, 5 deletions
diff --git a/ext/ftp/tests/ftp_delete.phpt b/ext/ftp/tests/ftp_delete.phpt
index 2883aa5341..cb3c65e8ae 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 53501060a5..285377e6e8 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");