Skip to content

Commit 0e99bf5

Browse files
authored
Provide compatibility with PHP 8.1 (alcaeus#290)
* Run tests on PHP 8.1 * Add ReturnTypeWillChange attributes where necessary * Remove invalid use of parse_url result * Drop ubuntu-16.04 in GitHub Actions * Use lower driver versions on PHP < 7.2
1 parent e9f2cb6 commit 0e99bf5

File tree

7 files changed

+30
-10
lines changed

7 files changed

+30
-10
lines changed

.github/workflows/tests.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ on:
1111
jobs:
1212
verification:
1313
name: "Verification tests"
14-
runs-on: "ubuntu-16.04"
14+
runs-on: "ubuntu-18.04"
1515

1616
steps:
1717
- name: "Checkout"
@@ -80,12 +80,11 @@ jobs:
8080
os:
8181
- "ubuntu-18.04"
8282
php-version:
83-
- "7.0"
84-
- "7.1"
8583
- "7.2"
8684
- "7.3"
8785
- "7.4"
8886
- "8.0"
87+
- "8.1"
8988
mongodb-version:
9089
- "4.4"
9190
driver-version:
@@ -94,10 +93,20 @@ jobs:
9493
- "normal"
9594
include:
9695
- deps: "low"
97-
os: "ubuntu-16.04"
96+
os: "ubuntu-18.04"
9897
php-version: "5.6"
9998
mongodb-version: "3.0"
10099
driver-version: "1.2.0"
100+
- deps: "normal"
101+
os: "ubuntu-18.04"
102+
php-version: "7.0"
103+
mongodb-version: "4.4"
104+
driver-version: "1.9.2"
105+
- deps: "normal"
106+
os: "ubuntu-18.04"
107+
php-version: "7.1"
108+
mongodb-version: "4.4"
109+
driver-version: "1.11.1"
101110

102111
steps:
103112
- name: "Checkout"

lib/Alcaeus/MongoDbAdapter/AbstractCursor.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Alcaeus\MongoDbAdapter\Helper\ReadPreference;
1919
use MongoDB\Collection;
2020
use MongoDB\Driver\Cursor;
21+
use ReturnTypeWillChange;
2122

2223
/**
2324
* @internal
@@ -136,6 +137,7 @@ public function __construct(\MongoClient $connection, $ns)
136137
* @link http://www.php.net/manual/en/mongocursor.current.php
137138
* @return array
138139
*/
140+
#[ReturnTypeWillChange]
139141
public function current()
140142
{
141143
return $this->current;
@@ -146,6 +148,7 @@ public function current()
146148
* @link http://www.php.net/manual/en/mongocursor.key.php
147149
* @return string The current result's _id as a string.
148150
*/
151+
#[ReturnTypeWillChange]
149152
public function key()
150153
{
151154
return $this->key;
@@ -158,6 +161,7 @@ public function key()
158161
* @throws \MongoCursorTimeoutException
159162
* @return array Returns the next object
160163
*/
164+
#[ReturnTypeWillChange]
161165
public function next()
162166
{
163167
if (! $this->startedIterating) {
@@ -181,6 +185,7 @@ public function next()
181185
* @throws \MongoCursorTimeoutException
182186
* @return void
183187
*/
188+
#[ReturnTypeWillChange]
184189
public function rewind()
185190
{
186191
// We can recreate the cursor to allow it to be rewound
@@ -196,6 +201,7 @@ public function rewind()
196201
* @link http://www.php.net/manual/en/mongocursor.valid.php
197202
* @return boolean If the current result is not null.
198203
*/
204+
#[ReturnTypeWillChange]
199205
public function valid()
200206
{
201207
return $this->valid;

lib/Alcaeus/MongoDbAdapter/CursorIterator.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use IteratorIterator;
66
use MongoDB\BSON\ObjectID;
77
use Traversable;
8+
use ReturnTypeWillChange;
89

910
/**
1011
* @internal
@@ -21,6 +22,7 @@ public function __construct(Traversable $iterator, $useIdAsKey = false)
2122
$this->useIdAsKey = $useIdAsKey;
2223
}
2324

25+
#[ReturnTypeWillChange]
2426
public function key()
2527
{
2628
if (!$this->useIdAsKey) {

lib/Mongo/MongoClient.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,12 @@ public function __sleep()
365365
*/
366366
private function extractUrlOptions($server)
367367
{
368-
$queryOptions = explode('&', parse_url($server, PHP_URL_QUERY));
368+
$queryOptions = parse_url($server, PHP_URL_QUERY);
369+
if (!$queryOptions) {
370+
return [];
371+
}
372+
373+
$queryOptions = explode('&', $queryOptions);
369374

370375
$options = [];
371376
foreach ($queryOptions as $option) {

lib/Mongo/MongoCursor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
use Alcaeus\MongoDbAdapter\TypeConverter;
2323
use Alcaeus\MongoDbAdapter\ExceptionConverter;
2424
use MongoDB\Driver\Cursor;
25-
use MongoDB\Driver\ReadPreference;
2625
use MongoDB\Operation\Find;
2726

2827
/**
@@ -134,6 +133,7 @@ public function awaitData($wait = true)
134133
* @param bool $foundOnly Send cursor limit and skip information to the count function, if applicable.
135134
* @return int The number of documents returned by this cursor's query.
136135
*/
136+
#[\ReturnTypeWillChange]
137137
public function count($foundOnly = false)
138138
{
139139
$optionNames = ['hint', 'maxTimeMS'];

lib/Mongo/MongoId.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ public static function __set_state(array $props)
202202
/**
203203
* @return stdClass
204204
*/
205+
#[ReturnTypeWillChange]
205206
public function jsonSerialize()
206207
{
207208
$object = new stdClass();

phpunit.xml.dist

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,12 @@
1313
<!-- Disable deprecation warnings -->
1414
<!-- php -r 'echo -1 & ~E_USER_DEPRECATED & ~E_DEPRECATED;' -->
1515
<ini name="error_reporting" value="-24577"/>
16+
<const name="MONGODB_URI" value="mongodb://localhost:27017" />
1617
</php>
1718

1819
<testsuites>
1920
<testsuite name="Mongo driver adapter test suite">
2021
<directory>./tests/Alcaeus/MongoDbAdapter/</directory>
2122
</testsuite>
2223
</testsuites>
23-
24-
<php>
25-
<const name="MONGODB_URI" value="mongodb://localhost:27017" />
26-
</php>
2724
</phpunit>

0 commit comments

Comments
 (0)