Skip to content

Commit 9b4e9a7

Browse files
authored
Remove calls to ReflectionMethod::setAccessible (#2751)
1 parent 4cc52c2 commit 9b4e9a7

File tree

6 files changed

+3
-20
lines changed

6 files changed

+3
-20
lines changed

tests/Doctrine/ODM/MongoDB/Tests/Functional/DocumentPersisterTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,6 @@ public function testExecuteInsertsRespectsWriteConcern(string $class, string|int
638638
->with($this->isType('array'), $this->logicalAnd($this->arrayHasKey('writeConcern'), $this->containsEqual(new WriteConcern($writeConcern))));
639639

640640
$reflectionProperty = new ReflectionProperty($documentPersister, 'collection');
641-
$reflectionProperty->setAccessible(true);
642641
$reflectionProperty->setValue($documentPersister, $collection);
643642

644643
$testDocument = new $class();
@@ -660,7 +659,6 @@ public function testExecuteInsertsOmitsWriteConcernInTransaction(string $class,
660659
->with($this->isType('array'), $this->logicalNot($this->arrayHasKey('writeConcern')));
661660

662661
$reflectionProperty = new ReflectionProperty($documentPersister, 'collection');
663-
$reflectionProperty->setAccessible(true);
664662
$reflectionProperty->setValue($documentPersister, $collection);
665663

666664
$testDocument = new $class();
@@ -682,7 +680,6 @@ public function testExecuteUpsertsRespectsWriteConcern(string $class, string|int
682680
->with($this->isType('array'), $this->isType('array'), $this->logicalAnd($this->arrayHasKey('writeConcern'), $this->containsEqual(new WriteConcern($writeConcern))));
683681

684682
$reflectionProperty = new ReflectionProperty($documentPersister, 'collection');
685-
$reflectionProperty->setAccessible(true);
686683
$reflectionProperty->setValue($documentPersister, $collection);
687684

688685
$testDocument = new $class();
@@ -705,7 +702,6 @@ public function testExecuteUpsertsDoesNotUseWriteConcernInTransaction(string $cl
705702
->with($this->isType('array'), $this->logicalNot($this->arrayHasKey('writeConcern')));
706703

707704
$reflectionProperty = new ReflectionProperty($documentPersister, 'collection');
708-
$reflectionProperty->setAccessible(true);
709705
$reflectionProperty->setValue($documentPersister, $collection);
710706

711707
$testDocument = new $class();
@@ -728,7 +724,6 @@ public function testRemoveRespectsWriteConcern(string $class, string|int $writeC
728724
->with($this->isType('array'), $this->logicalAnd($this->arrayHasKey('writeConcern'), $this->containsEqual(new WriteConcern($writeConcern))));
729725

730726
$reflectionProperty = new ReflectionProperty($documentPersister, 'collection');
731-
$reflectionProperty->setAccessible(true);
732727
$reflectionProperty->setValue($documentPersister, $collection);
733728

734729
$testDocument = new $class();
@@ -753,7 +748,6 @@ public function testRemoveDoesNotUseWriteConcernInTransaction(string $class, str
753748
->with($this->isType('array'), $this->logicalNot($this->arrayHasKey('writeConcern')));
754749

755750
$reflectionProperty = new ReflectionProperty($documentPersister, 'collection');
756-
$reflectionProperty->setAccessible(true);
757751
$reflectionProperty->setValue($documentPersister, $collection);
758752

759753
$testDocument = new $class();
@@ -777,7 +771,6 @@ public function testDefaultWriteConcernIsRespected(): void
777771
->with($this->isType('array'), $this->equalTo(['writeConcern' => new WriteConcern(0)]));
778772

779773
$reflectionProperty = new ReflectionProperty($documentPersister, 'collection');
780-
$reflectionProperty->setAccessible(true);
781774
$reflectionProperty->setValue($documentPersister, $collection);
782775

783776
$this->dm->getConfiguration()->setDefaultCommitOptions(['writeConcern' => new WriteConcern(0)]);
@@ -800,7 +793,6 @@ public function testDefaultWriteConcernIsIgnoredInTransaction(): void
800793
->with($this->isType('array'), $this->logicalNot($this->arrayHasKey('writeConcern')));
801794

802795
$reflectionProperty = new ReflectionProperty($documentPersister, 'collection');
803-
$reflectionProperty->setAccessible(true);
804796
$reflectionProperty->setValue($documentPersister, $collection);
805797

806798
$this->dm->getConfiguration()->setDefaultCommitOptions(['writeConcern' => new WriteConcern(1)]);
@@ -823,7 +815,6 @@ public function testDefaultWriteConcernIsRespectedBackwardCompatibility(): void
823815
->with($this->isType('array'), $this->equalTo(['writeConcern' => new WriteConcern(0)]));
824816

825817
$reflectionProperty = new ReflectionProperty($documentPersister, 'collection');
826-
$reflectionProperty->setAccessible(true);
827818
$reflectionProperty->setValue($documentPersister, $collection);
828819

829820
$this->dm->getConfiguration()->setDefaultCommitOptions(['w' => 0]);

tests/Doctrine/ODM/MongoDB/Tests/Functional/SplObjectHashCollisionsTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,6 @@ private function expectCount(string $prop, int $expected): void
7777
{
7878
$ro = new ReflectionObject($this->uow);
7979
$rp = $ro->getProperty($prop);
80-
$rp->setAccessible(true);
8180
self::assertCount($expected, $rp->getValue($this->uow));
8281
}
8382
}

tests/Doctrine/ODM/MongoDB/Tests/Mapping/XmlMappingDriverTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ public function testSetShardKeyOptionsByAttributes(): void
2929

3030
/** @uses XmlDriver::setShardKey */
3131
$m = new ReflectionMethod($driver::class, 'setShardKey');
32-
$m->setAccessible(true);
3332
$m->invoke($driver, $class, $element);
3433

3534
self::assertTrue($class->isSharded());

tests/Doctrine/ODM/MongoDB/Tests/Persisters/DocumentPersisterGetShardKeyQueryTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public function testGetShardKeyQueryScalars(): void
2626
$persister = $this->uow->getDocumentPersister($o::class);
2727

2828
$method = new ReflectionMethod($persister, 'getShardKeyQuery');
29-
$method->setAccessible(true);
3029

3130
self::assertSame(
3231
['int' => $o->int, 'string' => $o->string, 'bool' => $o->bool, 'float' => $o->float],
@@ -43,8 +42,7 @@ public function testGetShardKeyQueryObjects(): void
4342

4443
$persister = $this->uow->getDocumentPersister($o::class);
4544

46-
$method = new ReflectionMethod($persister, 'getShardKeyQuery');
47-
$method->setAccessible(true);
45+
$method = new ReflectionMethod($persister, 'getShardKeyQuery');
4846
$shardKeyQuery = $method->invoke($persister, $o);
4947

5048
self::assertInstanceOf(ObjectId::class, $shardKeyQuery['oid']);
@@ -69,8 +67,7 @@ public function testShardById(): void
6967

7068
$persister = $this->uow->getDocumentPersister($o::class);
7169

72-
$method = new ReflectionMethod($persister, 'getShardKeyQuery');
73-
$method->setAccessible(true);
70+
$method = new ReflectionMethod($persister, 'getShardKeyQuery');
7471
$shardKeyQuery = $method->invoke($persister, $o);
7572

7673
self::assertSame(['_id' => $o->identifier], $shardKeyQuery);
@@ -88,8 +85,7 @@ public function testShardByReference(): void
8885

8986
$persister = $this->uow->getDocumentPersister($o::class);
9087

91-
$method = new ReflectionMethod($persister, 'getShardKeyQuery');
92-
$method->setAccessible(true);
88+
$method = new ReflectionMethod($persister, 'getShardKeyQuery');
9389
$shardKeyQuery = $method->invoke($persister, $o);
9490

9591
self::assertSame(['reference.$id' => $userId], $shardKeyQuery);

tests/Doctrine/ODM/MongoDB/Tests/Query/BuilderTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,6 @@ public function testProxiedExprMethods(string $method, array $args = []): void
479479

480480
$qb = $this->getTestQueryBuilder();
481481
$reflectionProperty = new ReflectionProperty($qb, 'expr');
482-
$reflectionProperty->setAccessible(true);
483482
$reflectionProperty->setValue($qb, $expr);
484483

485484
self::assertSame($qb, $qb->$method(...$args));

tests/Doctrine/ODM/MongoDB/Tests/UnitOfWorkTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,6 @@ public function testTransactionalCommitOmitsWriteConcernInOperation(): void
535535
$documentPersister = $this->uow->getDocumentPersister(ForumUser::class);
536536

537537
$reflectionProperty = new ReflectionProperty($documentPersister, 'collection');
538-
$reflectionProperty->setAccessible(true);
539538
$reflectionProperty->setValue($documentPersister, $collection);
540539

541540
$user = new ForumUser();

0 commit comments

Comments
 (0)