Skip to content

Commit ca4c52e

Browse files
jmikolaalcaeus
authored andcommitted
PHPC-1692: Test suite fixes for PHP 8
1 parent 35f589b commit ca4c52e

21 files changed

+196
-71
lines changed

tests/apm/bug0950-002.phpt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
PHPC-950: Segfault killing cursor after subscriber HashTable is destroyed (one subscriber)
33
--SKIPIF--
44
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_php_version('>=', '7.99'); ?>
56
<?php skip_if_not_live(); ?>
67
<?php skip_if_not_clean(); ?>
78
--FILE--
89
<?php
910
require_once __DIR__ . "/../utils/basic.inc";
1011

12+
/* Note: this test is skipped on PHP 8 because the CommandSubscriber ends up
13+
* observing the killCursors command invoked from the Cursor's dtor. */
14+
1115
class MySubscriber implements MongoDB\Driver\Monitoring\CommandSubscriber
1216
{
1317
public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event)
@@ -39,7 +43,7 @@ MongoDB\Driver\Monitoring\addSubscriber(new MySubscriber);
3943
$cursor = $manager->executeQuery(NS, new MongoDB\Driver\Query([], ['batchSize' => 2]));
4044

4145
/* Exiting during iteration on a live cursor will result in
42-
* php_phongo_command_started() being invoked for the killCursor command after
46+
* php_phongo_command_started() being invoked for the killCursors command after
4347
* RSHUTDOWN has already destroyed the subscriber HashTable */
4448
foreach ($cursor as $data) {
4549
echo "Exiting during first iteration on cursor\n";

tests/bson/bson-binary_error-001.phpt

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

tests/bson/bson-decimal128_error-001.phpt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
--TEST--
22
MongoDB\BSON\Decimal128 requires valid decimal string
33
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_php_version('>=', '7.99'); ?>
46
<?php if (!class_exists('MongoDB\BSON\Decimal128')) { die('skip MongoDB\BSON\Decimal128 is not available'); } ?>
57
--FILE--
68
<?php

tests/bson/bson-javascript_error-001.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
--TEST--
22
MongoDB\BSON\Javascript #001 error
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_php_version('>=', '7.99'); ?>
36
--FILE--
47
<?php
58

tests/bson/bson-objectid-001.phpt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,6 @@ throws(function() {
5555
$id = new MongoDB\BSON\ObjectId(" 3e28b650640fd3162152da1");
5656
}, "MongoDB\\Driver\\Exception\\InvalidArgumentException");
5757

58-
59-
60-
raises(function() use($pregenerated) {
61-
$pregenerated->__toString(1);
62-
}, E_WARNING);
6358
?>
6459
===DONE===
6560
<?php exit(0); ?>
@@ -88,5 +83,4 @@ OK: Got MongoDB\Driver\Exception\InvalidArgumentException
8883
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
8984
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
9085
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
91-
OK: Got E_WARNING
9286
===DONE===
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
MongoDB\BSON\ObjectId raises warning on invalid arguments
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_php_version('>=', '7.99'); ?>
6+
--FILE--
7+
<?php
8+
9+
require_once __DIR__ . '/../utils/tools.php';
10+
11+
$pregenerated = new MongoDB\BSON\ObjectId("53e28b650640fd3162152de1");
12+
13+
raises(function() use($pregenerated) {
14+
$pregenerated->__toString(1);
15+
}, E_WARNING);
16+
17+
?>
18+
===DONE===
19+
<?php exit(0); ?>
20+
--EXPECTF--
21+
OK: Got E_WARNING
22+
===DONE===

tests/bson/bson-objectid_error-001.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
--TEST--
22
MongoDB\BSON\ObjectId #001 error
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_php_version('>=', '7.99'); ?>
36
--FILE--
47
<?php
58

tests/bson/bson-regex_error-001.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
--TEST--
22
MongoDB\BSON\Regex #001 error
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_php_version('>=', '7.99'); ?>
36
--FILE--
47
<?php
58

tests/bson/bson-timestamp_error-001.phpt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
--TEST--
22
MongoDB\BSON\Timestamp #001 error
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
5+
<?php skip_if_php_version('>=', '7.99'); ?>
36
--FILE--
47
<?php
58

tests/bson/bug0939-001.phpt

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ foreach ($tests as $test) {
2121
var_dump($object);
2222

2323
foreach ($properties as $property) {
24-
var_dump($object->{$property});
24+
printf("%s::$%s exists: %s\n", get_class($object), $property, property_exists($object, $property) ? 'yes' : 'no');
2525
}
2626

2727
echo "\n";
@@ -31,26 +31,21 @@ foreach ($tests as $test) {
3131
===DONE===
3232
<?php exit(0); ?>
3333
--EXPECTF--
34+
3435
object(MongoDB\BSON\Binary)#%d (%d) {
3536
["data"]=>
3637
string(3) "foo"
3738
["type"]=>
3839
int(0)
3940
}
40-
41-
Notice: Undefined property: MongoDB\BSON\Binary::$data in %s on line %d
42-
NULL
43-
44-
Notice: Undefined property: MongoDB\BSON\Binary::$type in %s on line %d
45-
NULL
41+
MongoDB\BSON\Binary::$data exists: no
42+
MongoDB\BSON\Binary::$type exists: no
4643

4744
object(MongoDB\BSON\Decimal128)#%d (%d) {
4845
["dec"]=>
4946
string(4) "3.14"
5047
}
51-
52-
Notice: Undefined property: MongoDB\BSON\Decimal128::$dec in %s on line %d
53-
NULL
48+
MongoDB\BSON\Decimal128::$dec exists: no
5449

5550
object(MongoDB\BSON\Javascript)#%d (%d) {
5651
["code"]=>
@@ -61,12 +56,8 @@ object(MongoDB\BSON\Javascript)#%d (%d) {
6156
int(42)
6257
}
6358
}
64-
65-
Notice: Undefined property: MongoDB\BSON\Javascript::$code in %s on line %d
66-
NULL
67-
68-
Notice: Undefined property: MongoDB\BSON\Javascript::$scope in %s on line %d
69-
NULL
59+
MongoDB\BSON\Javascript::$code exists: no
60+
MongoDB\BSON\Javascript::$scope exists: no
7061

