gzcompress_error1.phpt 983 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. --TEST--
  2. Test gzcompress() function : error conditions
  3. --EXTENSIONS--
  4. zlib
  5. --FILE--
  6. <?php
  7. /*
  8. * add a comment here to say what the test is supposed to do
  9. */
  10. echo "*** Testing gzcompress() : error conditions ***\n";
  11. echo "\n-- Testing with incorrect compression level --\n";
  12. $data = 'string_val';
  13. $bad_level = 99;
  14. try {
  15. var_dump(gzcompress($data, $bad_level));
  16. } catch (\ValueError $e) {
  17. echo $e->getMessage() . \PHP_EOL;
  18. }
  19. echo "\n-- Testing with invalid encoding --\n";
  20. $data = 'string_val';
  21. $level = 2;
  22. $encoding = 99;
  23. try {
  24. var_dump(gzcompress($data, $level, $encoding));
  25. } catch (\ValueError $e) {
  26. echo $e->getMessage() . \PHP_EOL;
  27. }
  28. ?>
  29. --EXPECT--
  30. *** Testing gzcompress() : error conditions ***
  31. -- Testing with incorrect compression level --
  32. gzcompress(): Argument #2 ($level) must be between -1 and 9
  33. -- Testing with invalid encoding --
  34. gzcompress(): Argument #3 ($encoding) must be one of ZLIB_ENCODING_RAW, ZLIB_ENCODING_GZIP, or ZLIB_ENCODING_DEFLATE