1--TEST-- 2Test gzencode() 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 gzencode ( string $data [, int $level [, int $encoding_mode ]] ) 12 * Description: Gzip-compress a string 13 * Source code: ext/zlib/zlib.c 14 * Alias to functions: 15 */ 16 17/* 18 * Test error cases for gzencode 19 */ 20 21echo "*** Testing gzencode() : error conditions ***\n"; 22 23// Zero arguments 24echo "\n-- Testing gzencode() function with Zero arguments --\n"; 25var_dump( gzencode() ); 26 27//Test gzencode with one more than the expected number of arguments 28echo "\n-- Testing gzencode() function with more than expected no. of arguments --\n"; 29$data = 'string_val'; 30$level = 2; 31$encoding_mode = FORCE_DEFLATE; 32$extra_arg = 10; 33var_dump( gzencode($data, $level, $encoding_mode, $extra_arg) ); 34 35echo "\n-- Testing with incorrect compression level --\n"; 36$bad_level = 99; 37var_dump(gzencode($data, $bad_level)); 38 39echo "\n-- Testing with incorrect encoding_mode --\n"; 40$bad_mode = 99; 41var_dump(gzencode($data, $level, $bad_mode)); 42 43class Tester { 44 function Hello() { 45 echo "Hello\n"; 46 } 47} 48 49echo "\n-- Testing with incorrect parameters --\n"; 50$testclass = new Tester(); 51var_dump(gzencode($testclass)); 52var_dump(gzencode($data, $testclass)); 53var_dump(gzencode($data, -1, 99.99)); 54var_dump(gzencode($data, -1, $testclass)); 55var_dump(gzencode($data, "a very none numeric string\n")); 56 57?> 58===Done=== 59--EXPECTF-- 60*** Testing gzencode() : error conditions *** 61 62-- Testing gzencode() function with Zero arguments -- 63 64Warning: gzencode() expects at least 1 parameter, 0 given in %s on line %d 65NULL 66 67-- Testing gzencode() function with more than expected no. of arguments -- 68 69Warning: gzencode() expects at most 3 parameters, 4 given in %s on line %d 70NULL 71 72-- Testing with incorrect compression level -- 73 74Warning: gzencode(): compression level(99) must be within -1..9 in %s on line %d 75bool(false) 76 77-- Testing with incorrect encoding_mode -- 78 79Warning: gzencode(): encoding mode must be FORCE_GZIP or FORCE_DEFLATE in %s on line %d 80bool(false) 81 82-- Testing with incorrect parameters -- 83 84Warning: gzencode() expects parameter 1 to be string, object given in %s on line %d 85NULL 86 87Warning: gzencode() expects parameter 2 to be long, object given in %s on line %d 88NULL 89 90Warning: gzencode(): encoding mode must be FORCE_GZIP or FORCE_DEFLATE in %s on line %d 91bool(false) 92 93Warning: gzencode() expects parameter 3 to be long, object given in %s on line %d 94NULL 95 96Warning: gzencode() expects parameter 2 to be long, string given in %s on line %d 97NULL 98===Done===