Skip to content

Commit 630f2fc

Browse files
committed
Cleanup Tempfiles in Unit Tests
1 parent 6d41054 commit 630f2fc

File tree

3 files changed

+118
-178
lines changed

3 files changed

+118
-178
lines changed

test/Tempfile.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ZipStream\Test;
6+
7+
trait Tempfile
8+
{
9+
protected string|null $tempfile;
10+
11+
/**
12+
* @var resource
13+
*/
14+
protected $tempfileStream;
15+
16+
protected function setUp(): void
17+
{
18+
[$tempfile, $tempfileStream] = $this->getTmpFileStream();
19+
20+
$this->tempfile = $tempfile;
21+
$this->tempfileStream = $tempfileStream;
22+
}
23+
24+
protected function tearDown(): void
25+
{
26+
unlink($this->tempfile);
27+
if(is_resource($this->tempfileStream)) {
28+
fclose($this->tempfileStream);
29+
}
30+
31+
$this->tempfile = null;
32+
$this->tempfileStream = null;
33+
}
34+
35+
protected function getTmpFileStream(): array
36+
{
37+
$tmp = tempnam(sys_get_temp_dir(), 'zipstreamtest');
38+
$stream = fopen($tmp, 'wb+');
39+
40+
return [$tmp, $stream];
41+
}
42+
}

test/Util.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@
1818

1919
trait Util
2020
{
21-
protected function getTmpFileStream(): array
22-
{
23-
$tmp = tempnam(sys_get_temp_dir(), 'zipstreamtest');
24-
$stream = fopen($tmp, 'wb+');
25-
26-
return [$tmp, $stream];
27-
}
28-
2921
protected function cmdExists(string $command): bool
3022
{
3123
if (strtolower(\substr(PHP_OS, 0, 3)) === 'win') {

0 commit comments

Comments
 (0)