7162
object(MongoDB\BSON\MaxKey)#%d (%d) {
7263
}
@@ -78,42 +69,30 @@ object(MongoDB\BSON\ObjectId)#%d (%d) {
7869
["oid"]=>
7970
string(24) "%x"
8071
}
81-
82-
Notice: Undefined property: MongoDB\BSON\ObjectId::$oid in %s on line %d
83-
NULL
72+
MongoDB\BSON\ObjectId::$oid exists: no
8473

8574
object(MongoDB\BSON\Regex)#%d (%d) {
8675
["pattern"]=>
8776
string(3) "foo"
8877
["flags"]=>
8978
string(1) "i"
9079
}
91-
92-
Notice: Undefined property: MongoDB\BSON\Regex::$pattern in %s on line %d
93-
NULL
94-
95-
Notice: Undefined property: MongoDB\BSON\Regex::$flags in %s on line %d
96-
NULL
80+
MongoDB\BSON\Regex::$pattern exists: no
81+
MongoDB\BSON\Regex::$flags exists: no
9782

9883
object(MongoDB\BSON\Timestamp)#%d (%d) {
9984
["increment"]=>
10085
string(4) "1234"
10186
["timestamp"]=>
10287
string(4) "5678"
10388
}
104-
105-
Notice: Undefined property: MongoDB\BSON\Timestamp::$increment in %s on line %d
106-
NULL
107-
108-
Notice: Undefined property: MongoDB\BSON\Timestamp::$timestamp in %s on line %d
109-
NULL
89+
MongoDB\BSON\Timestamp::$increment exists: no
90+
MongoDB\BSON\Timestamp::$timestamp exists: no
11091

