Skip to content

Commit c233d17

Browse files
committed
Duplicate clone test without dynamic properties for PHP >= 8.2
1 parent 2c5a02f commit c233d17

26 files changed

+514
-59
lines changed

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-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===

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
--TEST--
2-
MongoDB\BSON\Int64 can be cloned
2+
MongoDB\BSON\Int64 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 (4 !== PHP_INT_SIZE) { die('skip Only for 32-bit platform'); } ?>
57
--FILE--
68
<?php
79

810
require_once __DIR__ . '/../utils/basic.inc';
911

1012
$int64 = unserialize('C:18:"MongoDB\BSON\Int64":47:{a:1:{s:7:"integer";s:19:"9223372036854775807";}}');
11-
$int64->foo = 'bar';
1213
$clone = clone $int64;
1314

1415
var_dump($clone == $int64);
@@ -17,7 +18,6 @@ var_dump($clone === $int64);
1718
unset($int64);
1819

1920
var_dump($clone);
20-
var_dump($clone->foo);
2121
?>
2222
===DONE===
2323
<?php exit(0); ?>
@@ -28,5 +28,4 @@ object(MongoDB\BSON\Int64)#%d (%d) {
2828
["integer"]=>
2929
string(19) "9223372036854775807"
3030
}
31-
string(3) "bar"
3231
===DONE===

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
--TEST--
2+
MongoDB\BSON\Int64 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 (4 !== PHP_INT_SIZE) { die('skip Only for 32-bit platform'); } ?>
7+
--FILE--
8+
<?php
9+
10+
require_once __DIR__ . '/../utils/basic.inc';
11+
12+
$int64 = unserialize('C:18:"MongoDB\BSON\Int64":47:{a:1:{s:7:"integer";s:19:"9223372036854775807";}}');
13+
$clone = clone $int64;
14+
15+
var_dump($clone == $int64);
16+
var_dump($clone === $int64);
17+
18+
unset($int64);
19+
20+
var_dump($clone);
21+
?>
22+
===DONE===
23+
<?php exit(0); ?>
24+
--EXPECTF--
25+
bool(true)
26+
bool(false)
27+
object(MongoDB\BSON\Int64)#%d (%d) {
28+
["integer"]=>
29+
string(19) "9223372036854775807"
30+
}
31+
===DONE===

0 commit comments

Comments
 (0)