[php-src] PHP-8.6: ext/zip: add regression tests for behavior with `ZIP_CREATE`

From: Date: Fri, 23 Oct 2026 01:58:58 +0000
Subject: [php-src] PHP-8.6: ext/zip: add regression tests for behavior with `ZIP_CREATE`
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-142615@lists.php.net to get a copy of this message
Author: Daniel Scherzer (DanielEScherzer) Date: 2026-10-22T18:00:35-07:00 Commit: https://github.com/php/php-src/commit/da4babf4fa1e68192c95cf8674cbdffff3647f75 Raw diff: https://github.com/php/php-src/commit/da4babf4fa1e68192c95cf8674cbdffff3647f75.diff ext/zip: add regression tests for behavior with ZIP_CREATE A follow-up commit will switch the uses of the ZIP_CREATE to instead use ZIP_RDONLY when creation is not desired; add tests to confirm that doing so does not change the actual behavior of the extension. Changed paths: A ext/zip/tests/stats_existing.phpt A ext/zip/tests/stats_missing.phpt A ext/zip/tests/stats_nonzip.phpt Diff: diff --git a/ext/zip/tests/stats_existing.phpt b/ext/zip/tests/stats_existing.phpt new file mode 100644 index 000000000000..a3d0190b8cd2 --- /dev/null +++ b/ext/zip/tests/stats_existing.phpt @@ -0,0 +1,39 @@ +--TEST-- +Regression tests for behavior when the requested zip does exist +--EXTENSIONS-- +zip +--FILE-- +<?php +$target = __DIR__ . '/test.zip'; + +echo "Stat:\n"; +var_dump(stat("zip://$target#entry1.txt")); + +echo "\nFile contents:\n"; +var_dump(file_get_contents("zip://$target#entry1.txt")); + +$fp = fopen("zip://$target#entry1.txt", 'rb'); + +$fstat = fstat($fp); +echo "\nFstat size:\n"; +var_dump($fstat['size']); + +echo "\nStream contents:\n"; +var_dump(stream_get_contents($fp)); + +fclose($fp); +?> +--EXPECTF-- +Stat: + +Warning: stat(): stat failed for zip://%stest.zip#entry1.txt in %s on line %d +bool(false) + +File contents: +string(8) "entry #1" + +Fstat size: +int(8) + +Stream contents: +string(8) "entry #1" diff --git a/ext/zip/tests/stats_missing.phpt b/ext/zip/tests/stats_missing.phpt new file mode 100644 index 000000000000..5f4df5745c3e --- /dev/null +++ b/ext/zip/tests/stats_missing.phpt @@ -0,0 +1,47 @@ +--TEST-- +Regression tests for behavior when the requested zip does not exist +--EXTENSIONS-- +zip +--FILE-- +<?php +$target = __DIR__ . '/target.zip'; +assert(!file_exists($target), 'target.zip should not exist at the start'); + +echo "Stat:\n"; +var_dump(stat("zip://$target#entry.txt")); +assert(!file_exists($target), 'target.zip should not exist after stat()'); + +echo "\n\nFile contents:\n"; +var_dump(file_get_contents("zip://$target#entry.txt")); +assert(!file_exists($target), 'target.zip should not exist after file_get_contents()'); + +echo "\n\nFopen:\n"; +var_dump(fopen("zip://$target#entry.txt", 'r')); +assert(!file_exists($target), 'target.zip should not exist after fopen() for reading'); + +echo "\n\nOn a missing directory:\n"; +var_dump(stat('zip:///nonexistent_dir_xyz/target.zip#entry.txt')); +?> +--EXPECTF-- +Stat: + +Warning: stat(): stat failed for zip://%starget.zip#entry.txt in %s on line %d +bool(false) + + +File contents: + +Warning: file_get_contents(): Failed to open stream: operation failed in %s on line %d +bool(false) + + +Fopen: + +Warning: fopen(): Failed to open stream: operation failed in %s on line %d +bool(false) + + +On a missing directory: + +Warning: stat(): stat failed for zip:///nonexistent_dir_xyz/target.zip#entry.txt in %s on line %d +bool(false) diff --git a/ext/zip/tests/stats_nonzip.phpt b/ext/zip/tests/stats_nonzip.phpt new file mode 100644 index 000000000000..ef24c4c2c32d --- /dev/null +++ b/ext/zip/tests/stats_nonzip.phpt @@ -0,0 +1,25 @@ +--TEST-- +Regression tests for behavior when the requested zip is not a zip file +--EXTENSIONS-- +zip +--FILE-- +<?php +$target = __FILE__; + +echo "Stat:\n"; +var_dump(stat("zip://$target#entry1.txt")); + +echo "\n\nFile contents:\n"; +var_dump(file_get_contents("zip://$target#entry1.txt")); +?> +--EXPECTF-- +Stat: + +Warning: stat(): stat failed for zip://%sstats_nonzip.php#entry1.txt in %s on line %d +bool(false) + + +File contents: + +Warning: file_get_contents(): Failed to open stream: operation failed in %s on line %d +bool(false)

« previous php.cvs (#142615) next »