11192
object(MongoDB\BSON\UTCDateTime)#%d (%d) {
11293
["milliseconds"]=>
11394
string(%d) "%d"
11495
}
115-
116-
Notice: Undefined property: MongoDB\BSON\UTCDateTime::$milliseconds in %s on line %d
117-
NULL
96+
MongoDB\BSON\UTCDateTime::$milliseconds exists: no
11897

11998
===DONE===

tests/cursor/bug1050-001.phpt

Lines changed: 46 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,31 @@ PHPC-1050: Command cursor should not invoke getMore at execution
1010
<?php
1111
require_once __DIR__ . "/../utils/basic.inc";
1212

13+
class CommandLogger implements MongoDB\Driver\Monitoring\CommandSubscriber
14+
{
15+
public function commandStarted(MongoDB\Driver\Monitoring\CommandStartedEvent $event)
16+
{
17+
if ($event->getCommandName() !== 'aggregate' && $event->getCommandName() !== 'getMore') {
18+
return;
19+
}
20+
21+
printf("Executing command: %s\n", $event->getCommandName());
22+
}
23+
24+
public function commandSucceeded(MongoDB\Driver\Monitoring\CommandSucceededEvent $event)
25+
{
26+
if ($event->getCommandName() !== 'aggregate' && $event->getCommandName() !== 'getMore') {
27+
return;
28+
}
29+
30+
printf("Executing command took %0.6f seconds\n", $event->getDurationMicros() / 1000000);
31+
}
32+
33+
public function commandFailed(MongoDB\Driver\Monitoring\CommandFailedEvent $event)
34+
{
35+
}
36+
}
37+
1338
$manager = new MongoDB\Driver\Manager(URI);
1439

1540
$cmd = new MongoDB\Driver\Command(
@@ -25,25 +50,27 @@ $cmd = new MongoDB\Driver\Command(
2550
]
2651
);
2752

28-
$start = microtime(true);
53+
MongoDB\Driver\Monitoring\addSubscriber(new CommandLogger);
54+
2955
$cursor = $manager->executeReadCommand(DATABASE_NAME, $cmd);
30-
printf("Executing command took %0.6f seconds\n", microtime(true) - $start);
3156

3257
$it = new IteratorIterator($cursor);
3358

34-
$start = microtime(true);
59+
printf("Current position is valid: %s\n\n", $it->valid() ? 'yes' : 'no');
60+
61+
echo "Rewinding cursor\n";
3562
$it->rewind();
36-
printf("Rewinding cursor took %0.6f seconds\n", microtime(true) - $start);
37-
printf("Current position is valid: %s\n", $it->valid() ? 'yes' : 'no');
63+
64+
printf("Current position is valid: %s\n\n", $it->valid() ? 'yes' : 'no');
3865

3966
$bulk = new MongoDB\Driver\BulkWrite;
4067
$bulk->insert(['x' => 1]);
4168
$manager->executeBulkWrite(NS, $bulk);
4269

43-
$start = microtime(true);
70+
echo "Advancing cursor\n";
4471
$it->next();
45-
printf("Advancing cursor took %0.6f seconds\n", microtime(true) - $start);
46-
printf("Current position is valid: %s\n", $it->valid() ? 'yes' : 'no');
72+
73+
printf("Current position is valid: %s\n\n", $it->valid() ? 'yes' : 'no');
4774

4875
$document = $it->current();
4976

@@ -56,11 +83,20 @@ if (isset($document)) {
5683
===DONE===
5784
<?php exit(0); ?>
5885
--EXPECTF--
86+
Executing command: aggregate
5987
Executing command took 0.%d seconds
60-
Rewinding cursor took 0.%r(4|5)%r%d seconds
6188
Current position is valid: no
62-
Advancing cursor took %d.%d seconds
89+
90+
Rewinding cursor
91+
Executing command: getMore
92+
Executing command took 0.%r(4|5)%r%d seconds
93+
Current position is valid: no
94+
95+
Advancing cursor
96+
Executing command: getMore
97+
Executing command took 0.%d seconds
6398
Current position is valid: yes
99+
64100
Operation type: insert
65101
object(stdClass)#%d (%d) {
66102
["_id"]=>

0 commit comments

Comments
 (0)