1--TEST--
2compress.zlib:// wrapper with compression level
3--SKIPIF--
4<?php in_array('compress.zlib', stream_get_wrappers()) || print 'skip No zlib wrapper';
5--FILE--
6<?php declare(strict_types=1);
7
8$filename = tempnam(sys_get_temp_dir(), "php-zlib-test-");
9$thisfile = file_get_contents(__FILE__);
10
11function write_at_level(int $level) {
12  global $filename, $thisfile;
13
14  $ctx = stream_context_create(['zlib' => ['level' => $level] ]);
15  $fp = fopen("compress.zlib://$filename", 'w', false, $ctx);
16  for ($i = 0; $i < 10; ++$i) {
17    fwrite($fp, $thisfile);
18  }
19  fclose($fp);
20  $size = filesize($filename);
21  unlink($filename);
22  return $size;
23}
24
25$size1 = write_at_level(1);
26$size9 = write_at_level(9);
27
28var_dump(10 * strlen($thisfile));
29var_dump($size1);
30var_dump($size9);
31var_dump($size9 < $size1);
32?>
33--EXPECTF--
34int(%d)
35int(%d)
36int(%d)
37bool(true)
38