Skip to content

Commit fe3e312

Browse files
authored
do not call setAccessible() on PHP 8.1+ (#1931)
This operation has no effect since PHP 8.1 and the method is deprecated in PHP 8.5.
1 parent 0197c6d commit fe3e312

File tree

6 files changed

+57
-19
lines changed

6 files changed

+57
-19
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858
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
5959
composer config minimum-stability dev
6060
composer config prefer-stable true
61-
composer require --dev --no-update symfony/phpunit-bridge
61+
composer require --dev --no-update symfony/phpunit-bridge:^7.3.2
6262
cat composer.json
6363
6464
echo ::endgroup::
@@ -93,7 +93,7 @@ jobs:
9393
cd "$CURRENT_DIR/$COMPONENT"
9494
9595
localExit=0
96-
composer require symfony/phpunit-bridge --no-update --no-install
96+
composer require symfony/phpunit-bridge:^7.3.2@dev --dev --no-update --no-install
9797
composer update --no-interaction --no-scripts --prefer-dist --optimize-autoloader ${{ matrix.strategy == 'lowest' && '--prefer-lowest' || '' }} $COMPOSER_OPTIONS || localExit=1
9898
./vendor/bin/simple-phpunit install
9999
echo ::endgroup::

src/Core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
- Support for Symfony 8
88

9+
### Changed
10+
11+
- `ResultMockFactory` does not call `ReflectionProperty::setAccessible()` on PHP 8.1+
12+
913
## 1.26.0
1014

1115
### Added

src/Core/src/Test/ResultMockFactory.php

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,9 @@ public static function create(string $class, array $data = [])
8484
// Make sure the Result is initialized
8585
$reflectionClass = new \ReflectionClass(Result::class);
8686
$initializedProperty = $reflectionClass->getProperty('initialized');
87-
$initializedProperty->setAccessible(true);
87+
if (\PHP_VERSION_ID < 80100) {
88+
$initializedProperty->setAccessible(true);
89+
}
8890

8991
/** @psalm-var \ReflectionClass<T> $reflectionClass */
9092
$reflectionClass = new \ReflectionClass($class);
@@ -116,7 +118,9 @@ public static function create(string $class, array $data = [])
116118
$property = $reflectionClass->getProperty($propertyName);
117119
}
118120
}
119-
$property->setAccessible(true);
121+
if (\PHP_VERSION_ID < 80100) {
122+
$property->setAccessible(true);
123+
}
120124
$property->setValue($object, $propertyValue);
121125
}
122126

@@ -151,10 +155,14 @@ public static function waiter(string $class, string $finalState)
151155

152156
$reflectionClass = new \ReflectionClass(Waiter::class);
153157
$propertyResponse = $reflectionClass->getProperty('response');
154-
$propertyResponse->setAccessible(true);
158+
if (\PHP_VERSION_ID < 80100) {
159+
$propertyResponse->setAccessible(true);
160+
}
155161

156162
$propertyState = $reflectionClass->getProperty('finalState');
157-
$propertyState->setAccessible(true);
163+
if (\PHP_VERSION_ID < 80100) {
164+
$propertyState->setAccessible(true);
165+
}
158166

159167
/** @psalm-var \ReflectionClass<T> $reflectionClass */
160168
$reflectionClass = new \ReflectionClass($class);
@@ -217,7 +225,9 @@ private static function addUndefinedProperties(\ReflectionClass $reflectionClass
217225
}
218226

219227
if (null !== $propertyValue) {
220-
$property->setAccessible(true);
228+
if (\PHP_VERSION_ID < 80100) {
229+
$property->setAccessible(true);
230+
}
221231
$property->setValue($object, $propertyValue);
222232
}
223233
}
@@ -260,14 +270,18 @@ private static function addPropertiesOnResult(\ReflectionClass $reflectionClass,
260270
if (class_exists($awsClientClass)) {
261271
$awsClientMock = (new \ReflectionClass($awsClientClass))->newInstanceWithoutConstructor();
262272
$property = $reflectionClass->getProperty('awsClient');
263-
$property->setAccessible(true);
273+
if (\PHP_VERSION_ID < 80100) {
274+
$property->setAccessible(true);
275+
}
264276
$property->setValue($object, $awsClientMock);
265277
}
266278

267279
if (class_exists($inputClass)) {
268280
$inputMock = (new \ReflectionClass($inputClass))->newInstanceWithoutConstructor();
269281
$property = $reflectionClass->getProperty('input');
270-
$property->setAccessible(true);
282+
if (\PHP_VERSION_ID < 80100) {
283+
$property->setAccessible(true);
284+
}
271285
$property->setValue($object, $inputMock);
272286
}
273287
}
@@ -278,15 +292,21 @@ private static function getResponseObject(): Response
278292
$response = $reflectionClass->newInstanceWithoutConstructor();
279293

