xref: /PHP-8.0/ext/zip/tests/oo_cancel.phpt (revision 6f536052)
1--TEST--
2registerCancelCallback
3--SKIPIF--
4<?php
5/* $Id$ */
6if(!extension_loaded('zip')) die('skip');
7if (!method_exists('ZipArchive', 'registerCancelCallback')) die('skip libzip too old');
8?>
9--INI--
10date.timezone=UTC
11--FILE--
12<?php
13$dirname = dirname(__FILE__) . '/';
14$file = $dirname . '__tmp_oo_progress.zip';
15
16@unlink($file);
17
18$zip = new ZipArchive;
19if (!$zip->open($file, ZIPARCHIVE::CREATE)) {
20    exit('failed');
21}
22
23var_dump($zip->registerCancelCallback(function () {
24    // Always cancel
25    return -1;
26}));
27var_dump($zip->addFromString(PHP_BINARY, 'entry #1'));
28
29var_dump($zip->close());
30var_dump($zip->status == ZipArchive::ER_CANCELLED);
31var_dump($zip->getStatusString());
32@unlink($file);
33?>
34Done
35--EXPECTF--
36bool(true)
37bool(true)
38
39Warning: ZipArchive::close(): Operation cancelled in %s
40bool(false)
41bool(true)
42string(19) "Operation cancelled"
43Done
44