Skip to content

Fix deprecations in tests #1458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions tests/GridFS/BucketFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,6 @@ public function testResolveStreamContextForRead(): void
fclose($stream);

$method = new ReflectionMethod($this->bucket, 'resolveStreamContext');
$method->setAccessible(true);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReflectionMethod::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


$context = $method->invokeArgs($this->bucket, ['gridfs://bucket/filename', 'rb', []]);

$this->assertIsArray($context);
Expand All @@ -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);
Expand Down
19 changes: 8 additions & 11 deletions tests/Operation/WatchFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -724,10 +725,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);

Expand Down Expand Up @@ -1225,7 +1223,6 @@ public function testSessionFreed(): void

$rc = new ReflectionClass($changeStream);
$rp = $rc->getProperty('resumeCallable');
$rp->setAccessible(true);

$this->assertIsCallable($rp->getValue($changeStream));

Expand Down Expand Up @@ -1282,19 +1279,19 @@ 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'),
Comment on lines -1285 to +1284
Copy link
Member Author

@GromNaN GromNaN Sep 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ObjectHasAttribute is deprecated and there is no helper for ObjectHasProperty. I don't want to add the helper, to avoid conflict if they decide to add it later.

),
),
);

$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'),
),
);

Expand Down