Skip to content

Commit 6ffcb1f

Browse files
authored
PHPC-2117: Test on PHP 8.2 (#1340)
* Test on PHP 8.2 * Fix tests relating to dynamic properties * Fix tests failing due to different __set_state output * Duplicate clone test without dynamic properties for PHP >= 8.2
1 parent 6887226 commit 6ffcb1f

File tree

60 files changed

+651
-169
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+651
-169
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ jobs:
2626
- "7.4"
2727
- "8.0"
2828
- "8.1"
29+
- "8.2"
2930
mongodb-version:
3031
- "4.4"
3132
topology:

tests/apm/commandFailedEvent-002.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ $m = create_test_manager();
1212

1313
class MySubscriber implements MongoDB\Driver\Monitoring\CommandSubscriber
1414
{
15+
private $startRequestId;
16+
private $startOperationId;
17+
1518
public function commandStarted( \MongoDB\Driver\Monitoring\CommandStartedEvent $event ): void
1619
{
1720
echo "started: ", $event->getCommandName(), "\n";

tests/apm/commandSucceededEvent-002.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ $m = create_test_manager();
1212

1313
class MySubscriber implements MongoDB\Driver\Monitoring\CommandSubscriber
1414
{
15+
private $startRequestId;
16+
private $startOperationId;
17+
1518
public function commandStarted( \MongoDB\Driver\Monitoring\CommandStartedEvent $event ): void
1619
{
1720
echo "started: ", $event->getCommandName(), "\n";

tests/bson/bson-binary-clone-001.phpt

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
--TEST--
2-
MongoDB\BSON\Binary can be cloned
2+
MongoDB\BSON\Binary can be cloned (PHP < 8.2)
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_php_version('>=', '8.2'); ?>
36
--FILE--
47
<?php
58

@@ -18,7 +21,6 @@ $types = array(
1821
foreach($types as $type) {
1922
// Use 16-byte data to satisfy UUID requirements
2023
$binary = new MongoDB\BSON\Binary('randomBinaryData', $type);
21-
$binary->foo = 'bar';
2224

2325
$clone = clone $binary;
2426

@@ -28,7 +30,6 @@ foreach($types as $type) {
2830
unset($binary);
2931

3032
var_dump($clone);
31-
var_dump($clone->foo);
3233
}
3334
?>
3435
===DONE===
@@ -42,7 +43,6 @@ object(MongoDB\BSON\Binary)#%d (2) {
4243
["type"]=>
4344
int(0)
4445
}
45-
string(3) "bar"
4646
bool(true)
4747
bool(false)
4848
object(MongoDB\BSON\Binary)#%d (2) {
@@ -51,7 +51,6 @@ object(MongoDB\BSON\Binary)#%d (2) {
5151
["type"]=>
5252
int(1)
5353
}
54-
string(3) "bar"
5554
bool(true)
5655
bool(false)
5756
object(MongoDB\BSON\Binary)#%d (2) {
@@ -60,7 +59,6 @@ object(MongoDB\BSON\Binary)#%d (2) {
6059
["type"]=>
6160
int(2)
6261
}
63-
string(3) "bar"
6462
bool(true)
6563
bool(false)
6664
object(MongoDB\BSON\Binary)#%d (2) {
@@ -69,7 +67,6 @@ object(MongoDB\BSON\Binary)#%d (2) {
6967
["type"]=>
7068
int(3)
7169
}
72-
string(3) "bar"
7370
bool(true)
7471
bool(false)
7572
object(MongoDB\BSON\Binary)#%d (2) {
@@ -78,7 +75,6 @@ object(MongoDB\BSON\Binary)#%d (2) {
7875
["type"]=>
7976
int(4)
8077
}
81-
string(3) "bar"
8278
bool(true)
8379
bool(false)
8480
object(MongoDB\BSON\Binary)#%d (2) {
@@ -87,7 +83,6 @@ object(MongoDB\BSON\Binary)#%d (2) {
8783
["type"]=>
8884
int(5)
8985
}
90-
string(3) "bar"
9186
bool(true)
9287
bool(false)
9388
object(MongoDB\BSON\Binary)#%d (2) {
@@ -96,7 +91,6 @@ object(MongoDB\BSON\Binary)#%d (2) {
9691
["type"]=>
9792
int(128)
9893
}
99-
string(3) "bar"
10094
bool(true)
10195
bool(false)
10296
object(MongoDB\BSON\Binary)#%d (2) {
@@ -105,5 +99,4 @@ object(MongoDB\BSON\Binary)#%d (2) {
10599
["type"]=>
106100
int(133)
107101
}
108-
string(3) "bar"
109102
===DONE===

