Source: php-horde-lz4
Version: 1.0.10-10
Severity: important
Tags: patch

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

Hi,

the autopkgtest of php-horde-lz4 fails on every architecture, and that
keeps 1.0.10-10 out of testing (1420 days by now, according to the
excuses).

With phpunit 13.4.8+ds-1 it stops at once:

  Unknown option "-v"

Without the -v, 7 of the 12 tests end with an error:

  Call to undefined method horde_lz4_UnitTest::expectErrorMessage()
  Call to undefined method horde_lz4_UnitTest::expectWarning()

PHPUnit 10 removed the -v option, expectErrorMessage() and
expectWarning().  None of this depends on the PHP version.

Two changes fix it:

  * The attached patch for horde_lz4-*/test/horde/lz4/UnitTest.php.  The
    four tests for a wrong number of arguments expect the
    ArgumentCountError that PHP 8 throws, with the same message.  The
    three tests for warnings collect the warning with an error handler
    and check its message and the false return value.  No test is
    dropped.

  * In debian/tests/phpunit, "phpunit -v ." becomes "phpunit .".

With both, the autopkgtest passes (12 tests, 21 assertions):

  * in unstable, with PHP 8.4.28 and the php-horde-lz4 binary from the
    archive;
  * in experimental, with PHP 8.6.0 and a package built with the lz4 1.11
    fix that I am filing separately.

PHPUnit still prints warnings; they come from
/usr/share/php/Horde/Test/Autoload.php in php-horde-test, not from this
package.


- -- System Information:
Debian Release: 13.8
  APT prefers stable-updates
  APT policy: (500, 'stable-updates'), (500, 'stable-security'), (500, 
'stable-debug'), (500, 'proposed-updates'), (500, 'stable')
Architecture: amd64 (x86_64)
Foreign Architectures: i386

Kernel: Linux 6.12.117+deb13-amd64 (SMP w/12 CPU threads; PREEMPT)
Locale: LANG=en_IE.UTF-8, LC_CTYPE=en_IE.UTF-8 (charmap=UTF-8), 
LANGUAGE=en_IE:en
Shell: /bin/sh linked to /usr/bin/dash
Init: systemd (via /run/systemd/system)

-----BEGIN PGP SIGNATURE-----

iQKTBAEBCgB9FiEEw2Gx4wKVQ+vGJel9g3Kkd++uWcIFAmsKoMNfFIAAAAAALgAo
aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldEMz
NjFCMUUzMDI5NTQzRUJDNjI1RTk3RDgzNzJBNDc3RUZBRTU5QzIACgkQg3Kkd++u
WcLNog/+KbDWqZGlRlAjcljZ+G5XAYkkKw2Ud64aNLKkVvp09kjQ80xTNxRckyWP
kJ5mumnOpyatpN3GoQiRvdB5IywP13JQy2eWVAe1wsJKD6YdZqw1z5lU6+yOZZp2
gjGTHZTnzn4I/x32xsTHAvP9T/5qoLzE8DI0Spq6QTN2rzEwYTJ1t5xIaJS58YCD
XA9vP3YYH7zbhDgYk8rTp8IvPNet1NeivvjXoovxezDZevP6cd+InMPjcnzaySko
wOSqmjyjlNq9hIP1tBdY3U1PxgMiPubHVXIxlZj542eg38IuXK9deakiJpXHHrIy
8Ajy5Hu7CdqsDvwZ0sZctmVG3wN3y5sLOGgjcpCmVh1vZsn8yrhDO9SZwD1+6aFm
kvYJmC3hjWzw1zqA8+jnbqjyo2D9ZqqIjxHjdceiVksBSnpZEFU7oLt0hG0QK/N6
WclsoYne/aUqpiUASHQHWQ9JPT4d+ei6oTbtWiizen5QkYAX30uYaGdaHTzqRsq/
CKUwwGFpFZYQ3OJ9JZCU4difImrIQZ9Tq9U9iBK+6rV4PgEKUto0z7G1dQlzCdxv
hX9cNFftKzfl0TpUOVbTrBaD6TQufJvyZzxebHx9pl/sZNnZxKgo4hQYT8l8f/u+
o5CopT9i1jzpDt0eDttOLvugI24k64FaJTyEsOKQ86lDFuUW5+E=
=O1dT
-----END PGP SIGNATURE-----
Description: Adapt the unit test to PHPUnit 10 and later
 PHPUnit 10 removed expectErrorMessage() and expectWarning(), so seven of the
 twelve tests end with "Call to undefined method" under the PHPUnit 13 in
 unstable.  Expect the ArgumentCountError that PHP 8 throws for a wrong number
 of arguments, and collect the warnings with an error handler instead.
 .
 This is not related to the PHP version; the tests fail the same way with
 PHP 8.4.
