Skip to content

Commit 9d8cadf

Browse files
authoredDec 10, 2022
Remove setAccessible() calls (#10286)
1 parent a17809c commit 9d8cadf

15 files changed

+14
-70
lines changed
 

‎lib/Doctrine/ORM/Proxy/ProxyFactory.php

-1
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ private function createLazyInitializer(ClassMetadata $classMetadata, EntityPersi
236236
continue;
237237
}
238238

239-
$property->setAccessible(true);
240239
$property->setValue($proxy, $property->getValue($entity));
241240
}
242241
};

‎tests/Doctrine/Tests/ORM/Cache/DefaultCacheTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,6 @@ public function testToIdentifierArrayShouldLookupForEntityIdentifier(): void
242242
$method = new ReflectionMethod($this->cache, 'toIdentifierArray');
243243
$property = new ReflectionProperty($entity, 'id');
244244

245-
$property->setAccessible(true);
246-
$method->setAccessible(true);
247245
$property->setValue($entity, $identifier);
248246

249247
self::assertEquals(['id' => $identifier], $method->invoke($this->cache, $metadata, $identifier));

‎tests/Doctrine/Tests/ORM/Cache/DefaultQueryCacheTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,6 @@ public function testGetAssociationValue(): void
580580
$rsm = new ResultSetMappingBuilder($this->em);
581581
$key = new QueryCacheKey('query.key1', 0);
582582

583-
$reflection->setAccessible(true);
584-
585583
$germany = new Country('Germany');
586584
$bavaria = new State('Bavaria', $germany);
587585
$wurzburg = new City('Würzburg', $bavaria);

‎tests/Doctrine/Tests/ORM/Cache/Persister/Collection/ReadWriteCachedCollectionPersisterTest.php

-12
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ public function testTransactionRollBackDeleteShouldClearQueue(): void
122122
$key = new CollectionCacheKey(State::class, 'cities', ['id' => 1]);
123123
$property = new ReflectionProperty(ReadWriteCachedCollectionPersister::class, 'queuedCache');
124124

125-
$property->setAccessible(true);
126-
127125
$this->region->expects(self::once())
128126
->method('lock')
129127
->with(self::equalTo($key))
@@ -154,8 +152,6 @@ public function testTransactionRollBackUpdateShouldClearQueue(): void
154152
$key = new CollectionCacheKey(State::class, 'cities', ['id' => 1]);
155153
$property = new ReflectionProperty(ReadWriteCachedCollectionPersister::class, 'queuedCache');
156154

157-
$property->setAccessible(true);
158-
159155
$this->region->expects(self::once())
160156
->method('lock')
161157
->with(self::equalTo($key))
@@ -186,8 +182,6 @@ public function testTransactionRollCommitDeleteShouldClearQueue(): void
186182
$key = new CollectionCacheKey(State::class, 'cities', ['id' => 1]);
187183
$property = new ReflectionProperty(ReadWriteCachedCollectionPersister::class, 'queuedCache');
188184

189-
$property->setAccessible(true);
190-
191185
$this->region->expects(self::once())
192186
->method('lock')
193187
->with(self::equalTo($key))
@@ -218,8 +212,6 @@ public function testTransactionRollCommitUpdateShouldClearQueue(): void
218212
$key = new CollectionCacheKey(State::class, 'cities', ['id' => 1]);
219213
$property = new ReflectionProperty(ReadWriteCachedCollectionPersister::class, 'queuedCache');
220214

221-
$property->setAccessible(true);
222-
223215
$this->region->expects(self::once())
224216
->method('lock')
225217
->with(self::equalTo($key))
@@ -249,8 +241,6 @@ public function testDeleteLockFailureShouldIgnoreQueue(): void
249241
$key = new CollectionCacheKey(State::class, 'cities', ['id' => 1]);
250242
$property = new ReflectionProperty(ReadWriteCachedCollectionPersister::class, 'queuedCache');
251243

