Skip to content

Commit f9d66ca

Browse files
wardcapppetk
authored andcommitted
Expand FTP delete basic test with "unknown file" coverage
A port of the original phpcommunity/phptestfest-php-src#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).
1 parent e94d98e commit f9d66ca

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

ext/ftp/tests/ftp_delete.phpt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
Testing ftp_delete basic functionality
33
--CREDITS--
44
Gabriel Caruso ([email protected])
5+
Contributed by Ward Cappelle <[email protected]>
6+
User Group: PHP-WVL & PHPGent #PHPTestFest
57
--SKIPIF--
68
<?php require 'skipif.inc'; ?>
79
--FILE--
@@ -12,7 +14,18 @@ $ftp = ftp_connect('127.0.0.1', $port);
1214
ftp_login($ftp, 'user', 'pass');
1315
$ftp or die("Couldn't connect to the server");
1416

15-
var_dump(ftp_delete($ftp, 'file'));
17+
echo "Test case #1: removal of existing file from FTP, should return true:", PHP_EOL;
18+
var_dump(ftp_delete($ftp, 'file1'));
19+
20+
echo "Test case #2: removal of non-existent file from FTP, should return false:", PHP_EOL;
21+
var_dump(ftp_delete($ftp, 'false-file.boo'));
22+
23+
ftp_close($ftp);
1624
?>
17-
--EXPECT--
25+
--EXPECTF--
26+
Test case #1: removal of existing file from FTP, should return true:
1827
bool(true)
28+
Test case #2: removal of non-existent file from FTP, should return false:
29+
30+
Warning: ftp_delete(): No such file or directory in %s on line %d
31+
bool(false)

ext/ftp/tests/server.inc

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,12 @@ if ($pid) {
464464
} elseif (preg_match('/^SITE CHMOD/', $buf, $matches)) {
465465
fputs($s, "200 OK\r\n");
466466

467-
} elseif (preg_match('/^DELE/', $buf, $matches)) {
468-
fputs($s, "250 OK\r\n");
469-
467+
} elseif (preg_match('/^DELE ([\w\h]+)/', $buf, $matches)) {
468+
if (isset($matches[1]) && in_array($matches[1], ['file1', "file\nb0rk"])){
469+
fputs($s, "250 Delete successful\r\n");
470+
} else {
471+
fputs($s, "550 No such file or directory\r\n");
472+
}
470473
} elseif (preg_match('/^ALLO (\d+)/', $buf, $matches)) {
471474
fputs($s, "200 " . $matches[1] . " bytes allocated\r\n");
472475

0 commit comments

Comments
 (0)