Skip to content

Commit c9cfb30

Browse files
committed
fix(foxy): Fix PHP 8.5 deprecation setAccessible() in ReflectionProperty class.
1 parent 406a412 commit c9cfb30

File tree

4 files changed

+42
-30
lines changed

4 files changed

+42
-30
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Change Log
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)
1515
- Bug #112: Fix PHP `8.4` nullable type deprecation warnings in tests (@terabytesoftw)
16-
16+
- Bug #113: Fix PHP `8.5` deprecation `setAccessible()` in `ReflectionProperty` class (@terabytesoftw)
1717

1818
## 0.1.2 June 10, 2024
1919

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: 22 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,18 @@ public function testActivateBuildsAssetFallbackWithResolvedRootPackagePath(): vo
145147

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

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

153157
$fallbackReflection = new \ReflectionClass($assetFallback);
154158
$pathProperty = $fallbackReflection->getProperty('path');
155-
$pathProperty->setAccessible(true);
159+
if (\PHP_VERSION_ID < 80500) {
160+
$pathProperty->setAccessible(true);
161+
}
156162

157163
$expectedPath = rtrim((string) \getcwd(), '/\\')
158164
. DIRECTORY_SEPARATOR
@@ -172,7 +178,11 @@ public function testActivateUsesPackageNameForNonAbstractAssetManager(): void
172178

173179
$foxyReflection = new \ReflectionClass(Foxy::class);
174180
$assetManagersProperty = $foxyReflection->getProperty('assetManagers');
175-
$assetManagersProperty->setAccessible(true);
181+
182+
if (PHP_VERSION_ID < 80500) {
183+
$assetManagersProperty->setAccessible(true);
184+
}
185+
176186
$originalAssetManagers = $assetManagersProperty->getValue();
177187
$assetManagersProperty->setValue(null, [StubAssetManager::class]);
178188

@@ -181,12 +191,19 @@ public function testActivateUsesPackageNameForNonAbstractAssetManager(): void
181191
$foxy->activate($this->composer, $this->io);
182192

183193
$assetFallbackProperty = $foxyReflection->getProperty('assetFallback');
184-
$assetFallbackProperty->setAccessible(true);
194+
if (PHP_VERSION_ID < 80500) {
195+
$assetFallbackProperty->setAccessible(true);
196+
}
197+
185198
$assetFallback = $assetFallbackProperty->getValue($foxy);
186199

187200
$fallbackReflection = new \ReflectionClass($assetFallback);
201+
188202
$pathProperty = $fallbackReflection->getProperty('path');
189-
$pathProperty->setAccessible(true);
203+
204+
if (PHP_VERSION_ID < 80500) {
205+
$pathProperty->setAccessible(true);
206+
}
190207

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

0 commit comments

Comments
 (0)