Skip to content

Commit e11d6ff

Browse files
committed
refactor: Guard reflection setAccessible calls with PHP version check
1 parent 1cf767e commit e11d6ff

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

tests/Constraints/TypeTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ public function testValidateTypeNameWording($nameWording): void
9696
$t = new TypeConstraint();
9797
$r = new \ReflectionObject($t);
9898
$m = $r->getMethod('validateTypeNameWording');
99-
$m->setAccessible(true);
99+
if (PHP_VERSION_ID < 80100) {
100+
$m->setAccessible(true);
101+
}
100102

101103
$m->invoke($t, $nameWording);
102104
$this->expectNotToPerformAssertions();
@@ -107,7 +109,9 @@ public function testInvalidateTypeNameWording(): void
107109
$t = new TypeConstraint();
108110
$r = new \ReflectionObject($t);
109111
$m = $r->getMethod('validateTypeNameWording');
110-
$m->setAccessible(true);
112+
if (PHP_VERSION_ID < 80100) {
113+
$m->setAccessible(true);
114+
}
111115

112116
$this->expectException('\UnexpectedValueException');
113117
$this->expectExceptionMessage("No wording for 'notAValidTypeName' available, expected wordings are: [an integer, a number, a boolean, an object, an array, a string, a null]");

tests/SchemaStorageTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,11 +290,13 @@ public function testNoDoubleResolve(): void
290290
$uriRetriever->retrieve('test/schema')->willReturn($schemaOne)->shouldBeCalled();
291291

292292
$s = new SchemaStorage($uriRetriever->reveal());
293-
$schema = $s->addSchema('test/schema');
293+
$s->addSchema('test/schema');
294294

295295
$r = new \ReflectionObject($s);
296296
$p = $r->getProperty('schemas');
297-
$p->setAccessible(true);
297+
if (PHP_VERSION_ID < 80100) {
298+
$p->setAccessible(true);
299+
}
298300
$schemas = $p->getValue($s);
299301

300302
$this->assertEquals(

tests/Uri/Retrievers/FileGetContentsTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ public function testContentType(): void
3131

3232
$reflector = new \ReflectionObject($res);
3333
$fetchContentType = $reflector->getMethod('fetchContentType');
34-
$fetchContentType->setAccessible(true);
34+
if (PHP_VERSION_ID < 80100) {
35+
$fetchContentType->setAccessible(true);
36+
}
3537

3638
$this->assertTrue($fetchContentType->invoke($res, ['Content-Type: application/json']));
3739
$this->assertFalse($fetchContentType->invoke($res, ['X-Some-Header: whateverValue']));

tests/Uri/UriRetrieverTest.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,11 +267,15 @@ private function mockRetriever($schema): void
267267
$retrieverMock = $this->getRetrieverMock($schema);
268268

269269
$factory = new \ReflectionProperty(\JsonSchema\Constraints\BaseConstraint::class, 'factory');
270-
$factory->setAccessible(true);
270+
if (PHP_VERSION_ID < 80100) {
271+
$factory->setAccessible(true);
272+
}
271273
$factory = $factory->getValue($this->validator);
272274

273275
$retriever = new \ReflectionProperty(\JsonSchema\Constraints\Factory::class, 'uriRetriever');
274-
$retriever->setAccessible(true);
276+
if (PHP_VERSION_ID < 80100) {
277+
$retriever->setAccessible(true);
278+
}
275279
$retriever->setValue($factory, $retrieverMock);
276280
}
277281

@@ -362,12 +366,16 @@ public function testSchemaCache(): void
362366

363367
// inject a schema cache value
364368
$schemaCache = $reflector->getProperty('schemaCache');
365-
$schemaCache->setAccessible(true);
369+
if (PHP_VERSION_ID < 80100) {
370+
$schemaCache->setAccessible(true);
371+
}
366372
$schemaCache->setValue($retriever, ['local://test/uri' => 'testSchemaValue']);
367373

368374
// retrieve from schema cache
369375
$loadSchema = $reflector->getMethod('loadSchema');
370-
$loadSchema->setAccessible(true);
376+
if (PHP_VERSION_ID < 80100) {
377+
$loadSchema->setAccessible(true);
378+
}
371379
$this->assertEquals(
372380
'testSchemaValue',
373381
$loadSchema->invoke($retriever, 'local://test/uri')

0 commit comments

Comments
 (0)