Skip to content

Commit cb9331f

Browse files
authored
PHPLIB-933: Test on PHP 8.2 (#953)
* Add testing for feature branches to GitHub Actions * Test on PHP 8.2 * Handle upcoming return type changes * Handle missing class properties * No longer use self in callable
1 parent 3ddb447 commit cb9331f

File tree

10 files changed

+30
-11
lines changed

10 files changed

+30
-11
lines changed

.github/workflows/tests.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@ on:
55
branches:
66
- "v*.*"
77
- "master"
8+
- "feature/*"
89
push:
910
branches:
1011
- "v*.*"
1112
- "master"
13+
- "feature/*"
1214

1315
jobs:
1416
phpunit:
@@ -24,6 +26,7 @@ jobs:
2426
- "7.4"
2527
- "8.0"
2628
- "8.1"
29+
- "8.2"
2730
mongodb-version:
2831
- "4.4"
2932
driver-version:

src/Model/BSONArray.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public static function __set_state(array $properties)
7171
* @see https://php.net/mongodb-bson-serializable.bsonserialize
7272
* @return array
7373
*/
74+
#[ReturnTypeWillChange]
7475
public function bsonSerialize()
7576
{
7677
return array_values($this->getArrayCopy());
@@ -82,6 +83,7 @@ public function bsonSerialize()
8283
* @see https://php.net/mongodb-bson-unserializable.bsonunserialize
8384
* @param array $data Array data
8485
*/
86+
#[ReturnTypeWillChange]
8587
public function bsonUnserialize(array $data)
8688
{
8789
self::__construct($data);

src/Model/BSONDocument.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ public static function __set_state(array $properties)
8181
* @see https://php.net/mongodb-bson-serializable.bsonserialize
8282
* @return object
8383
*/
84+
#[ReturnTypeWillChange]
8485
public function bsonSerialize()
8586
{
8687
return (object) $this->getArrayCopy();
@@ -92,6 +93,7 @@ public function bsonSerialize()
9293
* @see https://php.net/mongodb-bson-unserializable.bsonunserialize
9394
* @param array $data Array data
9495
*/
96+
#[ReturnTypeWillChange]
9597
public function bsonUnserialize(array $data)
9698
{
9799
parent::__construct($data, ArrayObject::ARRAY_AS_PROPS);

src/Model/ChangeStreamIterator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ public function __construct(Cursor $cursor, $firstBatchSize, $initialResumeToken
100100
}
101101

102102
/** @internal */
103-
final public function commandFailed(CommandFailedEvent $event)
103+
final public function commandFailed(CommandFailedEvent $event): void
104104
{
105105
}
106106

107107
/** @internal */
108-
final public function commandStarted(CommandStartedEvent $event)
108+
final public function commandStarted(CommandStartedEvent $event): void
109109
{
110110
if ($event->getCommandName() !== 'getMore') {
111111
return;
@@ -117,7 +117,7 @@ final public function commandStarted(CommandStartedEvent $event)
117117
}
118118

119119
/** @internal */
120-
final public function commandSucceeded(CommandSucceededEvent $event)
120+
final public function commandSucceeded(CommandSucceededEvent $event): void
121121
{
122122
if ($event->getCommandName() !== 'getMore') {
123123
return;

src/Model/IndexInput.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
use MongoDB\BSON\Serializable;
2121
use MongoDB\Exception\InvalidArgumentException;
22+
use ReturnTypeWillChange;
2223

2324
use function is_array;
2425
use function is_float;
@@ -91,6 +92,7 @@ public function __toString()
9192
* @see https://php.net/mongodb-bson-serializable.bsonserialize
9293
* @return array
9394
*/
95+
#[ReturnTypeWillChange]
9496
public function bsonSerialize()
9597
{
9698
return $this->index;

src/Operation/Watch.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,12 @@ public function __construct(Manager $manager, $databaseName, $collectionName, ar
271271
}
272272

273273
/** @internal */
274-
final public function commandFailed(CommandFailedEvent $event)
274+
final public function commandFailed(CommandFailedEvent $event): void
275275
{
276276
}
277277

278278
/** @internal */
279-
final public function commandStarted(CommandStartedEvent $event)
279+
final public function commandStarted(CommandStartedEvent $event): void
280280
{
281281
if ($event->getCommandName() !== 'aggregate') {
282282
return;
@@ -287,7 +287,7 @@ final public function commandStarted(CommandStartedEvent $event)
287287
}
288288

289289
/** @internal */
290-
final public function commandSucceeded(CommandSucceededEvent $event)
290+
final public function commandSucceeded(CommandSucceededEvent $event): void
291291
{
292292
if ($event->getCommandName() !== 'aggregate') {
293293
return;

tests/GridFS/UnusableStream.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
final class UnusableStream
1414
{
15+
public $context;
16+
1517
public static function register($protocol = 'unusable'): void
1618
{
1719
if (in_array($protocol, stream_get_wrappers())) {

tests/UnifiedSpecTests/Constraint/IsBsonTypeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,15 @@ private function assertResult($expected, Constraint $constraint, $value, string
163163
// phpcs:disable Squiz.Classes.ClassFileName.NoMatch
164164
class SerializableArray implements Serializable
165165
{
166-
public function bsonSerialize()
166+
public function bsonSerialize(): array
167167
{
168168
return ['foo'];
169169
}
170170
}
171171

172172
class SerializableObject implements Serializable
173173
{
174-
public function bsonSerialize()
174+
public function bsonSerialize(): array
175175
{
176176
return ['x' => 1];
177177
}

tests/UnifiedSpecTests/Constraint/Matches.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ class Matches extends Constraint
6868
/** @var ComparisonFailure|null */
6969
private $lastFailure;
7070

71+
/** @var Factory */
72+
private $comparatorFactory;
73+
7174
public function __construct($value, ?EntityMap $entityMap = null, $allowExtraRootKeys = true, $allowOperators = true)
7275
{
7376
$this->value = self::prepare($value);

tests/UnifiedSpecTests/Operation.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ final class Operation
8585
private $entityMap;
8686

8787
/** @var ExpectedError */
88-
private $expectedError;
88+
private $expectError;
8989

9090
/** @var ExpectedResult */
91-
private $expectedResult;
91+
private $expectResult;
9292

9393
/** @var bool */
9494
private $ignoreResultAndError;
@@ -295,7 +295,12 @@ private function executeForCollection(Collection $collection)
295295
assertIsArray($args['requests']);
296296

297297
return $collection->bulkWrite(
298-
array_map('self::prepareBulkWriteRequest', $args['requests']),
298+
array_map(
299+
static function ($request) {
300+
return self::prepareBulkWriteRequest($request);
301+
},
302+
$args['requests']
303+
),
299304
array_diff_key($args, ['requests' => 1])
300305
);
301306

0 commit comments

Comments
 (0)