1--TEST--
2Test gzcompress() function : error conditions
3--SKIPIF--
4<?php
5if (!extension_loaded("zlib")) {
6	print "skip - ZLIB extension not loaded";
7}
8?>
9--FILE--
10<?php
11/* Prototype  : string gzcompress(string data [, int level])
12 * Description: Gzip-compress a string
13 * Source code: ext/zlib/zlib.c
14 * Alias to functions:
15 */
16
17/*
18 * add a comment here to say what the test is supposed to do
19 */
20
21echo "*** Testing gzcompress() : error conditions ***\n";
22
23// Zero arguments
24echo "\n-- Testing gzcompress() function with Zero arguments --\n";
25var_dump( gzcompress() );
26
27//Test gzcompress with one more than the expected number of arguments
28echo "\n-- Testing gzcompress() function with more than expected no. of arguments --\n";
29$data = 'string_val';
30$level = 2;
31$extra_arg = 10;
32var_dump( gzcompress($data, $level, $extra_arg) );
33
34echo "\n-- Testing with incorrect compression level --\n";
35$bad_level = 99;
36var_dump(gzcompress($data, $bad_level));
37
38class Tester {
39    function Hello() {
40        echo "Hello\n";
41    }
42}
43
44echo "\n-- Testing with incorrect parameters --\n";
45$testclass = new Tester();
46var_dump(gzcompress($testclass));
47
48var_dump(gzcompress($data, $testclass));
49
50
51?>
52===Done===
53--EXPECTF--
54*** Testing gzcompress() : error conditions ***
55
56-- Testing gzcompress() function with Zero arguments --
57
58Warning: gzcompress() expects at least 1 parameter, 0 given in %s on line %d
59NULL
60
61-- Testing gzcompress() function with more than expected no. of arguments --
62
63Warning: gzcompress() expects at most 2 parameters, 3 given in %s on line %d
64NULL
65
66-- Testing with incorrect compression level --
67
68Warning: gzcompress(): compression level (99) must be within -1..9 in %s on line %d
69bool(false)
70
71-- Testing with incorrect parameters --
72
73Warning: gzcompress() expects parameter 1 to be string, object given in %s on line %d
74NULL
75
76Warning: gzcompress() expects parameter 2 to be long, object given in %s on line %d
77NULL
78===Done===