252-
$property->setAccessible(true);
253-
254244
$this->region->expects(self::once())
255245
->method('lock')
256246
->with(self::equalTo($key))
@@ -274,8 +264,6 @@ public function testUpdateLockFailureShouldIgnoreQueue(): void
274264
$key = new CollectionCacheKey(State::class, 'cities', ['id' => 1]);
275265
$property = new ReflectionProperty(ReadWriteCachedCollectionPersister::class, 'queuedCache');
276266

277-
$property->setAccessible(true);
278-
279267
$this->region->expects(self::once())
280268
->method('lock')
281269
->with(self::equalTo($key))

‎tests/Doctrine/Tests/ORM/Cache/Persister/Entity/NonStrictReadWriteCachedEntityPersisterTest.php

-8
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ public function testTransactionRollBackShouldClearQueue(): void
2929
$persister = $this->createPersisterDefault();
3030
$property = new ReflectionProperty($persister, 'queuedCache');
3131

32-
$property->setAccessible(true);
33-
3432
$this->em->getUnitOfWork()->registerManaged($entity, ['id' => 1], ['id' => 1, 'name' => 'Foo']);
3533

3634
$persister->update($entity);
@@ -51,8 +49,6 @@ public function testInsertTransactionCommitShouldPutCache(): void
5149
$entry = new EntityCacheEntry(Country::class, ['id' => 1, 'name' => 'Foo']);
5250
$property = new ReflectionProperty($persister, 'queuedCache');
5351

54-
$property->setAccessible(true);
55-
5652
$this->region->expects(self::once())
5753
->method('put')
5854
->with(self::equalTo($key), self::equalTo($entry));
@@ -88,8 +84,6 @@ public function testUpdateTransactionCommitShouldPutCache(): void
8884
$entry = new EntityCacheEntry(Country::class, ['id' => 1, 'name' => 'Foo']);
8985
$property = new ReflectionProperty($persister, 'queuedCache');
9086

91-
$property->setAccessible(true);
92-
9387
$this->region->expects(self::once())
9488
->method('put')
9589
->with(self::equalTo($key), self::equalTo($entry));
@@ -116,8 +110,6 @@ public function testDeleteTransactionCommitShouldEvictCache(): void
116110
$key = new EntityCacheKey(Country::class, ['id' => 1]);
117111
$property = new ReflectionProperty($persister, 'queuedCache');
118112

119-
$property->setAccessible(true);
120-
121113
$this->region->expects(self::once())
122114
->method('evict')
123115
->with(self::equalTo($key));

‎tests/Doctrine/Tests/ORM/Cache/Persister/Entity/ReadWriteCachedEntityPersisterTest.php

-8
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ public function testTransactionRollBackShouldClearQueue(): void
117117
$key = new EntityCacheKey(Country::class, ['id' => 1]);
118118
$property = new ReflectionProperty(ReadWriteCachedEntityPersister::class, 'queuedCache');
119119

120-
$property->setAccessible(true);
121-
122120
$this->region->expects(self::exactly(2))
123121
->method('lock')
124122
->with(self::equalTo($key))
@@ -148,8 +146,6 @@ public function testTransactionCommitShouldClearQueue(): void
148146
$key = new EntityCacheKey(Country::class, ['id' => 1]);
149147
$property = new ReflectionProperty(ReadWriteCachedEntityPersister::class, 'queuedCache');
150148

151-
$property->setAccessible(true);
152-
153149
$this->region->expects(self::exactly(2))
154150
->method('lock')
155151
->with(self::equalTo($key))
@@ -178,8 +174,6 @@ public function testDeleteLockFailureShouldIgnoreQueue(): void
178174
$key = new EntityCacheKey(Country::class, ['id' => 1]);
179175
$property = new ReflectionProperty(ReadWriteCachedEntityPersister::class, 'queuedCache');
180176

181-
$property->setAccessible(true);
182-
183177
$this->region->expects(self::once())
184178
->method('lock')
185179
->with(self::equalTo($key))
@@ -202,8 +196,6 @@ public function testUpdateLockFailureShouldIgnoreQueue(): void
202196
$key = new EntityCacheKey(Country::class, ['id' => 1]);
203197
$property = new ReflectionProperty(ReadWriteCachedEntityPersister::class, 'queuedCache');
204198

