Skip to content

Commit 434f22d

Browse files
fix(foxy): Fix PHP 8.5 deprecation of setAccessible() in ReflectionProperty class. (#114)
1 parent 406a412 commit 434f22d

File tree

4 files changed

+48
-31
lines changed

4 files changed

+48
-31
lines changed

.github/workflows/build.yml

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,22 @@
1+
---
12
on:
2-
pull_request:
3+
pull_request: &ignore-paths
34
paths-ignore:
4-
- 'docs/**'
5-
- 'README.md'
6-
- 'CHANGELOG.md'
7-
- '.gitignore'
8-
- '.gitattributes'
9-
- 'infection.json.dist'
10-
- 'psalm.xml'
5+
- ".gitattributes"
6+
- ".gitignore"
7+
- "CHANGELOG.md"
8+
- "docs/**"
9+
- "README.md"
1110

12-
push:
13-
paths-ignore:
14-
- 'docs/**'
15-
- 'README.md'
16-
- 'CHANGELOG.md'
17-
- '.gitignore'
18-
- '.gitattributes'
19-
- 'infection.json.dist'
20-
- 'psalm.xml'
11+
push: *ignore-paths
2112

2213
name: build
2314

15+
permissions:
16+
contents: read
17+
2418
jobs:
2519
phpunit:
26-
uses: php-forge/actions/.github/workflows/phpunit.yml@main
20+
uses: yii2-framework/actions/.github/workflows/phpunit.yml@main
2721
secrets:
2822
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
29-
with:
30-
os: >-
31-
['ubuntu-latest', 'windows-latest']
32-
php-version: >-
33-
['8.1', '8.2', '8.3', '8.4']

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ Change Log
1212
- Bug #109: Respect `root-package-json-dir` for `package.json` read/write (@terabytesoftw)
1313
- Bug #110: Preserve nested empty arrays when rewriting `package.json` (@terabytesoftw)
1414
- Bug #111: Throw `RuntimeException` class on asset/json `I/O` failures (@terabytesoftw)
15-
- Bug #112: Fix PHP `8.4` nullable type deprecation warnings in tests (@terabytesoftw)
16-
15+
- Bug #112: Update `README.md` and add development and testing documentation (@terabytesoftw)
16+
- Bug #113: Fix PHP `8.4` nullable type deprecation warnings in tests (@terabytesoftw)
17+
- Bug #114: Fix PHP `8.5` deprecation of `setAccessible()` in `ReflectionProperty` class (`@terabytesoftw`)
1718

1819
## 0.1.2 June 10, 2024
1920

src/Util/ConsoleUtil.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
use Symfony\Component\Console\Input\ArgvInput;
1919
use Symfony\Component\Console\Input\InputInterface;
2020

21+
use const PHP_VERSION_ID;
22+
2123
/**
2224
* Helper for console.
2325
*
@@ -36,7 +38,11 @@ public static function getInput(IOInterface $io): InputInterface
3638

3739
if ($ref->hasProperty('input')) {
3840
$prop = $ref->getProperty('input');
39-
$prop->setAccessible(true);
41+
42+
if (PHP_VERSION_ID < 80500) {
43+
$prop->setAccessible(true);
44+
}
45+
4046
$input = $prop->getValue($io);
4147

4248
if ($input instanceof InputInterface) {

tests/FoxyTest.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
use Foxy\Tests\Fixtures\Asset\StubAssetManager;
2929
use PHPUnit\Framework\MockObject\MockObject;
3030

31+
use const PHP_VERSION_ID;
32+
3133
final class FoxyTest extends \PHPUnit\Framework\TestCase
3234
{
3335
private Composer|MockObject $composer;
@@ -145,14 +147,21 @@ public function testActivateBuildsAssetFallbackWithResolvedRootPackagePath(): vo
145147

146148
$foxyReflection = new \ReflectionClass($foxy);
147149
$assetFallbackProperty = $foxyReflection->getProperty('assetFallback');
148-
$assetFallbackProperty->setAccessible(true);
150+
151+
if (PHP_VERSION_ID < 80500) {
152+
$assetFallbackProperty->setAccessible(true);
153+
}
154+
149155
$assetFallback = $assetFallbackProperty->getValue($foxy);
150156

151157
$this->assertInstanceOf(\Foxy\Fallback\AssetFallback::class, $assetFallback);
152158

153159
$fallbackReflection = new \ReflectionClass($assetFallback);
154160
$pathProperty = $fallbackReflection->getProperty('path');
155-
$pathProperty->setAccessible(true);
161+
162+
if (PHP_VERSION_ID < 80500) {
163+
$pathProperty->setAccessible(true);
164+
}
156165

157166
$expectedPath = rtrim((string) \getcwd(), '/\\')
158167
. DIRECTORY_SEPARATOR
@@ -172,7 +181,11 @@ public function testActivateUsesPackageNameForNonAbstractAssetManager(): void
172181

173182
$foxyReflection = new \ReflectionClass(Foxy::class);
174183
$assetManagersProperty = $foxyReflection->getProperty('assetManagers');
175-
$assetManagersProperty->setAccessible(true);
184+
185+
if (PHP_VERSION_ID < 80500) {
186+
$assetManagersProperty->setAccessible(true);
187+
}
188+
176189
$originalAssetManagers = $assetManagersProperty->getValue();
177190
$assetManagersProperty->setValue(null, [StubAssetManager::class]);
178191

@@ -181,12 +194,20 @@ public function testActivateUsesPackageNameForNonAbstractAssetManager(): void
181194
$foxy->activate($this->composer, $this->io);
182195

183196
$assetFallbackProperty = $foxyReflection->getProperty('assetFallback');
184-
$assetFallbackProperty->setAccessible(true);
197+
198+
if (PHP_VERSION_ID < 80500) {
199+
$assetFallbackProperty->setAccessible(true);
200+
}
201+
185202
$assetFallback = $assetFallbackProperty->getValue($foxy);
186203

187204
$fallbackReflection = new \ReflectionClass($assetFallback);
205+
188206
$pathProperty = $fallbackReflection->getProperty('path');
189-
$pathProperty->setAccessible(true);
207+
208+
if (PHP_VERSION_ID < 80500) {
209+
$pathProperty->setAccessible(true);
210+
}
190211

191212
$this->assertSame('stub-package.json', $pathProperty->getValue($assetFallback));
192213
} finally {

0 commit comments

Comments
 (0)