Skip to content

Commit

Permalink
Test against PHP 8.4 (#189)
Browse files Browse the repository at this point in the history
* Test against PHP 8.4

* Fix PHP 8.4 deprecations

* Resolve MongoDB deprecations in tests

* Add changelog entry
  • Loading branch information
Jean85 authored Dec 7, 2024
1 parent 40a9c3b commit e7ee50d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ jobs:
- php: 8.3
mongo-ext: 1.19.0
mongo-img: 7.0
- php: 8.4
mongo-ext: 1.20.0
mongo-img: 7.0

steps:
- name: Checkout
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
* Fixed deprecation warnings using PHP 8.4

## [1.6.1] (2024-10-04)
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion src/Command/AbstractCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class AbstractCommand extends Command
/**
* AbstractCommand constructor.
*/
public function __construct(ContainerInterface $container, string $name = null)
public function __construct(ContainerInterface $container, ?string $name = null)
{
parent::__construct($name);
$this->container = $container;
Expand Down
2 changes: 1 addition & 1 deletion src/Models/ClientConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function __construct(
string $uri,
string $username = '',
string $password = '',
string $authSource = null,
?string $authSource = null,
array $options = [],
array $driverOptions = []
) {
Expand Down
25 changes: 17 additions & 8 deletions tests/Unit/Capsule/DatabaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,40 @@ public function test_selectCollection(): void
self::assertEquals('testdb', $debugInfo['databaseName']);
}

public function test_withOptions(): void
/**
* @dataProvider readPreferenceDataProvider
*
* @param int|string $readPreference
*/
public function test_withOptions($readPreference): void
{
$manager = new Manager('mongodb://localhost');
$logger = $this->prophesize(EventDispatcherInterface::class);

$db = new Database($manager, 'client_name', 'testdb', [], $logger->reveal());
self::assertInstanceOf(\MongoDB\Database::class, $db);

$newDb = $db->withOptions(['readPreference' => new ReadPreference(ReadPreference::RP_NEAREST)]);
$newDb = $db->withOptions(['readPreference' => new ReadPreference($readPreference)]);

self::assertInstanceOf(Database::class, $newDb);

$debugInfo = $newDb->__debugInfo();
self::assertSame($manager, $debugInfo['manager']);
self::assertEquals('testdb', $debugInfo['databaseName']);

$this->assertReadPreferenceMode($debugInfo['readPreference']);
if (method_exists(ReadPreference::class, 'getModeString')) {
self::assertEquals(ReadPreference::NEAREST, $debugInfo['readPreference']->getModeString());
} else {
self::assertEquals(ReadPreference::RP_NEAREST, $debugInfo['readPreference']->getMode());
}
}

public function assertReadPreferenceMode(ReadPreference $readPreference): void
public static function readPreferenceDataProvider(): array
{
if (method_exists(ReadPreference::class, 'getModeString')) {
self::assertEquals(ReadPreference::NEAREST, $readPreference->getModeString());
} else {
self::assertEquals(ReadPreference::RP_NEAREST, $readPreference->getMode());
if (! method_exists(ReadPreference::class, 'getModeString')) {
return [[ReadPreference::RP_NEAREST]];
}

return [[ReadPreference::NEAREST]];
}
}

0 comments on commit e7ee50d

Please sign in to comment.