xref: /PHP-7.3/ext/phar/tests/tar/bug70417.phpt (revision a86c87df)
1--TEST--
2Bug #70417 (PharData::compress() doesn't close temp file)
3--SKIPIF--
4<?php
5if (!extension_loaded('phar') || !extension_loaded('zlib')) {
6    die("skip ext/phar or ext/zlib not available");
7}
8exec('lsof -p ' . getmypid(), $out, $status);
9if ($status !== 0) {
10    die("skip lsof(8) not available");
11}
12?>
13--FILE--
14<?php
15function countOpenFiles() {
16    exec('lsof -p ' . escapeshellarg(getmypid()) . ' 2> /dev/null', $out);
17    return count($out);
18}
19$filename = __DIR__ . '/bug70417.tar';
20@unlink("$filename.gz");
21$openFiles1 = countOpenFiles();
22$arch = new PharData($filename);
23$arch->addFromString('foo', 'bar');
24$arch->compress(Phar::GZ);
25unset($arch);
26$openFiles2 = countOpenFiles();
27var_dump($openFiles1 === $openFiles2);
28?>
29--CLEAN--
30<?php
31$filename = __DIR__ . '/bug70417.tar';
32@unlink($filename);
33@unlink("$filename.gz");
34?>
35--EXPECT--
36bool(true)
37