Author: Ondřej Surý <[email protected]>
Forwarded: no
Last-Update: 2026-11-28
---
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
--- a/horde_lz4-1.0.10/test/horde/lz4/UnitTest.php
+++ b/horde_lz4-1.0.10/test/horde/lz4/UnitTest.php
@@ -36,6 +36,23 @@
         $this->data = file_get_contents(__DIR__ . '/fixtures/data.txt');
     }
 
+    // Runs $callback, stores what it returned in $result and returns the
+    // messages of the warnings it raised (PHPUnit 10 removed expectWarning()).
+    private function catchWarnings($callback, &$result = null)
+    {
+        $warnings = array();
+        set_error_handler(function ($errno, $errstr) use (&$warnings) {
+            $warnings[] = $errstr;
+            return true;
+        }, E_WARNING);
+        try {
+            $result = $callback();
+        } finally {
+            restore_error_handler();
+        }
+        return $warnings;
+    }
+
     // Test horde_lz4_compress() function : basic functionality
     public function testCompressBasic()
     {
@@ -58,7 +75,8 @@
     // Test horde_lz4_compress() function : error conditions
     public function testCompressErrorConditionOne()
     {
-        $this->expectErrorMessage('horde_lz4_compress() expects at least 1 
argument, 0 given');
+        $this->expectException(ArgumentCountError::class);
+        $this->expectExceptionMessage('horde_lz4_compress() expects at least 1 
argument, 0 given');
 
         // Zero arguments
         horde_lz4_compress();
@@ -67,7 +85,8 @@
     // Test horde_lz4_compress() function : error conditions
     public function testCompressErrorConditionTwo()
     {
-        $this->expectErrorMessage('horde_lz4_compress() expects at most 2 
arguments, 3 given');
+        $this->expectException(ArgumentCountError::class);
+        $this->expectExceptionMessage('horde_lz4_compress() expects at most 2 
arguments, 3 given');
 
         // Test horde_lz4_compress with one more than the expected number
         // of arguments
@@ -79,9 +98,15 @@
     // Test horde_lz4_compress() function : error conditions
     public function testCompressErrorConditionThree()
     {
-        $this->expectWarning('PHPUnit\Framework\Error\Warning');
+        $warnings = $this->catchWarnings(function () {
+            return horde_lz4_compress(new stdClass);
+        }, $result);
 
-        horde_lz4_compress(new stdClass);
+        $this->assertFalse($result);
+        $this->assertEquals(
+            array('horde_lz4_compress: uncompressed data must be a string.'),
+            $warnings
+        );
     }
 
     // Test horde_lz4_compress() function : variation
@@ -108,7 +133,8 @@
     // Test horde_lz4_uncompress() function : error conditions
     public function testUncompressErrorConditionOne()
     {
-        $this->expectErrorMessage('horde_lz4_uncompress() expects exactly 1 
argument, 0 given');
+        $this->expectException(ArgumentCountError::class);
+        $this->expectExceptionMessage('horde_lz4_uncompress() expects exactly 
1 argument, 0 given');
 
         // Zero arguments
         horde_lz4_uncompress();
@@ -117,7 +143,8 @@
     // Test horde_lz4_uncompress() function : error conditions
     public function testUncompressErrorConditionTwo()
     {
-        $this->expectErrorMessage('horde_lz4_uncompress() expects exactly 1 
argument, 2 given');
+        $this->expectException(ArgumentCountError::class);
+        $this->expectExceptionMessage('horde_lz4_uncompress() expects exactly 
1 argument, 2 given');
 
         // Test horde_lz4_uncompress with one more than the expected number
         // of arguments
@@ -129,18 +156,30 @@
     // Test horde_lz4_uncompress() function : error conditions
     public function testUncompressErrorConditionThree()
     {
-        $this->expectWarning('PHPUnit\Framework\Error\Warning');
+        $warnings = $this->catchWarnings(function () {
+            return horde_lz4_uncompress(new stdClass);
+        }, $result);
 
-        horde_lz4_uncompress(new stdClass);
+        $this->assertFalse($result);
+        $this->assertEquals(
+            array('horde_lz4_uncompress: compressed data must be a string.'),
+            $warnings
+        );
     }
 
     // Test horde_lz4_uncompress() function : error conditions
     public function testUncompressErrorConditionFour()
     {
-        $this->expectWarning('PHPUnit\Framework\Error\Warning');
-
         // Testing with incorrect arguments
-        horde_lz4_uncompress(123);
+        $warnings = $this->catchWarnings(function () {
+            return horde_lz4_uncompress(123);
+        }, $result);
+
+        $this->assertFalse($result);
+        $this->assertEquals(
+            array('horde_lz4_uncompress: compressed data must be a string.'),
+            $warnings
+        );
     }
 
     // Test horde_lz4_compress() function : high compression

Reply via email to