From 4ef3f54f23e0c8c5c9211e86a018081cc6e5c10d Mon Sep 17 00:00:00 2001 From: Christian Flothmann Date: Sun, 10 Aug 2025 14:20:34 +0200 Subject: [PATCH] do not call setAccessible() on PHP 8.1+ This operation has no effect since PHP 8.1 and the method is deprecated in PHP 8.5. --- .github/workflows/ci.yml | 4 +- src/Core/CHANGELOG.md | 4 ++ src/Core/src/Test/ResultMockFactory.php | 40 ++++++++++++++----- .../Cache/tests/Unit/ServiceProviderTest.php | 4 +- .../Functional/BundleInitializationTest.php | 20 +++++++--- src/Service/Ses/tests/Unit/SesClientTest.php | 4 +- 6 files changed, 57 insertions(+), 19 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e84b22645..86b16c51d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -58,7 +58,7 @@ jobs: sed -i -re 's/"require": \{/"repositories": [{"type": "path","url": "..\/..\/Core", "options": {"versions": {"async-aws\/core": "dev-master"}}, "canonical": ${{matrix.strategy != 'lowest' && 'true' || 'false'}} }],"require": \{/' composer.json composer config minimum-stability dev composer config prefer-stable true - composer require --dev --no-update symfony/phpunit-bridge + composer require --dev --no-update symfony/phpunit-bridge:^7.3.2 cat composer.json echo ::endgroup:: @@ -93,7 +93,7 @@ jobs: cd "$CURRENT_DIR/$COMPONENT" localExit=0 - composer require symfony/phpunit-bridge --no-update --no-install + composer require symfony/phpunit-bridge:^7.3.2@dev --dev --no-update --no-install composer update --no-interaction --no-scripts --prefer-dist --optimize-autoloader ${{ matrix.strategy == 'lowest' && '--prefer-lowest' || '' }} $COMPOSER_OPTIONS || localExit=1 ./vendor/bin/simple-phpunit install echo ::endgroup:: diff --git a/src/Core/CHANGELOG.md b/src/Core/CHANGELOG.md index c36f61f21..c7c1d08ad 100644 --- a/src/Core/CHANGELOG.md +++ b/src/Core/CHANGELOG.md @@ -6,6 +6,10 @@ - Support for Symfony 8 +### Changed + +- `ResultMockFactory` does not call `ReflectionProperty::setAccessible()` on PHP 8.1+ + ## 1.26.0 ### Added diff --git a/src/Core/src/Test/ResultMockFactory.php b/src/Core/src/Test/ResultMockFactory.php index b2ab34e35..dd98277aa 100644 --- a/src/Core/src/Test/ResultMockFactory.php +++ b/src/Core/src/Test/ResultMockFactory.php @@ -84,7 +84,9 @@ public static function create(string $class, array $data = []) // Make sure the Result is initialized $reflectionClass = new \ReflectionClass(Result::class); $initializedProperty = $reflectionClass->getProperty('initialized'); - $initializedProperty->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $initializedProperty->setAccessible(true); + } /** @psalm-var \ReflectionClass $reflectionClass */ $reflectionClass = new \ReflectionClass($class); @@ -116,7 +118,9 @@ public static function create(string $class, array $data = []) $property = $reflectionClass->getProperty($propertyName); } } - $property->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $property->setAccessible(true); + } $property->setValue($object, $propertyValue); } @@ -151,10 +155,14 @@ public static function waiter(string $class, string $finalState) $reflectionClass = new \ReflectionClass(Waiter::class); $propertyResponse = $reflectionClass->getProperty('response'); - $propertyResponse->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $propertyResponse->setAccessible(true); + } $propertyState = $reflectionClass->getProperty('finalState'); - $propertyState->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $propertyState->setAccessible(true); + } /** @psalm-var \ReflectionClass $reflectionClass */ $reflectionClass = new \ReflectionClass($class); @@ -217,7 +225,9 @@ private static function addUndefinedProperties(\ReflectionClass $reflectionClass } if (null !== $propertyValue) { - $property->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $property->setAccessible(true); + } $property->setValue($object, $propertyValue); } } @@ -260,14 +270,18 @@ private static function addPropertiesOnResult(\ReflectionClass $reflectionClass, if (class_exists($awsClientClass)) { $awsClientMock = (new \ReflectionClass($awsClientClass))->newInstanceWithoutConstructor(); $property = $reflectionClass->getProperty('awsClient'); - $property->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $property->setAccessible(true); + } $property->setValue($object, $awsClientMock); } if (class_exists($inputClass)) { $inputMock = (new \ReflectionClass($inputClass))->newInstanceWithoutConstructor(); $property = $reflectionClass->getProperty('input'); - $property->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $property->setAccessible(true); + } $property->setValue($object, $inputMock); } } @@ -278,15 +292,21 @@ private static function getResponseObject(): Response $response = $reflectionClass->newInstanceWithoutConstructor(); $property = $reflectionClass->getProperty('resolveResult'); - $property->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $property->setAccessible(true); + } $property->setValue($response, true); $property = $reflectionClass->getProperty('bodyDownloaded'); - $property->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $property->setAccessible(true); + } $property->setValue($response, true); $property = $reflectionClass->getProperty('httpResponse'); - $property->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $property->setAccessible(true); + } $property->setValue($response, new SimpleMockedResponse()); return $response; diff --git a/src/Integration/Laravel/Cache/tests/Unit/ServiceProviderTest.php b/src/Integration/Laravel/Cache/tests/Unit/ServiceProviderTest.php index 5ce57599a..409ac9090 100644 --- a/src/Integration/Laravel/Cache/tests/Unit/ServiceProviderTest.php +++ b/src/Integration/Laravel/Cache/tests/Unit/ServiceProviderTest.php @@ -23,7 +23,9 @@ public function testCreateStore() self::assertInstanceOf(AsyncAwsDynamoDbStore::class, $store); $refl = new \ReflectionClass($store); $property = $refl->getProperty('dynamoDb'); - $property->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $property->setAccessible(true); + } $client = $property->getValue($store); $config = $client->getConfiguration(); diff --git a/src/Integration/Symfony/Bundle/tests/Functional/BundleInitializationTest.php b/src/Integration/Symfony/Bundle/tests/Functional/BundleInitializationTest.php index 13272ba48..620dea6a4 100644 --- a/src/Integration/Symfony/Bundle/tests/Functional/BundleInitializationTest.php +++ b/src/Integration/Symfony/Bundle/tests/Functional/BundleInitializationTest.php @@ -186,7 +186,9 @@ public function testIssue1758Cache() $r = new \ReflectionObject($cache); $p = $r->getProperty('cache'); - $p->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $p->setAccessible(true); + } $adapter = $p->getValue($cache); self::assertInstanceOf(ApcuAdapter::class, $adapter); @@ -205,7 +207,9 @@ public function testIssue1758Provider() $r = new \ReflectionClass(AbstractApi::class); $p = $r->getProperty('credentialProvider'); - $p->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $p->setAccessible(true); + } $credentialProvider = $p->getValue($client); self::assertInstanceOf(InstanceProvider::class, $credentialProvider); @@ -226,7 +230,9 @@ public function testIssue1758ProviderAndCache() $r = new \ReflectionClass(AbstractApi::class); $p = $r->getProperty('credentialProvider'); - $p->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $p->setAccessible(true); + } $credentialProvider = $p->getValue($client); self::assertInstanceOf(CacheProvider::class, $credentialProvider); @@ -235,13 +241,17 @@ public function testIssue1758ProviderAndCache() $r = new \ReflectionObject($cache); $p = $r->getProperty('cache'); - $p->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $p->setAccessible(true); + } $adapter = $p->getValue($cache); self::assertInstanceOf(ApcuAdapter::class, $adapter); $p = $r->getProperty('decorated'); - $p->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $p->setAccessible(true); + } $decorated = $p->getValue($cache); self::assertInstanceOf(InstanceProvider::class, $decorated); diff --git a/src/Service/Ses/tests/Unit/SesClientTest.php b/src/Service/Ses/tests/Unit/SesClientTest.php index 53ace8894..58b2ce62a 100644 --- a/src/Service/Ses/tests/Unit/SesClientTest.php +++ b/src/Service/Ses/tests/Unit/SesClientTest.php @@ -159,7 +159,9 @@ public function testSignService() $ses = new SesClient([], new NullProvider()); $refl = new \ReflectionClass($ses); $method = $refl->getMethod('getEndpointMetadata'); - $method->setAccessible(true); + if (\PHP_VERSION_ID < 80100) { + $method->setAccessible(true); + } $data = $method->invokeArgs($ses, ['eu-central-1']); self::assertEquals('ses', $data['signService']);