diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 860643a..15f9aa2 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,15 +13,17 @@ jobs: runs-on: "ubuntu-24.04" strategy: + fail-fast: false matrix: php-version: - - "8.2" - "8.3" + - "8.4" + - "8.5" dependencies: - "highest" include: - dependencies: "lowest" - php-version: "8.2" + php-version: "8.3" steps: - name: "Checkout" diff --git a/.github/workflows/coding-standards.yaml b/.github/workflows/coding-standards.yaml index ad945c7..6349ab0 100644 --- a/.github/workflows/coding-standards.yaml +++ b/.github/workflows/coding-standards.yaml @@ -19,7 +19,7 @@ jobs: - name: "Install PHP" uses: "shivammathur/setup-php@v2" with: - php-version: "8.2" + php-version: "8.3" coverage: "none" tools: "cs2pr, pecl" diff --git a/.github/workflows/infection.yaml b/.github/workflows/infection.yaml index b7efdf5..4ada929 100644 --- a/.github/workflows/infection.yaml +++ b/.github/workflows/infection.yaml @@ -20,7 +20,7 @@ jobs: - name: "Install PHP" uses: "shivammathur/setup-php@v2" with: - php-version: "8.2" + php-version: "8.3" coverage: "pcov" - name: "Install dependencies with Composer" diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index 2b9533d..6039c51 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -19,7 +19,7 @@ jobs: - name: "Install PHP" uses: "shivammathur/setup-php@v2" with: - php-version: "8.2" + php-version: "8.3" coverage: "none" tools: "cs2pr, pecl" diff --git a/composer.json b/composer.json index b163b46..a1f410e 100644 --- a/composer.json +++ b/composer.json @@ -19,9 +19,9 @@ } }, "require": { - "php": "^8.2", + "php": "^8.3", "league/construct-finder": "^1.4", - "phpunit/phpunit": "^11 || ^12" + "phpunit/phpunit": "^12 || ^13" }, "require-dev": { "cdn77/coding-standard": "^7.0", diff --git a/src/Stub.php b/src/Stub.php index 6aee93b..306bda7 100644 --- a/src/Stub.php +++ b/src/Stub.php @@ -34,7 +34,6 @@ public static function create(string $class, array $properties = []): object throw new ReflectionException(sprintf('Property "%s" not found', $property)); } - $reflectionProperty->setAccessible(true); $reflectionProperty->setValue($stub, $value); } @@ -59,7 +58,6 @@ public static function extend(object $stub, array $newProperties = []): object /** @var array $properties */ $properties = []; foreach (self::getAllProperties($reflection) as $property) { - $property->setAccessible(true); if (! $property->isInitialized($stub)) { continue; } diff --git a/tests/StubTest.php b/tests/StubTest.php index c5bf365..e5cea84 100644 --- a/tests/StubTest.php +++ b/tests/StubTest.php @@ -9,6 +9,8 @@ use Error; use ReflectionException; +use const PHP_VERSION_ID; + final class StubTest extends BaseTestCase { public function testValueIsDefaultWhenNotSet(): void @@ -67,9 +69,16 @@ public function testPrivateReadonlyPropertyIsSetBypassingConstructor(): void self::assertSame('value', $stub->parentReadonlyProperty()); } - /** PHP does not allow setting protected or public readonly properties from different scopes */ + /** PHP < 8.4 does not allow setting public readonly properties from different scopes */ public function testPublicReadonlyPropertyCannotBeSet(): void { + if (PHP_VERSION_ID >= 80400) { + $stub = Stub::create(ClassWithReadonlyProperty::class, ['parentPublicReadonlyProperty' => 'value']); + self::assertSame('value', $stub->parentPublicReadonlyProperty); + + return; + } + try { Stub::create(ClassWithReadonlyProperty::class, ['parentPublicReadonlyProperty' => 'value']); } catch (Error $e) {