summaryrefslogtreecommitdiff
path: root/ext/zlib/tests/zlib_wrapper_level.phpt
blob: 5cfd9cf6a801937f15069275cb2d7c6418c044bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
--TEST--
compress.zlib:// wrapper with compression level
--SKIPIF--
<?php in_array('compress.zlib', stream_get_wrappers()) || print 'skip No zlib wrapper';
--FILE--
<?php declare(strict_types=1);

$filename = tempnam(sys_get_temp_dir(), "php-zlib-test-");
$thisfile = file_get_contents(__FILE__);

function write_at_level(int $level) {
  global $filename, $thisfile;

  $ctx = stream_context_create(['zlib' => ['level' => $level] ]);
  $fp = fopen("compress.zlib://$filename", 'w', false, $ctx);
  for ($i = 0; $i < 10; ++$i) {
    fwrite($fp, $thisfile);
  }
  fclose($fp);
  $size = filesize($filename);
  unlink($filename);
  return $size;
}

$size1 = write_at_level(1);
$size9 = write_at_level(9);

var_dump(10 * strlen($thisfile));
var_dump($size1);
var_dump($size9);
var_dump($size9 < $size1);
?>
--EXPECTF--
int(%d)
int(%d)
int(%d)
bool(true)