Skip to content

ext/zlib: Refactor tests #18887

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions ext/zlib/tests/002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ $original = str_repeat("hallo php",4096);
$packed=gzcompress($original);
echo strlen($packed)." ".strlen($original)."\n";
$unpacked=gzuncompress($packed);
if (strcmp($original,$unpacked)==0) echo "Strings are equal\n";
if ($original === $unpacked) echo "Strings are equal\n";

/* with explicit compression level, length */
$original = str_repeat("hallo php",4096);
$packed=gzcompress($original, 9);
echo strlen($packed)." ".strlen($original)."\n";
$unpacked=gzuncompress($packed, 40000);
if (strcmp($original,$unpacked)==0) echo "Strings are equal\n";
if ($original === $unpacked) echo "Strings are equal\n";
?>
--EXPECT--
106 36864
Expand Down
2 changes: 1 addition & 1 deletion ext/zlib/tests/003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ zlib
$original = str_repeat("hallo php",4096);
$packed = gzencode($original);
echo strlen($packed)." ".strlen($original). "\n";
if (strcmp($original, gzdecode($packed)) == 0) echo "Strings are equal";
if ($original === gzdecode($packed)) echo "Strings are equal\n";
?>
--EXPECT--
118 36864
Expand Down
Binary file modified ext/zlib/tests/bug55544-win.phpt
Binary file not shown.
7 changes: 3 additions & 4 deletions ext/zlib/tests/bug60761.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@
checks zlib compression output size is always the same
--EXTENSIONS--
zlib
--INI--
zlib.output_compression=4096
zlib.output_compression_level=9
--CGI--
--FILE--
<?php

// the INI directives from bug #60761 report
ini_set('zlib.output_compression', '4096');
ini_set('zlib.output_compression_level', '9');