205-
$property->setAccessible(true);
206-
207199
$this->region->expects(self::once())
208200
->method('lock')
209201
->with(self::equalTo($key))

‎tests/Doctrine/Tests/ORM/Functional/PaginationTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -637,8 +637,6 @@ public function testCountQueryStripsParametersInSelect(): void
637637

638638
$getCountQuery = new ReflectionMethod($paginator, 'getCountQuery');
639639

640-
$getCountQuery->setAccessible(true);
641-
642640
self::assertCount(2, $getCountQuery->invoke($paginator)->getParameters());
643641
self::assertCount(9, $paginator);
644642

‎tests/Doctrine/Tests/ORM/Functional/SQLFilterTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ public function testSQLFilterGetConnection(): void
273273
$filter = new MyLocaleFilter($em);
274274

275275
$reflMethod = new ReflectionMethod(SQLFilter::class, 'getConnection');
276-
$reflMethod->setAccessible(true);
277276

278277
self::assertSame($conn, $reflMethod->invoke($filter));
279278
}

‎tests/Doctrine/Tests/ORM/Functional/SecondLevelCacheQueryCacheTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,6 @@ public function testQueryCacheLifetime(): void
805805

806806
$getHash = static function (AbstractQuery $query) {
807807
$method = new ReflectionMethod($query, 'getHash');
808-
$method->setAccessible(true);
809808

810809
return $method->invoke($query);
811810
};

‎tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3123Test.php

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ public function __construct(UnitOfWork $uow)
4343
public function postFlush(): void
4444
{
4545
$property = new ReflectionProperty(UnitOfWork::class, 'extraUpdates');
46-
$property->setAccessible(true);
4746

4847
Assert::assertEmpty(
4948
$property->getValue($this->uow),

‎tests/Doctrine/Tests/ORM/Mapping/ClassMetadataFactoryTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,6 @@ public function testAcceptsEntityManagerInterfaceInstances(): void
414414
// not really the cleanest way to check it, but we won't add a getter to the CMF just for the sake of testing.
415415
$class = new ReflectionClass(ClassMetadataFactory::class);
416416
$property = $class->getProperty('em');
417-
$property->setAccessible(true);
418417
self::assertSame($entityManager, $property->getValue($classMetadataFactory));
419418
}
420419

‎tests/Doctrine/Tests/ORM/Mapping/ReflectionEmbeddedPropertyTest.php

+12-21
Original file line numberDiff line numberDiff line change
@@ -77,46 +77,37 @@ public function getTestedReflectionProperties(): array
7777
{
7878
return [
7979
[
80-
$this->getReflectionProperty(BooleanModel::class, 'id'),
81-
$this->getReflectionProperty(BooleanModel::class, 'id'),
80+
new ReflectionProperty(BooleanModel::class, 'id'),
81+
new ReflectionProperty(BooleanModel::class, 'id'),
8282
BooleanModel::class,
8383
],
8484
// reflection on embeddables that have properties defined in abstract ancestors:
8585
[
86-
$this->getReflectionProperty(BooleanModel::class, 'id'),
87-
$this->getReflectionProperty(AbstractEmbeddable::class, 'propertyInAbstractClass'),
86+
new ReflectionProperty(BooleanModel::class, 'id'),
87+
new ReflectionProperty(AbstractEmbeddable::class, 'propertyInAbstractClass'),
8888
ConcreteEmbeddable::class,
8989
],
9090
[
91-
$this->getReflectionProperty(BooleanModel::class, 'id'),
92-
$this->getReflectionProperty(ConcreteEmbeddable::class, 'propertyInConcreteClass'),
91+
new ReflectionProperty(BooleanModel::class, 'id'),
92+
new ReflectionProperty(ConcreteEmbeddable::class, 'propertyInConcreteClass'),
9393
ConcreteEmbeddable::class,
9494
],
9595
// reflection on classes extending internal PHP classes:
9696
[
97-
$this->getReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'),
98-
$this->getReflectionProperty(ArrayObjectExtendingClass::class, 'privateProperty'),
97+
new ReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'),
98+
new ReflectionProperty(ArrayObjectExtendingClass::class, 'privateProperty'),
9999
ArrayObjectExtendingClass::class,
100100
],
101101
[
102-
$this->getReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'),
103-
$this->getReflectionProperty(ArrayObjectExtendingClass::class, 'protectedProperty'),
102+
new ReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'),
103+
new ReflectionProperty(ArrayObjectExtendingClass::class, 'protectedProperty'),
104104
ArrayObjectExtendingClass::class,
105105
],
106106
[
107-
$this->getReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'),
108-
$this->getReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'),
107+
new ReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'),
108+
new ReflectionProperty(ArrayObjectExtendingClass::class, 'publicProperty'),
109109
ArrayObjectExtendingClass::class,
110110
],
111111
];
112112
}
113-
114-
private function getReflectionProperty(string $className, string $propertyName): ReflectionProperty
115-
{
116-
$reflectionProperty = new ReflectionProperty($className, $propertyName);
117-
118-
$reflectionProperty->setAccessible(true);
119-
120-
return $reflectionProperty;
121-
}
122113
}

