summaryrefslogtreecommitdiff
path: root/ext/zip/tests
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2015-08-21 22:26:26 +0200
committerChristoph M. Becker <cmb@php.net>2015-09-05 00:34:10 +0200
commitc77f783777e0169b2a4b7b9439cad76b372290a3 (patch)
treec1370e0d681d44fa142b051f6dbbd5ef26180a7c /ext/zip/tests
parent4b1dff6f438f84f7694df701b68744edbdd86153 (diff)
downloadphp-git-c77f783777e0169b2a4b7b9439cad76b372290a3.tar.gz
Fix #70322: ZipArchive::close() doesn't indicate errors
If an archive can't be written, ZipArchive::close() nonetheless returns TRUE. We fix the return value to properly return success, and additionally raise a warning on failure.
Diffstat (limited to 'ext/zip/tests')
-rw-r--r--ext/zip/tests/bug70322.phpt29
-rw-r--r--ext/zip/tests/oo_delete.phpt3
2 files changed, 31 insertions, 1 deletions
diff --git a/ext/zip/tests/bug70322.phpt b/ext/zip/tests/bug70322.phpt
new file mode 100644
index 0000000000..a9b4915914
--- /dev/null
+++ b/ext/zip/tests/bug70322.phpt
@@ -0,0 +1,29 @@
+--TEST--
+Bug #70322 (ZipArchive::close() doesn't indicate errors)
+--DESCRIPTION--
+We want to test whether ZipArchive::close() returns FALSE and raises a warning
+on failure, so we force the failure by adding a file to the archive, which we
+delete before closing.
+--SKIPIF--
+<?php
+if (!extension_loaded('zip')) die('skip requires zip extension');
+?>
+--FILE--
+<?php
+$zipfile = __DIR__ . '/bug70322.zip';
+$textfile = __DIR__ . '/bug70322.txt';
+touch($textfile);
+$zip = new ZipArchive();
+$zip->open($zipfile, ZipArchive::CREATE);
+$zip->addFile($textfile);
+unlink($textfile);
+var_dump($zip->close());
+?>
+--CLEAN--
+<?php
+// we don't expect the archive to be created, but clean up just in case...
+@unlink(__DIR__ . '/bug70322.zip');
+?>
+--EXPECTF--
+Warning: ZipArchive::close(): Read error: No such file or directory in %s%ebug70322.php on line %d
+bool(false)
diff --git a/ext/zip/tests/oo_delete.phpt b/ext/zip/tests/oo_delete.phpt
index 9eac821734..69c6151d5c 100644
--- a/ext/zip/tests/oo_delete.phpt
+++ b/ext/zip/tests/oo_delete.phpt
@@ -63,7 +63,8 @@ $sb = $zip->statIndex(1);
var_dump($sb);
$sb = $zip->statIndex(2);
var_dump($sb);
-$zip->close();
+// suppress irrelevant error message:
+@$zip->close();
unset($zip);
if (file_exists($file)) {