// try to duplicate the original bug by running this as a CGI
// test using ob_start and zlib.output_compression(or ob_gzhandler)
// so it follows more of the original code-path than just calling
Expand Down
2 changes: 1 addition & 1 deletion ext/zlib/tests/bug61139.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ gzopen('someFile', 'c');
?>
--CLEAN--
<?php
unlink('someFile');
unlink('someFile');
?>
--EXPECTF--
Warning: gzopen(): gzopen failed in %s on line %d
2 changes: 1 addition & 1 deletion ext/zlib/tests/bug71417.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function test($case) {
// The gzdecode() function applied to the corrupted compressed data always
// detects the error:
// --> gzdecode(): PHP Fatal error: Uncaught ErrorException: gzdecode(): data error in ...
echo "gzdecode(): ", rawurldecode(gzdecode($compressed)), "\n";
echo "gzdecode(): ", rawurldecode((string) gzdecode($compressed)), "\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this cast added

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because gzdecode() can return false, and I didn't really want to bother figuring out why

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack


file_put_contents($fn, $compressed);

Expand Down
4 changes: 2 additions & 2 deletions ext/zlib/tests/bug74240.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
Bug #74240 (deflate_add can allocate too much memory)
--EXTENSIONS--
zlib
--INI--
memory_limit=64M
--FILE--
<?php

ini_set('memory_limit', '64M');

$deflator = deflate_init(ZLIB_ENCODING_RAW);

$bytes = str_repeat("*", 65536);
Expand Down
8 changes: 3 additions & 5 deletions ext/zlib/tests/compress_zlib_wrapper.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@ compress.zlib:// wrapper
zlib
--FILE--
<?php
chdir(__DIR__. "/../../..");

$pfx = str_repeat('../', substr_count($_SERVER['PHP_SELF'], '../'));
chdir(__DIR__. "/data");

// Relative path
$fp = fopen("compress.zlib://{$pfx}ext/xsl/tests/xslt.xsl.gz", "rb");
$fp = fopen("compress.zlib://test.txt.gz", "rb");
fclose($fp);

// Absolute path
$fp = fopen("compress.zlib://". __DIR__. "/../../../ext/xsl/tests/xslt.xsl.gz", "rb");
$fp = fopen("compress.zlib://". __DIR__. "/data/test.txt.gz", "rb");
fclose($fp);

echo "ok\n";
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion ext/zlib/tests/deflate_init_reuse.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ foreach (range("a", "z") as $char) {
$compressed .= deflate_add($resource, $char, ZLIB_NO_FLUSH);
}
$compressed .= deflate_add($resource, "", ZLIB_FINISH);
assert($uncompressed === zlib_decode($compressed));
var_dump($uncompressed === zlib_decode($compressed));
?>
===DONE===
--EXPECT--
bool(true)
===DONE===
4 changes: 2 additions & 2 deletions ext/zlib/tests/gh16883.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ stream_context_set_default([
$f = gzopen('http://'.PHP_CLI_SERVER_HOSTNAME.':'.PHP_CLI_SERVER_PORT, 'r');
var_dump(stream_get_contents($f));

var_dump(gzfile('http://'.PHP_CLI_SERVER_HOSTNAME.':'.PHP_CLI_SERVER_PORT, 'r'));
var_dump(gzfile('http://'.PHP_CLI_SERVER_HOSTNAME.':'.PHP_CLI_SERVER_PORT));

var_dump(readgzfile('http://'.PHP_CLI_SERVER_HOSTNAME.':'.PHP_CLI_SERVER_PORT, 'r'));
var_dump(readgzfile('http://'.PHP_CLI_SERVER_HOSTNAME.':'.PHP_CLI_SERVER_PORT));

?>
--EXPECT--
Expand Down
2 changes: 1 addition & 1 deletion ext/zlib/tests/gzclose_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ zlib
// note that gzclose is an alias to fclose. parameter checking tests will be
// the same as fclose

$f = __DIR__."/004.txt.gz";
$f = __DIR__."/data/test.txt.gz";
$h = gzopen($f, 'r');
gzread($h, 20);
var_dump(gzclose($h));
Expand Down
54 changes: 27 additions & 27 deletions ext/zlib/tests/gzcompress_basic1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ zlib
* add a comment here to say what the test is supposed to do
*/

include(__DIR__ . '/data.inc');
include(__DIR__ . '/data/data.inc');

echo "*** Testing gzcompress() : basic functionality ***\n";

Expand All @@ -23,68 +23,68 @@ $smallstring = "A small string to compress\n";
for($i = -1; $i < 10; $i++) {
echo "-- Compression level $i --\n";
$output = gzcompress($data, $i);
var_dump(strcmp(gzuncompress($output), $data));
var_dump(gzuncompress($output) === $data);
}

// Compressing a smaller string
for($i = -1; $i < 10; $i++) {
echo "-- Compression level $i --\n";
$output = gzcompress($smallstring, $i);
var_dump(strcmp(gzuncompress($output), $smallstring));
var_dump(gzuncompress($output) === $smallstring);
}

// Calling gzcompress() with mandatory arguments
echo "\n-- Testing with no specified compression level --\n";
$output = gzcompress($smallstring);
var_dump(strcmp(gzuncompress($output), $smallstring));
var_dump(gzuncompress($output) === $smallstring);

?>
--EXPECT--
*** Testing gzcompress() : basic functionality ***
-- Compression level -1 --
int(0)
bool(true)
-- Compression level 0 --
int(0)
bool(true)
-- Compression level 1 --
int(0)
bool(true)
-- Compression level 2 --
int(0)
bool(true)
-- Compression level 3 --
int(0)
bool(true)
-- Compression level 4 --
int(0)
bool(true)
-- Compression level 5 --
int(0)
bool(true)
-- Compression level 6 --
int(0)
bool(true)
-- Compression level 7 --
int(0)
bool(true)
-- Compression level 8 --
int(0)
bool(true)
-- Compression level 9 --
int(0)
bool(true)
-- Compression level -1 --
int(0)
bool(true)
-- Compression level 0 --
int(0)
bool(true)
-- Compression level 1 --
int(0)
bool(true)
-- Compression level 2 --
int(0)
bool(true)
-- Compression level 3 --
int(0)
bool(true)
-- Compression level 4 --
int(0)
bool(true)
-- Compression level 5 --
int(0)
bool(true)
-- Compression level 6 --
int(0)
bool(true)
-- Compression level 7 --
int(0)
bool(true)
-- Compression level 8 --
int(0)
bool(true)
-- Compression level 9 --
int(0)
bool(true)

-- Testing with no specified compression level --
int(0)
bool(true)
1 change: 0 additions & 1 deletion ext/zlib/tests/gzcompress_error1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ try {
}

echo "\n-- Testing with invalid encoding --\n";
$data = 'string_val';
$level = 2;
$encoding = 99;
try {
Expand Down
2 changes: 1 addition & 1 deletion ext/zlib/tests/gzcompress_variation1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Test gzcompress() function : variation
zlib
--FILE--
<?php
include(__DIR__ . '/data.inc');
include(__DIR__ . '/data/data.inc');

echo "*** Testing gzcompress() : variation ***\n";

Expand Down
54 changes: 27 additions & 27 deletions ext/zlib/tests/gzdeflate_basic1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ zlib
* add a comment here to say what the test is supposed to do
*/

include(__DIR__ . '/data.inc');
include(__DIR__ . '/data/data.inc');

echo "*** Testing gzdeflate() : basic functionality ***\n";

Expand All @@ -23,68 +23,68 @@ $smallstring = "A small string to compress\n";
for($i = -1; $i < 10; $i++) {
echo "-- Compression level $i --\n";
$output = gzdeflate($data, $i);
var_dump(strcmp(gzinflate($output), $data));
var_dump(gzinflate($output) === $data);
}

// Compressing a smaller string
for($i = -1; $i < 10; $i++) {
echo "-- Compression level $i --\n";
$output = gzdeflate($smallstring, $i);
var_dump(strcmp(gzinflate($output), $smallstring));
var_dump(gzinflate($output) === $smallstring);
}

// Calling gzdeflate() with just mandatory arguments
echo "\n-- Testing with no specified compression level --\n";
$output = gzdeflate($smallstring);
var_dump(strcmp(gzinflate($output), $smallstring));
var_dump(gzinflate($output) === $smallstring);

?>
--EXPECT--
*** Testing gzdeflate() : basic functionality ***
-- Compression level -1 --
int(0)
bool(true)
-- Compression level 0 --
int(0)
bool(true)
-- Compression level 1 --
int(0)
bool(true)
-- Compression level 2 --
int(0)
bool(true)
-- Compression level 3 --
int(0)
bool(true)
-- Compression level 4 --
int(0)
bool(true)
-- Compression level 5 --
int(0)
bool(true)
-- Compression level 6 --
int(0)
bool(true)
-- Compression level 7 --
int(0)
bool(true)
-- Compression level 8 --
int(0)
bool(true)
-- Compression level 9 --
int(0)
bool(true)
-- Compression level -1 --
int(0)
bool(true)
-- Compression level 0 --
int(0)
bool(true)
-- Compression level 1 --
int(0)
bool(true)
-- Compression level 2 --
int(0)
bool(true)
-- Compression level 3 --
int(0)
bool(true)
-- Compression level 4 --
int(0)
bool(true)
-- Compression level 5 --
int(0)
bool(true)
-- Compression level 6 --
int(0)
bool(true)
-- Compression level 7 --
int(0)
bool(true)
-- Compression level 8 --
int(0)
bool(true)
-- Compression level 9 --
int(0)
bool(true)

-- Testing with no specified compression level --
int(0)
bool(true)
4 changes: 1 addition & 3 deletions ext/zlib/tests/gzdeflate_variation1.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ Test gzdeflate() function : variation
zlib
--FILE--
<?php
include(__DIR__ . '/data.inc');
include(__DIR__ . '/data/data.inc');

echo "*** Testing gzdeflate() : variation ***\n";



echo "\n-- Testing multiple compression --\n";
$output = gzdeflate($data);
var_dump(strlen($output));
Expand Down
Loading