‎tests/Doctrine/Tests/ORM/ORMSetupTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ public function testCacheNamespaceShouldBeGeneratedForApcu(): void
4444
$cache = $config->getMetadataCache();
4545

4646
$namespaceProperty = new ReflectionProperty(AbstractAdapter::class, 'namespace');
47-
$namespaceProperty->setAccessible(true);
4847

4948
self::assertInstanceOf(ApcuAdapter::class, $cache);
5049
self::assertSame('dc2_1effb2475fcfba4f9e8b8a1dbc8f3caf:', $namespaceProperty->getValue($cache));

‎tests/Doctrine/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ protected function setUp(): void
4949
public function testGetInsertSQLUsesTypeValuesSQL(): void
5050
{
5151
$method = new ReflectionMethod($this->persister, 'getInsertSQL');
52-
$method->setAccessible(true);
53-
54-
$sql = $method->invoke($this->persister);
52+
$sql = $method->invoke($this->persister);
5553

5654
self::assertEquals('INSERT INTO customtype_parents (customInteger, child_id) VALUES (ABS(?), ?)', $sql);
5755
}
@@ -101,9 +99,7 @@ public function testUpdateUsesTypeValuesSQL(): void
10199
public function testGetSelectConditionSQLUsesTypeValuesSQL(): void
102100
{
103101
$method = new ReflectionMethod($this->persister, 'getSelectConditionSQL');
104-
$method->setAccessible(true);
105-
106-
$sql = $method->invoke($this->persister, ['customInteger' => 1, 'child' => 1]);
102+
$sql = $method->invoke($this->persister, ['customInteger' => 1, 'child' => 1]);
107103

108104
self::assertEquals('t0.customInteger = ABS(?) AND t0.child_id = ?', $sql);
109105
}
@@ -113,7 +109,6 @@ public function testStripNonAlphanumericCharactersFromSelectColumnListSQL(): voi
113109
{
114110
$persister = new BasicEntityPersister($this->entityManager, $this->entityManager->getClassMetadata(NonAlphaColumnsEntity::class));
115111
$method = new ReflectionMethod($persister, 'getSelectColumnsSQL');
116-
$method->setAccessible(true);
117112

118113
self::assertEquals('t0."simple-entity-id" AS simpleentityid_1, t0."simple-entity-value" AS simpleentityvalue_2', $method->invoke($persister));
119114
}

‎tests/Doctrine/Tests/ORM/Proxy/ProxyFactoryTest.php

-2
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,6 @@ public function testProxyClonesParentFields(): void
179179

180180
// Set the id of the CompanyEmployee (which is in the parent CompanyPerson)
181181
$property = new ReflectionProperty(CompanyPerson::class, 'id');
182-
183-
$property->setAccessible(true);
184182
$property->setValue($companyEmployee, 42);
185183

186184
$classMetaData = $this->emMock->getClassMetadata(CompanyEmployee::class);

0 commit comments

Comments
 (0)