]> granicus.if.org Git - php/commitdiff
Expand FTP delete basic test with "unknown file" coverage
authorWard Cappelle <ward.cappelle@studioemma.com>
Sun, 10 Feb 2019 13:15:49 +0000 (14:15 +0100)
committerPeter Kokot <peterkokot@gmail.com>
Sun, 10 Feb 2019 19:41:08 +0000 (20:41 +0100)
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).

ext/ftp/tests/ftp_delete.phpt
ext/ftp/tests/server.inc

index 2883aa5341611e36d47a2c9b2dbeb255ba868424..cb3c65e8ae3d6d84066c5be7df0b8bcdf436c273 100644 (file)
@@ -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)
index 53501060a5d2a9d5e40f8bfdb8b29dfe620c17d0..285377e6e8e54eb2767f7e8531c9e97a217faf78 100644 (file)
@@ -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");