280294
$property = $reflectionClass->getProperty('resolveResult');
281-
$property->setAccessible(true);
295+
if (\PHP_VERSION_ID < 80100) {
296+
$property->setAccessible(true);
297+
}
282298
$property->setValue($response, true);
283299

284300
$property = $reflectionClass->getProperty('bodyDownloaded');
285-
$property->setAccessible(true);
301+
if (\PHP_VERSION_ID < 80100) {
302+
$property->setAccessible(true);
303+
}
286304
$property->setValue($response, true);
287305

288306
$property = $reflectionClass->getProperty('httpResponse');
289-
$property->setAccessible(true);
307+
if (\PHP_VERSION_ID < 80100) {
308+
$property->setAccessible(true);
309+
}
290310
$property->setValue($response, new SimpleMockedResponse());
291311

292312
return $response;

src/Integration/Laravel/Cache/tests/Unit/ServiceProviderTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ public function testCreateStore()
2323
self::assertInstanceOf(AsyncAwsDynamoDbStore::class, $store);
2424
$refl = new \ReflectionClass($store);
2525
$property = $refl->getProperty('dynamoDb');
26-
$property->setAccessible(true);
26+
if (\PHP_VERSION_ID < 80100) {
27+
$property->setAccessible(true);
28+
}
2729
$client = $property->getValue($store);
2830

2931
$config = $client->getConfiguration();

src/Integration/Symfony/Bundle/tests/Functional/BundleInitializationTest.php

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ public function testIssue1758Cache()
186186

187187
$r = new \ReflectionObject($cache);
188188
$p = $r->getProperty('cache');
189-
$p->setAccessible(true);
189+
if (\PHP_VERSION_ID < 80100) {
190+
$p->setAccessible(true);
191+
}
190192

191193
$adapter = $p->getValue($cache);
192194
self::assertInstanceOf(ApcuAdapter::class, $adapter);
@@ -205,7 +207,9 @@ public function testIssue1758Provider()
205207

206208
$r = new \ReflectionClass(AbstractApi::class);
207209
$p = $r->getProperty('credentialProvider');
208-
$p->setAccessible(true);
210+
if (\PHP_VERSION_ID < 80100) {
211+
$p->setAccessible(true);
212+
}
209213

210214
$credentialProvider = $p->getValue($client);
211215
self::assertInstanceOf(InstanceProvider::class, $credentialProvider);
@@ -226,7 +230,9 @@ public function testIssue1758ProviderAndCache()
226230

227231
$r = new \ReflectionClass(AbstractApi::class);
228232
$p = $r->getProperty('credentialProvider');
229-
$p->setAccessible(true);
233+
if (\PHP_VERSION_ID < 80100) {
234+
$p->setAccessible(true);
235+
}
230236

231237
$credentialProvider = $p->getValue($client);
232238
self::assertInstanceOf(CacheProvider::class, $credentialProvider);
@@ -235,13 +241,17 @@ public function testIssue1758ProviderAndCache()
235241

236242
$r = new \ReflectionObject($cache);
237243
$p = $r->getProperty('cache');
238-
$p->setAccessible(true);
244+
if (\PHP_VERSION_ID < 80100) {
245+
$p->setAccessible(true);
246+
}
239247

240248
$adapter = $p->getValue($cache);
241249
self::assertInstanceOf(ApcuAdapter::class, $adapter);
242250

243251
$p = $r->getProperty('decorated');
244-
$p->setAccessible(true);
252+
if (\PHP_VERSION_ID < 80100) {
253+
$p->setAccessible(true);
254+
}
245255

246256
$decorated = $p->getValue($cache);
247257
self::assertInstanceOf(InstanceProvider::class, $decorated);

src/Service/Ses/tests/Unit/SesClientTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ public function testSignService()
159159
$ses = new SesClient([], new NullProvider());
160160
$refl = new \ReflectionClass($ses);
161161
$method = $refl->getMethod('getEndpointMetadata');
162-
$method->setAccessible(true);
162+
if (\PHP_VERSION_ID < 80100) {
163+
$method->setAccessible(true);
164+
}
163165
$data = $method->invokeArgs($ses, ['eu-central-1']);
164166

165167
self::assertEquals('ses', $data['signService']);

0 commit comments

Comments
 (0)