From e4850cba6fd67a6d4d9d8c969281e57447c17fd9 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Sun, 2 Sep 2018 18:58:32 -0400 Subject: add tests/ and composer test script --- tests/BaseTestCase.php | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tests/BaseTestCase.php (limited to 'tests/BaseTestCase.php') diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php new file mode 100644 index 0000000..8934e96 --- /dev/null +++ b/tests/BaseTestCase.php @@ -0,0 +1,49 @@ +open($path) !== true) { + throw new Exception("ZipArchive#open() failed: $dst_name"); + } + + # return archive + return $zip; + } + + protected function with_temp_file(callable $cb) : void { + # build path to temp file + $path = tempnam('/tmp', 'zipstream-test'); + try { + # pass to test + $cb($path); + } finally { + if (file_exists($path)) { + # remove temp file if it exists + unlink($path); + } + } + } + + protected function with_temp_zip(callable $zip_cb, callable $test_cb = null) { + $this->with_temp_file(function(string $dst_path) use ($zip_cb, $test_cb) { + # create zip, pass to zip callback + ZipStream::send($dst_path, $zip_cb, [ + 'output' => new FileWriter(), + ]); + + if ($test_cb) { + # pass to test callback + $test_cb($dst_path); + } + }); + } +}; -- cgit v1.2.3