xref: /PHP-8.4/ext/zlib/tests/007.phpt (revision 74859783)
1--TEST--
2gzencode() and invalid params
3--EXTENSIONS--
4zlib
5--FILE--
6<?php
7
8try {
9    var_dump(gzencode("", -10));
10} catch (\ValueError $e) {
11    echo $e->getMessage() . \PHP_EOL;
12}
13try {
14    var_dump(gzencode("", 100));
15} catch (\ValueError $e) {
16    echo $e->getMessage() . \PHP_EOL;
17}
18try {
19    var_dump(gzencode("", 1, 100));
20} catch (\ValueError $e) {
21    echo $e->getMessage() . \PHP_EOL;
22}
23
24var_dump(gzencode("", -1, ZLIB_ENCODING_GZIP));
25var_dump(gzencode("", 9, ZLIB_ENCODING_DEFLATE));
26
27$string = "Light of my sun
28Light in this temple
29Light in my truth
30Lies in the darkness";
31
32try {
33    var_dump(gzencode($string, 9, 3));
34} catch (\ValueError $e) {
35    echo $e->getMessage() . \PHP_EOL;
36}
37
38var_dump(gzencode($string, -1, ZLIB_ENCODING_GZIP));
39var_dump(gzencode($string, 9, ZLIB_ENCODING_DEFLATE));
40
41?>
42--EXPECTF--
43gzencode(): Argument #2 ($level) must be between -1 and 9
44gzencode(): Argument #2 ($level) must be between -1 and 9
45gzencode(): Argument #3 ($encoding) must be one of ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP, or ZLIB_ENCODING_DEFLATE
46string(%d) "%a"
47string(%d) "%a"
48gzencode(): Argument #3 ($encoding) must be one of ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP, or ZLIB_ENCODING_DEFLATE
49string(%d) "%a"
50string(%d) "%a"
51