From 76dbb5347cd36a969e75f83ed9cec012e985c15c Mon Sep 17 00:00:00 2001 From: Paragon Initiative Enterprises Date: Wed, 16 Feb 2022 11:25:28 -0500 Subject: [PATCH 1/2] Fix PHP 8.1.0 test code, widen phpunit --- composer.json | 2 +- tests/unit/RandomBytesTest.php | 4 +++- tests/unit/RandomIntTest.php | 8 ++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 34f1381..794e7fe 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,7 @@ "php": ">=5.2.0" }, "require-dev": { - "phpunit/phpunit": "4.*|5.*" + "phpunit/phpunit": "*" }, "suggest": { "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." diff --git a/tests/unit/RandomBytesTest.php b/tests/unit/RandomBytesTest.php index 4b3ab43..c6e2048 100644 --- a/tests/unit/RandomBytesTest.php +++ b/tests/unit/RandomBytesTest.php @@ -40,7 +40,9 @@ public function testOutput() random_bytes(12), random_bytes(64), random_bytes(64), - random_bytes(1.5) + PHP_VERSION_ID < 80100 + ? random_bytes(1.5) + : random_bytes(1) ); $this->assertTrue( diff --git a/tests/unit/RandomIntTest.php b/tests/unit/RandomIntTest.php index c8cbb0d..b6371b7 100644 --- a/tests/unit/RandomIntTest.php +++ b/tests/unit/RandomIntTest.php @@ -16,10 +16,14 @@ public function testOutput() random_int(-1000, 1000), random_int(~PHP_INT_MAX, PHP_INT_MAX), random_int("0", "1"), - random_int(0.11111, 0.99999), + PHP_VERSION_ID < 80100 + ? random_int(0.11111, 0.99999) + : 0, random_int($half_neg_max, PHP_INT_MAX), random_int(0.0, 255.0), - random_int(-4.5, -4.5), + PHP_VERSION_ID < 80100 + ? random_int(-4.5, -4.5) + : -4, random_int("1337e3","1337e3") ); From 4958521983edab0d6eba1e727dcb936228e34eaf Mon Sep 17 00:00:00 2001 From: Paragon Initiative Enterprises Date: Wed, 16 Feb 2022 11:29:48 -0500 Subject: [PATCH 2/2] Fix issue #175 --- lib/random.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/random.php b/lib/random.php index 6df1cb0..9429ec3 100644 --- a/lib/random.php +++ b/lib/random.php @@ -183,7 +183,7 @@ class_exists('COM') try { $RandomCompatCOMtest = new COM('CAPICOM.Utilities.1'); /** @psalm-suppress TypeDoesNotContainType */ - if (method_exists($RandomCompatCOMtest, 'GetRandom')) { + if (is_callable(array($RandomCompatCOMtest, 'GetRandom'))) { // See random_bytes_com_dotnet.php require_once $RandomCompatDIR.DIRECTORY_SEPARATOR.'random_bytes_com_dotnet.php'; }