From 912fc74b5d032178a2b9540eb223722f579f564d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 25 Sep 2024 14:54:39 +0200 Subject: [PATCH 1/2] Reflection method setAccessible is useless As of PHP 8.1.0, calling this method has no effect; all properties are accessible by default. https://www.php.net/manual/en/reflectionproperty.setaccessible.php --- tests/GridFS/BucketFunctionalTest.php | 4 ---- tests/Operation/WatchFunctionalTest.php | 6 +----- 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/tests/GridFS/BucketFunctionalTest.php b/tests/GridFS/BucketFunctionalTest.php index ccbe6bf02..163c458c2 100644 --- a/tests/GridFS/BucketFunctionalTest.php +++ b/tests/GridFS/BucketFunctionalTest.php @@ -951,8 +951,6 @@ public function testResolveStreamContextForRead(): void fclose($stream); $method = new ReflectionMethod($this->bucket, 'resolveStreamContext'); - $method->setAccessible(true); - $context = $method->invokeArgs($this->bucket, ['gridfs://bucket/filename', 'rb', []]); $this->assertIsArray($context); @@ -967,8 +965,6 @@ public function testResolveStreamContextForRead(): void public function testResolveStreamContextForWrite(): void { $method = new ReflectionMethod($this->bucket, 'resolveStreamContext'); - $method->setAccessible(true); - $context = $method->invokeArgs($this->bucket, ['gridfs://bucket/filename', 'wb', []]); $this->assertIsArray($context); diff --git a/tests/Operation/WatchFunctionalTest.php b/tests/Operation/WatchFunctionalTest.php index cc6690b0f..37ba39ada 100644 --- a/tests/Operation/WatchFunctionalTest.php +++ b/tests/Operation/WatchFunctionalTest.php @@ -724,10 +724,7 @@ public function testInitialCursorIsNotClosed(): void $this->assertNotEquals('0', (string) $changeStream->getCursorId(true)); $rc = new ReflectionClass(ChangeStream::class); - $rp = $rc->getProperty('iterator'); - $rp->setAccessible(true); - - $iterator = $rp->getValue($changeStream); + $iterator = $rc->getProperty('iterator')->getValue($changeStream); $this->assertInstanceOf('IteratorIterator', $iterator); @@ -1225,7 +1222,6 @@ public function testSessionFreed(): void $rc = new ReflectionClass($changeStream); $rp = $rc->getProperty('resumeCallable'); - $rp->setAccessible(true); $this->assertIsCallable($rp->getValue($changeStream)); From e962256bca91e1c59aab924a258c0a9516fc771e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Tamarelle?= Date: Wed, 25 Sep 2024 14:56:04 +0200 Subject: [PATCH 2/2] Replace deprecated ObjectHasAttribute with ObjectHasProperty --- tests/Operation/WatchFunctionalTest.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/Operation/WatchFunctionalTest.php b/tests/Operation/WatchFunctionalTest.php index 37ba39ada..df4c98fdc 100644 --- a/tests/Operation/WatchFunctionalTest.php +++ b/tests/Operation/WatchFunctionalTest.php @@ -25,6 +25,7 @@ use MongoDB\Operation\InsertOne; use MongoDB\Operation\Watch; use MongoDB\Tests\CommandObserver; +use PHPUnit\Framework\Constraint\ObjectHasProperty; use PHPUnit\Framework\ExpectationFailedException; use ReflectionClass; use stdClass; @@ -1278,9 +1279,9 @@ function (array $event) use (&$aggregateCommands): void { $aggregateCommands[0]['pipeline'][0]->{'$changeStream'}, $this->logicalNot( $this->logicalOr( - $this->objectHasAttribute('resumeAfter'), - $this->objectHasAttribute('startAfter'), - $this->objectHasAttribute('startAtOperationTime'), + new ObjectHasProperty('resumeAfter'), + new ObjectHasProperty('startAfter'), + new ObjectHasProperty('startAtOperationTime'), ), ), ); @@ -1288,9 +1289,9 @@ function (array $event) use (&$aggregateCommands): void { $this->assertThat( $aggregateCommands[1]['pipeline'][0]->{'$changeStream'}, $this->logicalOr( - $this->objectHasAttribute('resumeAfter'), - $this->objectHasAttribute('startAfter'), - $this->objectHasAttribute('startAtOperationTime'), + new ObjectHasProperty('resumeAfter'), + new ObjectHasProperty('startAfter'), + new ObjectHasProperty('startAtOperationTime'), ), );