From 512690dba4f021c11fc1ef758bffe6080c1cb9b1 Mon Sep 17 00:00:00 2001 From: Juliette <663378+jrfnl@users.noreply.github.com> Date: Wed, 30 Aug 2023 11:42:33 +0200 Subject: [PATCH] PHP 8.3 | Tests: fix deprecation notices (#11599) * PHP 8.3 | ZipDownloaderTest: fix deprecation notice Calling `ReflectionProperty::setValue()` with only one argument (to set a static property) is deprecated. Passing `null` as the first (`$object`) parameter will work cross-version. As the `ZipDownloaderTest::setPrivateProperty()` method has a `null` default value for the `$obj` parameter anyway, this means the if/else toggle can be removed. Ref: https://wiki.php.net/rfc/deprecate_functions_with_overloaded_signatures#reflectionpropertysetvalue * PHP 8.3 | InstalledVersionsTest: fix deprecation notice Calling `ReflectionProperty::setValue()` with only one argument (to set a static property) is deprecated. Passing `null` as the first (`$object`) parameter will work cross-version. Ref: https://wiki.php.net/rfc/deprecate_functions_with_overloaded_signatures#reflectionpropertysetvalue --------- Co-authored-by: jrfnl --- tests/Composer/Test/Downloader/ZipDownloaderTest.php | 6 +----- tests/Composer/Test/InstalledVersionsTest.php | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/tests/Composer/Test/Downloader/ZipDownloaderTest.php b/tests/Composer/Test/Downloader/ZipDownloaderTest.php index ced6c0992..80e9378d9 100644 --- a/tests/Composer/Test/Downloader/ZipDownloaderTest.php +++ b/tests/Composer/Test/Downloader/ZipDownloaderTest.php @@ -65,11 +65,7 @@ class ZipDownloaderTest extends TestCase $reflectionClass = new \ReflectionClass('Composer\Downloader\ZipDownloader'); $reflectedProperty = $reflectionClass->getProperty($name); $reflectedProperty->setAccessible(true); - if ($obj === null) { - $reflectedProperty->setValue($value); - } else { - $reflectedProperty->setValue($obj, $value); - } + $reflectedProperty->setValue($obj, $value); } public function testErrorMessages(): void diff --git a/tests/Composer/Test/InstalledVersionsTest.php b/tests/Composer/Test/InstalledVersionsTest.php index 6edd91e04..c227675ca 100644 --- a/tests/Composer/Test/InstalledVersionsTest.php +++ b/tests/Composer/Test/InstalledVersionsTest.php @@ -33,14 +33,14 @@ class InstalledVersionsTest extends TestCase $prop = new \ReflectionProperty('Composer\Autoload\ClassLoader', 'registeredLoaders'); $prop->setAccessible(true); self::$previousRegisteredLoaders = $prop->getValue(); - $prop->setValue([]); + $prop->setValue(null, []); } public static function tearDownAfterClass(): void { $prop = new \ReflectionProperty('Composer\Autoload\ClassLoader', 'registeredLoaders'); $prop->setAccessible(true); - $prop->setValue(self::$previousRegisteredLoaders); + $prop->setValue(null, self::$previousRegisteredLoaders); InstalledVersions::reload(null); // @phpstan-ignore-line }