Skip to content

Commit e70a06d

Browse files
authored
Merge pull request #1538 from Roave/fix/#1537-correct-reflectionproperty-setvalue-deprecation
ReflectionProperty#setValue() always requires 2 arguments
2 parents 70f4290 + 6ec37ba commit e70a06d

File tree

10 files changed

+7
-18
lines changed

10 files changed

+7
-18
lines changed

phpunit.xml.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
colors="true"
77
executionOrder="random"
88
cacheDirectory=".phpunit.cache"
9+
failOnDeprecation="true"
910
>
1011
<source>
1112
<include>

src/Reflection/Adapter/ReflectionClass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,7 +600,7 @@ public function setStaticPropertyValue(string $name, mixed $value): void
600600
throw new CoreReflectionException(sprintf('Class %s does not have a property named %s', $this->betterReflectionClass->getName(), $name));
601601
}
602602

603-
$property->setValue($value);
603+
$property->setValue(null, $value);
604604
}
605605

606606
/**

test/unit/Reflection/Adapter/ReflectionClassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,7 +728,7 @@ public function testSetStaticPropertyValue(): void
728728
$betterReflectionProperty
729729
->expects($this->once())
730730
->method('setValue')
731-
->with(123);
731+
->with(null, 123);
732732

733733
$betterReflectionClass = $this->createMock(BetterReflectionClass::class);
734734
$betterReflectionClass

test/unit/Reflection/Adapter/ReflectionObjectTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,6 @@ public function testGetAttributesWithName(): void
958958
$betterReflectionObject = $betterReflectionObjectReflection->newInstanceWithoutConstructor();
959959

960960
$betterReflectionObjectClassPropertyReflection = $betterReflectionObjectReflection->getProperty('reflectionClass');
961-
$betterReflectionObjectClassPropertyReflection->setAccessible(true);
962961
$betterReflectionObjectClassPropertyReflection->setValue($betterReflectionObject, $betterReflectionClass);
963962

964963
$reflectionObjectAdapter = new ReflectionObjectAdapter($betterReflectionObject);
@@ -1067,7 +1066,6 @@ public function testGetAttributesWithInstance(): void
10671066
$betterReflectionObject = $betterReflectionObjectReflection->newInstanceWithoutConstructor();
10681067

10691068
$betterReflectionObjectClassPropertyReflection = $betterReflectionObjectReflection->getProperty('reflectionClass');
1070-
$betterReflectionObjectClassPropertyReflection->setAccessible(true);
10711069
$betterReflectionObjectClassPropertyReflection->setValue($betterReflectionObject, $betterReflectionClass);
10721070

10731071
$reflectionObjectAdapter = new ReflectionObjectAdapter($betterReflectionObject);

test/unit/Reflection/ReflectionObjectTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,11 +151,9 @@ public function testExceptionThrownWhenInvalidInstanceGiven(): void
151151
$reflectionObjectReflection = new CoreReflectionObject($classInfo);
152152

153153
$reflectionObjectObjectReflection = $reflectionObjectReflection->getProperty('object');
154-
$reflectionObjectObjectReflection->setAccessible(true);
155154
$reflectionObjectObjectReflection->setValue($classInfo, new stdClass());
156155

157156
$reflectionObjectReflectionClassReflection = $reflectionObjectReflection->getProperty('reflectionClass');
158-
$reflectionObjectReflectionClassReflection->setAccessible(true);
159157
$reflectionObjectReflectionClassReflection->setValue($classInfo, $mockClass);
160158

161159
$this->expectException(InvalidArgumentException::class);
@@ -300,7 +298,6 @@ public function testReflectionObjectOverridesAllMethodsInReflectionClass(string
300298

301299
foreach ($properties as $propertyName => $propertyValue) {
302300
$mockReflectionClassNodeReflection = $mockReflectionClassReflection->getProperty($propertyName);
303-
$mockReflectionClassNodeReflection->setAccessible(true);
304301
$mockReflectionClassNodeReflection->setValue($mockReflectionClass, $propertyValue);
305302
}
306303

@@ -311,7 +308,6 @@ public function testReflectionObjectOverridesAllMethodsInReflectionClass(string
311308
// the mocked reflectionclass above
312309
$reflectionObjectReflection = new CoreReflectionObject($reflectionObject);
313310
$reflectionObjectReflectionClassPropertyReflection = $reflectionObjectReflection->getProperty('reflectionClass');
314-
$reflectionObjectReflectionClassPropertyReflection->setAccessible(true);
315311
$reflectionObjectReflectionClassPropertyReflection->setValue($reflectionObject, $mockReflectionClass);
316312

317313
$reflectionObjectReflectionMethod = $reflectionObjectReflection->getMethod($methodName);

test/unit/SourceLocator/Ast/Exception/ParseToAstFailureTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,6 @@ public function testLocatedSourceWithFilename(): void
172172
$locatedSource = new LocatedSource('<?php abc', 'Whatever');
173173

174174
$filenameProperty = new ReflectionProperty($locatedSource, 'filename');
175-
$filenameProperty->setAccessible(true);
176175
$filenameProperty->setValue($locatedSource, '/foo/bar');
177176

178177
$previous = new Error('Some error message', ['startLine' => 1]);
@@ -209,7 +208,6 @@ public function testUnknownError(): void
209208
$locatedSource = new LocatedSource('<?php abc', 'Whatever');
210209

211210
$filenameProperty = new ReflectionProperty($locatedSource, 'filename');
212-
$filenameProperty->setAccessible(true);
213211
$filenameProperty->setValue($locatedSource, '/foo/bar');
214212

215213
$previous = new Exception('Unknown error');

test/unit/SourceLocator/SourceStubber/PhpStormStubsSourceStubberTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -765,20 +765,20 @@ public function testUpdateConstantValue(): void
765765
$stubberReflection = new CoreReflectionClass($sourceStubber);
766766

767767
$stubDirectoryReflection = $stubberReflection->getProperty('stubsDirectory');
768-
$stubDirectoryReflection->setAccessible(true);
769768
$stubDirectoryReflection->setValue($sourceStubber, __DIR__ . '/../../Fixture');
770769

771770
$classMapReflection = $stubberReflection->getProperty('classMap');
772-
$classMapReflection->setAccessible(true);
771+
773772
$classMapValue = $classMapReflection->getValue();
774773
$classMapValue['roave\betterreflectiontest\fixture\fakeconstants'] = 'fakeconstants/FakeConstantsStub.php';
775774
$classMapReflection->setValue($classMapReflection, $classMapValue);
776775

777776
$constantMapReflection = $stubberReflection->getProperty('constantMap');
778-
$constantMapReflection->setAccessible(true);
777+
779778
$constantMapValue = $constantMapReflection->getValue();
780779
$constantMapValue['define_constant'] = 'fakeconstants/FakeConstantsStub.php';
781780
$constantMapValue['roave\betterreflectiontest\fixture\const_constant'] = 'fakeconstants/FakeConstantsStub.php';
781+
782782
$constantMapReflection->setValue($constantMapReflection, $constantMapValue);
783783

784784
$classConstantStub = $sourceStubber->generateClassStub('Roave\BetterReflectionTest\Fixture\FakeConstants');

test/unit/SourceLocator/Type/AnonymousClassObjectSourceLocatorTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,6 @@ public function testExceptionIfAnonymousClassNotFoundOnExpectedLine(): void
165165
->willReturn(0);
166166

167167
$coreReflectionPropertyInSourceLocatatorReflection = $sourceLocatorReflection->getProperty('coreClassReflection');
168-
$coreReflectionPropertyInSourceLocatatorReflection->setAccessible(true);
169168
$coreReflectionPropertyInSourceLocatatorReflection->setValue($sourceLocator, $coreReflectionPropertyMock);
170169

171170
$this->expectException(NoAnonymousClassOnLine::class);
@@ -262,7 +261,6 @@ public function testExceptionIfSourceFileIsNotReadable(): void
262261

263262
$sourceLocatorReflection = new CoreReflectionClass($sourceLocator);
264263
$sourceLocatorReflectionCoreClassReflectionProperty = $sourceLocatorReflection->getProperty('coreClassReflection');
265-
$sourceLocatorReflectionCoreClassReflectionProperty->setAccessible(true);
266264
$sourceLocatorReflectionCoreClassReflectionProperty->setValue($sourceLocator, $sourceLocatorReflectionCoreClassReflectionPropertyValue);
267265

268266
$this->expectException(InvalidFileLocation::class);

test/unit/SourceLocator/Type/AutoloadSourceLocatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ public function testNullReturnedWhenInvalidTypeGiven(): void
345345
$type = new IdentifierType();
346346
$typeReflection = new ReflectionObject($type);
347347
$prop = $typeReflection->getProperty('name');
348-
$prop->setAccessible(true);
348+
349349
$prop->setValue($type, 'nonsense');
350350

351351
$identifier = new Identifier('foo', $type);

test/unit/SourceLocator/Type/ClosureSourceLocatorTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ public function testExceptionIfClosureNotFoundOnExpectedLine(): void
141141
->willReturn(0);
142142

143143
$coreReflectionPropertyInSourceLocatatorReflection = $sourceLocatorReflection->getProperty('coreFunctionReflection');
144-
$coreReflectionPropertyInSourceLocatatorReflection->setAccessible(true);
145144
$coreReflectionPropertyInSourceLocatatorReflection->setValue($sourceLocator, $coreReflectionPropertyMock);
146145

147146
$this->expectException(NoClosureOnLine::class);
@@ -221,7 +220,6 @@ public function testExceptionIfSourceFileIsNotReadable(): void
221220

222221
$sourceLocatorReflection = new CoreReflectionClass($sourceLocator);
223222
$sourceLocatorReflectionCoreFunctionReflectionProperty = $sourceLocatorReflection->getProperty('coreFunctionReflection');
224-
$sourceLocatorReflectionCoreFunctionReflectionProperty->setAccessible(true);
225223
$sourceLocatorReflectionCoreFunctionReflectionProperty->setValue($sourceLocator, $sourceLocatorReflectionCoreFunctionReflectionPropertyValue);
226224

227225
$this->expectException(InvalidFileLocation::class);

0 commit comments

Comments
 (0)