xref: /PHP-8.2/ext/zlib/tests/gzencode_error1.phpt (revision 74859783)
1--TEST--
2Test gzencode() function : error conditions
3--EXTENSIONS--
4zlib
5--FILE--
6<?php
7/*
8 * Test error cases for gzencode
9 */
10
11echo "*** Testing gzencode() : error conditions ***\n";
12
13$data = 'string_val';
14$level = 2;
15$encoding_mode = FORCE_DEFLATE;
16
17echo "\n-- Testing with incorrect compression level --\n";
18$bad_level = 99;
19try {
20    var_dump(gzencode($data, $bad_level));
21} catch (\ValueError $e) {
22    echo $e->getMessage() . \PHP_EOL;
23}
24
25echo "\n-- Testing with incorrect encoding_mode --\n";
26$bad_mode = 99;
27try {
28    var_dump(gzencode($data, $level, $bad_mode));
29} catch (\ValueError $e) {
30    echo $e->getMessage() . \PHP_EOL;
31}
32
33?>
34--EXPECT--
35*** Testing gzencode() : error conditions ***
36
37-- Testing with incorrect compression level --
38gzencode(): Argument #2 ($level) must be between -1 and 9
39
40-- Testing with incorrect encoding_mode --
41gzencode(): Argument #3 ($encoding) must be one of ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP, or ZLIB_ENCODING_DEFLATE
42