Skip to content

PHPLIB-766: Fix deprecation notices for PHP 8.1 #874

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 5 commits into from
Dec 1, 2021
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: 2 additions & 2 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ class Collection
*/
public function __construct(Manager $manager, $databaseName, $collectionName, array $options = [])
{
if (strlen($databaseName) < 1) {
if (strlen((string) $databaseName) < 1) {
throw new InvalidArgumentException('$databaseName is invalid: ' . $databaseName);
}

if (strlen($collectionName) < 1) {
if (strlen((string) $collectionName) < 1) {
throw new InvalidArgumentException('$collectionName is invalid: ' . $collectionName);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ class Database
*/
public function __construct(Manager $manager, $databaseName, array $options = [])
{
if (strlen($databaseName) < 1) {
if (strlen((string) $databaseName) < 1) {
throw new InvalidArgumentException('$databaseName is invalid: ' . $databaseName);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Model/CollectionInfoCommandIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace MongoDB\Model;

use IteratorIterator;
use ReturnTypeWillChange;
use Traversable;

/**
Expand Down Expand Up @@ -53,6 +54,7 @@ public function __construct(Traversable $iterator, $databaseName = null)
* @see http://php.net/iterator.current
* @return CollectionInfo
*/
#[ReturnTypeWillChange]
public function current()
{
$info = parent::current();
Expand Down
2 changes: 2 additions & 0 deletions src/Model/IndexInfoIteratorIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
namespace MongoDB\Model;

use IteratorIterator;
use ReturnTypeWillChange;
use Traversable;

use function array_key_exists;
Expand Down Expand Up @@ -57,6 +58,7 @@ public function __construct(Traversable $iterator, $ns = null)
* @see http://php.net/iterator.current
* @return IndexInfo
*/
#[ReturnTypeWillChange]
public function current()
{
$info = parent::current();
Expand Down
2 changes: 1 addition & 1 deletion tests/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ public function configureFailPoint($command, ?Server $server = null): void
throw new InvalidArgumentException('$command is not an array or stdClass instance');
}

if (key($command) !== 'configureFailPoint') {
if (key((array) $command) !== 'configureFailPoint') {
throw new InvalidArgumentException('$command is not a configureFailPoint command');
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Model/BSONIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class BSONIteratorTest extends TestCase
/**
* @dataProvider provideTypeMapOptionsAndExpectedDocuments
*/
public function testValidValues(?array $typeMap = null, $binaryString, array $expectedDocuments): void
public function testValidValues(?array $typeMap, $binaryString, array $expectedDocuments): void
{
$bsonIt = new BSONIterator($binaryString, ['typeMap' => $typeMap]);

Expand Down
6 changes: 3 additions & 3 deletions tests/Model/CachingIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function testWithWrongIterator(): void
/** @var int */
private $i = 0;

public function current()
public function current(): int
{
return $this->i;
}
Expand All @@ -132,12 +132,12 @@ public function next(): void
$this->i++;
}

public function key()
public function key(): int
{
return $this->i;
}

public function valid()
public function valid(): bool
{
return $this->i == 0;
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Operation/AggregateFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ function (array $event): void {
/**
* @dataProvider provideTypeMapOptionsAndExpectedDocuments
*/
public function testTypeMapOption(?array $typeMap = null, array $expectedDocuments): void
public function testTypeMapOption(?array $typeMap, array $expectedDocuments): void
{
$this->createFixtures(3);

Expand All @@ -167,7 +167,7 @@ public function testTypeMapOption(?array $typeMap = null, array $expectedDocumen
/**
* @dataProvider provideTypeMapOptionsAndExpectedDocuments
*/
public function testTypeMapOptionWithoutCursor(?array $typeMap = null, array $expectedDocuments): void
public function testTypeMapOptionWithoutCursor(?array $typeMap, array $expectedDocuments): void
{
if (version_compare($this->getServerVersion(), '3.6.0', '>=')) {
$this->markTestSkipped('Aggregations with useCursor == false are not supported');
Expand Down
2 changes: 1 addition & 1 deletion tests/Operation/FindAndModifyFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function (array $event): void {
/**
* @dataProvider provideTypeMapOptionsAndExpectedDocument
*/
public function testTypeMapOption(?array $typeMap = null, $expectedDocument): void
public function testTypeMapOption(?array $typeMap, $expectedDocument): void
{
$this->createFixtures(1);

Expand Down
4 changes: 2 additions & 2 deletions tests/Operation/MapReduceFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ function (array $event): void {
/**
* @dataProvider provideTypeMapOptionsAndExpectedDocuments
*/
public function testTypeMapOptionWithInlineResults(?array $typeMap = null, array $expectedDocuments): void
public function testTypeMapOptionWithInlineResults(?array $typeMap, array $expectedDocuments): void
{
$this->createFixtures(3);

Expand Down Expand Up @@ -282,7 +282,7 @@ public function provideTypeMapOptionsAndExpectedDocuments()
/**
* @dataProvider provideTypeMapOptionsAndExpectedDocuments
*/
public function testTypeMapOptionWithOutputCollection(?array $typeMap = null, array $expectedDocuments): void
public function testTypeMapOptionWithOutputCollection(?array $typeMap, array $expectedDocuments): void
{
$this->createFixtures(3);

Expand Down
2 changes: 1 addition & 1 deletion tests/SpecTests/AtlasDataLakeSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function assertCommandMatches(stdClass $expected, stdClass $actual
* @param string $databaseName Name of database under test
* @param string $collectionName Name of collection under test
*/
public function testAtlasDataLake(stdClass $test, ?array $runOn = null, array $data, ?string $databaseName = null, ?string $collectionName = null): void
public function testAtlasDataLake(stdClass $test, ?array $runOn, array $data, ?string $databaseName = null, ?string $collectionName = null): void
{
if (isset($runOn)) {
$this->checkServerRequirements($runOn);
Expand Down
2 changes: 1 addition & 1 deletion tests/SpecTests/ClientSideEncryptionSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static function assertCommandMatches(stdClass $expected, stdClass $actual
* @param string $databaseName Name of database under test
* @param string $collectionName Name of collection under test
*/
public function testClientSideEncryption(stdClass $test, ?array $runOn = null, array $data, ?array $keyVaultData = null, $jsonSchema = null, ?string $databaseName = null, ?string $collectionName = null): void
public function testClientSideEncryption(stdClass $test, ?array $runOn, array $data, ?array $keyVaultData = null, $jsonSchema = null, ?string $databaseName = null, ?string $collectionName = null): void
{
if (isset(self::$incompleteTests[$this->dataDescription()])) {
$this->markTestIncomplete(self::$incompleteTests[$this->dataDescription()]);
Expand Down
2 changes: 1 addition & 1 deletion tests/SpecTests/CommandExpectations.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class CommandExpectations implements CommandSubscriber
private function __construct(array $events)
{
foreach ($events as $event) {
switch (key($event)) {
switch (key((array) $event)) {
case 'command_failed_event':
// phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
$this->expectedEvents[] = [$event->command_failed_event, CommandFailedEvent::class];
Expand Down
2 changes: 1 addition & 1 deletion tests/SpecTests/ReadWriteConcernSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static function assertCommandMatches(stdClass $expected, stdClass $actual
* @param string $databaseName Name of database under test
* @param string $collectionName Name of collection under test
*/
public function testReadWriteConcern(stdClass $test, ?array $runOn = null, array $data, ?string $databaseName = null, ?string $collectionName = null): void
public function testReadWriteConcern(stdClass $test, ?array $runOn, array $data, ?string $databaseName = null, ?string $collectionName = null): void
{
if (isset(self::$incompleteTests[$this->dataDescription()])) {
$this->markTestIncomplete(self::$incompleteTests[$this->dataDescription()]);
Expand Down
2 changes: 1 addition & 1 deletion tests/SpecTests/RetryableReadsSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static function assertCommandMatches(stdClass $expected, stdClass $actual
* @group matrix-testing-exclude-server-4.4-driver-4.2
* @group matrix-testing-exclude-server-5.0-driver-4.2
*/
public function testRetryableReads(stdClass $test, ?array $runOn = null, $data, string $databaseName, ?string $collectionName, ?string $bucketName): void
public function testRetryableReads(stdClass $test, ?array $runOn, $data, string $databaseName, ?string $collectionName, ?string $bucketName): void
{
if (isset($runOn)) {
$this->checkServerRequirements($runOn);
Expand Down
2 changes: 1 addition & 1 deletion tests/SpecTests/RetryableWritesSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class RetryableWritesSpecTest extends FunctionalTestCase
* @param array $runOn Top-level "runOn" array with server requirements
* @param array $data Top-level "data" array to initialize collection
*/
public function testRetryableWrites(stdClass $test, ?array $runOn = null, array $data): void
public function testRetryableWrites(stdClass $test, ?array $runOn, array $data): void
{
if ($this->isShardedCluster() && ! $this->isShardedClusterUsingReplicasets()) {
$this->markTestSkipped('Transaction numbers are only allowed on a replica set member or mongos (PHPC-1415)');
Expand Down
6 changes: 3 additions & 3 deletions tests/SpecTests/TransactionsSpecTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public static function assertCommandMatches(stdClass $expected, stdClass $actual
* @dataProvider provideTransactionsTests
* @group serverless
*/
public function testTransactions(stdClass $test, ?array $runOn = null, array $data, ?string $databaseName = null, ?string $collectionName = null): void
public function testTransactions(stdClass $test, ?array $runOn, array $data, ?string $databaseName = null, ?string $collectionName = null): void
{
$this->runTransactionTest($test, $runOn, $data, $databaseName, $collectionName);
}
Expand All @@ -127,7 +127,7 @@ public function provideTransactionsTests(): array
/**
* @dataProvider provideTransactionsConvenientApiTests
*/
public function testTransactionsConvenientApi(stdClass $test, ?array $runOn = null, array $data, ?string $databaseName = null, ?string $collectionName = null): void
public function testTransactionsConvenientApi(stdClass $test, ?array $runOn, array $data, ?string $databaseName = null, ?string $collectionName = null): void
{
$this->runTransactionTest($test, $runOn, $data, $databaseName, $collectionName);
}
Expand All @@ -146,7 +146,7 @@ public function provideTransactionsConvenientApiTests(): array
* @param string $databaseName Name of database under test
* @param string $collectionName Name of collection under test
*/
private function runTransactionTest(stdClass $test, ?array $runOn = null, array $data, ?string $databaseName = null, ?string $collectionName = null): void
private function runTransactionTest(stdClass $test, ?array $runOn, array $data, ?string $databaseName = null, ?string $collectionName = null): void
{
if (isset(self::$incompleteTests[$this->dataDescription()])) {
$this->markTestIncomplete(self::$incompleteTests[$this->dataDescription()]);
Expand Down
2 changes: 1 addition & 1 deletion tests/UnifiedSpecTests/ExpectedError.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ final class ExpectedError
/** @var ExpectedResult|null */
private $expectedResult;

public function __construct(?stdClass $o = null, EntityMap $entityMap)
public function __construct(?stdClass $o, EntityMap $entityMap)
{
if ($o === null) {
return;
Expand Down