tests/bson/bson-binary-clone-002.phpt

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
--TEST--
2+
MongoDB\BSON\Binary can be cloned (PHP >= 8.2)
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_php_version('<', '8.2'); ?>
6+
--FILE--
7+
<?php
8+
9+
require_once __DIR__ . '/../utils/basic.inc';
10+
11+
$types = array(
12+
MongoDB\BSON\Binary::TYPE_GENERIC,
13+
MongoDB\BSON\Binary::TYPE_FUNCTION,
14+
MongoDB\BSON\Binary::TYPE_OLD_BINARY,
15+
MongoDB\BSON\Binary::TYPE_OLD_UUID,
16+
MongoDB\BSON\Binary::TYPE_UUID,
17+
MongoDB\BSON\Binary::TYPE_MD5,
18+
MongoDB\BSON\Binary::TYPE_USER_DEFINED,
19+
MongoDB\BSON\Binary::TYPE_USER_DEFINED+5,
20+
);
21+
foreach($types as $type) {
22+
// Use 16-byte data to satisfy UUID requirements
23+
$binary = new MongoDB\BSON\Binary('randomBinaryData', $type);
24+
25+
$clone = clone $binary;
26+
27+
var_dump($clone == $binary);
28+
var_dump($clone === $binary);
29+
30+
unset($binary);
31+
32+
var_dump($clone);
33+
}
34+
?>
35+
===DONE===
36+
<?php exit(0); ?>
37+
--EXPECTF--
38+
bool(true)
39+
bool(false)
40+
object(MongoDB\BSON\Binary)#%d (2) {
41+
["data"]=>
42+
string(16) "randomBinaryData"
43+
["type"]=>
44+
int(0)
45+
}
46+
bool(true)
47+
bool(false)
48+
object(MongoDB\BSON\Binary)#%d (2) {
49+
["data"]=>
50+
string(16) "randomBinaryData"
51+
["type"]=>
52+
int(1)
53+
}
54+
bool(true)
55+
bool(false)
56+
object(MongoDB\BSON\Binary)#%d (2) {
57+
["data"]=>
58+
string(16) "randomBinaryData"
59+
["type"]=>
60+
int(2)
61+
}
62+
bool(true)
63+
bool(false)
64+
object(MongoDB\BSON\Binary)#%d (2) {
65+
["data"]=>
66+
string(16) "randomBinaryData"
67+
["type"]=>
68+
int(3)
69+
}
70+
bool(true)
71+
bool(false)
72+
object(MongoDB\BSON\Binary)#%d (2) {
73+
["data"]=>
74+
string(16) "randomBinaryData"
75+
["type"]=>
76+
int(4)
77+
}
78+
bool(true)
79+
bool(false)
80+
object(MongoDB\BSON\Binary)#%d (2) {
81+
["data"]=>
82+
string(16) "randomBinaryData"
83+
["type"]=>
84+
int(5)
85+
}
86+
bool(true)
87+
bool(false)
88+
object(MongoDB\BSON\Binary)#%d (2) {
89+
["data"]=>
90+
string(16) "randomBinaryData"
91+
["type"]=>
92+
int(128)
93+
}
94+
bool(true)
95+
bool(false)
96+
object(MongoDB\BSON\Binary)#%d (2) {
97+
["data"]=>
98+
string(16) "randomBinaryData"
99+
["type"]=>
100+
int(133)
101+
}
102+
===DONE===

