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