tests/bson/bson-binary-set_state-001.phpt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,27 +25,27 @@ foreach ($tests as $test) {
2525
===DONE===
2626
<?php exit(0); ?>
2727
--EXPECTF--
28-
MongoDB\BSON\Binary::__set_state(array(
28+
%r\\?%rMongoDB\BSON\Binary::__set_state(array(
2929
%w'data' => 'foobar',
3030
%w'type' => 0,
3131
))
3232

33-
MongoDB\BSON\Binary::__set_state(array(
33+
%r\\?%rMongoDB\BSON\Binary::__set_state(array(
3434
%w'data' => '',
3535
%w'type' => 0,
3636
))
3737

38-
MongoDB\BSON\Binary::__set_state(array(
38+
%r\\?%rMongoDB\BSON\Binary::__set_state(array(
3939
%w'data' => '' . "\0" . 'foo',
4040
%w'type' => 0,
4141
))
4242

43-
MongoDB\BSON\Binary::__set_state(array(
43+
%r\\?%rMongoDB\BSON\Binary::__set_state(array(
4444
%w'data' => '>Egè›Ó¤VBfUD' . "\0" . '' . "\0" . '',
4545
%w'type' => 4,
4646
))
4747

48-
MongoDB\BSON\Binary::__set_state(array(
48+
%r\\?%rMongoDB\BSON\Binary::__set_state(array(
4949
%w'data' => '8Xö"0¬<‘_0 fCÆ?',
5050
%w'type' => 5,
5151
))

tests/bson/bson-dbpointer-clone-001.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
--TEST--
2-
MongoDB\BSON\DBPointer can be cloned
2+
MongoDB\BSON\DBPointer can be cloned (PHP < 8.2)
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_php_version('>=', '8.2'); ?>
36
--FILE--
47
<?php
58

@@ -8,7 +11,6 @@ require_once __DIR__ . '/../utils/basic.inc';
811
$test = MongoDB\BSON\toPHP(MongoDB\BSON\fromJSON('{ "dbref": {"$dbPointer": {"$ref": "phongo.test", "$id" : { "$oid" : "5a2e78accd485d55b405ac12" } }} }'));
912

1013
$dbPointer = $test->dbref;
11-
$dbPointer->foo = 'bar';
1214
$clone = clone($dbPointer);
1315

1416
var_dump($clone == $dbPointer);
@@ -17,7 +19,6 @@ var_dump($clone === $dbPointer);
1719
unset($dbPointer);
1820

1921
var_dump($clone);
20-
var_dump($clone->foo);
2122
?>
2223
===DONE===
2324
<?php exit(0); ?>
@@ -30,5 +31,4 @@ object(MongoDB\BSON\DBPointer)#%d (2) {
3031
["id"]=>
3132
string(24) "5a2e78accd485d55b405ac12"
3233
}
33-
string(3) "bar"
3434
===DONE===
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
--TEST--
2+
MongoDB\BSON\DBPointer can be cloned (PHP >= 8.2)
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_php_version('<', '8.2'); ?>
6+
--FILE--
7+
<?php
8+
9+
require_once __DIR__ . '/../utils/basic.inc';
10+
11+
$test = MongoDB\BSON\toPHP(MongoDB\BSON\fromJSON('{ "dbref": {"$dbPointer": {"$ref": "phongo.test", "$id" : { "$oid" : "5a2e78accd485d55b405ac12" } }} }'));
12+
13+
$dbPointer = $test->dbref;
14+
$clone = clone($dbPointer);
15+
16+
var_dump($clone == $dbPointer);
17+
var_dump($clone === $dbPointer);
18+
19+
unset($dbPointer);
20+
21+
var_dump($clone);
22+
?>
23+
===DONE===
24+
<?php exit(0); ?>
25+
--EXPECTF--
26+
bool(true)
27+
bool(false)
28+
object(MongoDB\BSON\DBPointer)#%d (2) {
29+
["ref"]=>
30+
string(11) "phongo.test"
31+
["id"]=>
32+
string(24) "5a2e78accd485d55b405ac12"
33+
}
34+
===DONE===

tests/bson/bson-decimal128-clone-001.phpt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
--TEST--
2-
MongoDB\BSON\Decimal128 can be cloned
2+
MongoDB\BSON\Decimal128 can be cloned (PHP < 8.2)
33
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_php_version('>=', '8.2'); ?>
46
<?php if (!class_exists('MongoDB\BSON\Decimal128')) { die('skip MongoDB\BSON\Decimal128 is not available'); } ?>
57
--FILE--
68
<?php
79

810
$decimal = new MongoDB\BSON\Decimal128('1234.5678');
9-
$decimal->foo = 'bar';
1011

1112
$clone = clone $decimal;
1213

@@ -16,7 +17,6 @@ var_dump($clone === $decimal);
1617
unset($decimal);
1718

1819
var_dump($clone);
19-
var_dump($clone->foo);
2020
?>
2121
===DONE===
2222
<?php exit(0); ?>
@@ -27,5 +27,4 @@ object(MongoDB\BSON\Decimal128)#%d (1) {
2727
["dec"]=>
2828
string(9) "1234.5678"
2929
}
30-
string(3) "bar"
3130
===DONE===
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
--TEST--
2+
MongoDB\BSON\Decimal128 can be cloned (PHP >= 8.2)
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_php_version('<', '8.2'); ?>
6+
<?php if (!class_exists('MongoDB\BSON\Decimal128')) { die('skip MongoDB\BSON\Decimal128 is not available'); } ?>
7+
--FILE--
8+
<?php
9+
10+
$decimal = new MongoDB\BSON\Decimal128('1234.5678');
11+
12+
$clone = clone $decimal;
13+
14+
var_dump($clone == $decimal);
15+
var_dump($clone === $decimal);
16+
17+
unset($decimal);
18+
19+
var_dump($clone);
20+
?>
21+
===DONE===
22+
<?php exit(0); ?>
23+
--EXPECTF--
24+
bool(true)
25+
bool(false)
26+
object(MongoDB\BSON\Decimal128)#%d (1) {
27+
["dec"]=>
28+
string(9) "1234.5678"
29+
}
30+
===DONE===

0 commit comments

Comments
 (0)