Skip to content

PHPC-2117: Test on PHP 8.2 #1340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
- "7.4"
- "8.0"
- "8.1"
- "8.2"
mongodb-version:
- "4.4"
topology:
Expand Down
3 changes: 3 additions & 0 deletions tests/apm/commandFailedEvent-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ $m = create_test_manager();

class MySubscriber implements MongoDB\Driver\Monitoring\CommandSubscriber
{
private $startRequestId;
private $startOperationId;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


public function commandStarted( \MongoDB\Driver\Monitoring\CommandStartedEvent $event ): void
{
echo "started: ", $event->getCommandName(), "\n";
Expand Down
3 changes: 3 additions & 0 deletions tests/apm/commandSucceededEvent-002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ $m = create_test_manager();

class MySubscriber implements MongoDB\Driver\Monitoring\CommandSubscriber
{
private $startRequestId;
private $startOperationId;

public function commandStarted( \MongoDB\Driver\Monitoring\CommandStartedEvent $event ): void
{
echo "started: ", $event->getCommandName(), "\n";
Expand Down
15 changes: 4 additions & 11 deletions tests/bson/bson-binary-clone-001.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
--TEST--
MongoDB\BSON\Binary can be cloned
MongoDB\BSON\Binary can be cloned (PHP < 8.2)
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_php_version('>=', '8.2'); ?>
--FILE--
<?php

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was actually a regression test for PHPC-1230 dating back to aed8384.

If we're removing this across the board, would it make sense to reintroduce a clone test for at least one class that runs on PHP versions before 8.2?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good point - I'll duplicate the tests and have them create dynamic properties on PHP before 8.2. 👍

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated each test for PHP 8.2 and restored the originals 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this test is now restricted to PHP < 8.2, shouldn't we add back the dynamic property testing? This might have been an oversight.

Also, quoting version_compare:

Note that pre-release versions, such as 5.3.0-dev, are considered lower than their final release counterparts (like 5.3.0).

So I think we do want to use <?php skip_if_php_version('>=', '8.1.99'); ?> as discussed in #1340 (comment)


$clone = clone $binary;

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

var_dump($clone);
var_dump($clone->foo);
}
?>
===DONE===
Expand All @@ -42,7 +43,6 @@ object(MongoDB\BSON\Binary)#%d (2) {
["type"]=>
int(0)
}
string(3) "bar"
bool(true)
bool(false)
object(MongoDB\BSON\Binary)#%d (2) {
Expand All @@ -51,7 +51,6 @@ object(MongoDB\BSON\Binary)#%d (2) {
["type"]=>
int(1)
}
string(3) "bar"
bool(true)
bool(false)
object(MongoDB\BSON\Binary)#%d (2) {
Expand All @@ -60,7 +59,6 @@ object(MongoDB\BSON\Binary)#%d (2) {
["type"]=>
int(2)
}
string(3) "bar"
bool(true)
bool(false)
object(MongoDB\BSON\Binary)#%d (2) {
Expand All @@ -69,7 +67,6 @@ object(MongoDB\BSON\Binary)#%d (2) {
["type"]=>
int(3)
}
string(3) "bar"
bool(true)
bool(false)
object(MongoDB\BSON\Binary)#%d (2) {
Expand All @@ -78,7 +75,6 @@ object(MongoDB\BSON\Binary)#%d (2) {
["type"]=>
int(4)
}
string(3) "bar"
bool(true)
bool(false)
object(MongoDB\BSON\Binary)#%d (2) {
Expand All @@ -87,7 +83,6 @@ object(MongoDB\BSON\Binary)#%d (2) {
["type"]=>
int(5)
}
string(3) "bar"
bool(true)
bool(false)
object(MongoDB\BSON\Binary)#%d (2) {
Expand All @@ -96,7 +91,6 @@ object(MongoDB\BSON\Binary)#%d (2) {
["type"]=>
int(128)
}
string(3) "bar"
bool(true)
bool(false)
object(MongoDB\BSON\Binary)#%d (2) {
Expand All @@ -105,5 +99,4 @@ object(MongoDB\BSON\Binary)#%d (2) {
["type"]=>
int(133)
}
string(3) "bar"
===DONE===
102 changes: 102 additions & 0 deletions tests/bson/bson-binary-clone-002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
--TEST--
MongoDB\BSON\Binary can be cloned (PHP >= 8.2)
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_php_version('<', '8.2'); ?>
--FILE--
<?php

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

$types = array(
MongoDB\BSON\Binary::TYPE_GENERIC,
MongoDB\BSON\Binary::TYPE_FUNCTION,
MongoDB\BSON\Binary::TYPE_OLD_BINARY,
MongoDB\BSON\Binary::TYPE_OLD_UUID,
MongoDB\BSON\Binary::TYPE_UUID,
MongoDB\BSON\Binary::TYPE_MD5,
MongoDB\BSON\Binary::TYPE_USER_DEFINED,
MongoDB\BSON\Binary::TYPE_USER_DEFINED+5,
);
foreach($types as $type) {
// Use 16-byte data to satisfy UUID requirements
$binary = new MongoDB\BSON\Binary('randomBinaryData', $type);

$clone = clone $binary;

var_dump($clone == $binary);
var_dump($clone === $binary);

unset($binary);

var_dump($clone);
}
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
bool(true)
bool(false)
object(MongoDB\BSON\Binary)#%d (2) {
["data"]=>
string(16) "randomBinaryData"
["type"]=>
int(0)
}
bool(true)
bool(false)
object(MongoDB\BSON\Binary)#%d (2) {
["data"]=>
string(16) "randomBinaryData"
["type"]=>
int(1)
}
bool(true)
bool(false)
object(MongoDB\BSON\Binary)#%d (2) {
["data"]=>
string(16) "randomBinaryData"
["type"]=>
int(2)
}
bool(true)
bool(false)
object(MongoDB\BSON\Binary)#%d (2) {
["data"]=>
string(16) "randomBinaryData"
["type"]=>
int(3)
}
bool(true)
bool(false)
object(MongoDB\BSON\Binary)#%d (2) {
["data"]=>
string(16) "randomBinaryData"
["type"]=>
int(4)
}
bool(true)
bool(false)
object(MongoDB\BSON\Binary)#%d (2) {
["data"]=>
string(16) "randomBinaryData"
["type"]=>
int(5)
}
bool(true)
bool(false)
object(MongoDB\BSON\Binary)#%d (2) {
["data"]=>
string(16) "randomBinaryData"
["type"]=>
int(128)
}
bool(true)
bool(false)
object(MongoDB\BSON\Binary)#%d (2) {
["data"]=>
string(16) "randomBinaryData"
["type"]=>
int(133)
}
===DONE===
10 changes: 5 additions & 5 deletions tests/bson/bson-binary-set_state-001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ foreach ($tests as $test) {
===DONE===
<?php exit(0); ?>
--EXPECTF--
MongoDB\BSON\Binary::__set_state(array(
%r\\?%rMongoDB\BSON\Binary::__set_state(array(
%w'data' => 'foobar',
%w'type' => 0,
))

MongoDB\BSON\Binary::__set_state(array(
%r\\?%rMongoDB\BSON\Binary::__set_state(array(
%w'data' => '',
%w'type' => 0,
))

MongoDB\BSON\Binary::__set_state(array(
%r\\?%rMongoDB\BSON\Binary::__set_state(array(
%w'data' => '' . "\0" . 'foo',
%w'type' => 0,
))

MongoDB\BSON\Binary::__set_state(array(
%r\\?%rMongoDB\BSON\Binary::__set_state(array(
%w'data' => '>Eg�ӤVBfUD' . "\0" . '' . "\0" . '',
%w'type' => 4,
))

MongoDB\BSON\Binary::__set_state(array(
%r\\?%rMongoDB\BSON\Binary::__set_state(array(
%w'data' => '8X�"0�<�_0 fC�?',
%w'type' => 5,
))
Expand Down
8 changes: 4 additions & 4 deletions tests/bson/bson-dbpointer-clone-001.phpt
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
--TEST--
MongoDB\BSON\DBPointer can be cloned
MongoDB\BSON\DBPointer can be cloned (PHP < 8.2)
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_php_version('>=', '8.2'); ?>
--FILE--
<?php

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

$dbPointer = $test->dbref;
$dbPointer->foo = 'bar';
$clone = clone($dbPointer);

var_dump($clone == $dbPointer);
Expand All @@ -17,7 +19,6 @@ var_dump($clone === $dbPointer);
unset($dbPointer);

var_dump($clone);
var_dump($clone->foo);
?>
===DONE===
<?php exit(0); ?>
Expand All @@ -30,5 +31,4 @@ object(MongoDB\BSON\DBPointer)#%d (2) {
["id"]=>
string(24) "5a2e78accd485d55b405ac12"
}
string(3) "bar"
===DONE===
34 changes: 34 additions & 0 deletions tests/bson/bson-dbpointer-clone-002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
--TEST--
MongoDB\BSON\DBPointer can be cloned (PHP >= 8.2)
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_php_version('<', '8.2'); ?>
--FILE--
<?php

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

$test = MongoDB\BSON\toPHP(MongoDB\BSON\fromJSON('{ "dbref": {"$dbPointer": {"$ref": "phongo.test", "$id" : { "$oid" : "5a2e78accd485d55b405ac12" } }} }'));

$dbPointer = $test->dbref;
$clone = clone($dbPointer);

var_dump($clone == $dbPointer);
var_dump($clone === $dbPointer);

unset($dbPointer);

var_dump($clone);
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
bool(true)
bool(false)
object(MongoDB\BSON\DBPointer)#%d (2) {
["ref"]=>
string(11) "phongo.test"
["id"]=>
string(24) "5a2e78accd485d55b405ac12"
}
===DONE===
7 changes: 3 additions & 4 deletions tests/bson/bson-decimal128-clone-001.phpt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
--TEST--
MongoDB\BSON\Decimal128 can be cloned
MongoDB\BSON\Decimal128 can be cloned (PHP < 8.2)
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_php_version('>=', '8.2'); ?>
<?php if (!class_exists('MongoDB\BSON\Decimal128')) { die('skip MongoDB\BSON\Decimal128 is not available'); } ?>
--FILE--
<?php

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

$clone = clone $decimal;

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

var_dump($clone);
var_dump($clone->foo);
?>
===DONE===
<?php exit(0); ?>
Expand All @@ -27,5 +27,4 @@ object(MongoDB\BSON\Decimal128)#%d (1) {
["dec"]=>
string(9) "1234.5678"
}
string(3) "bar"
===DONE===
30 changes: 30 additions & 0 deletions tests/bson/bson-decimal128-clone-002.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
--TEST--
MongoDB\BSON\Decimal128 can be cloned (PHP >= 8.2)
--SKIPIF--
<?php require __DIR__ . "/../utils/basic-skipif.inc"; ?>
<?php skip_if_php_version('<', '8.2'); ?>
<?php if (!class_exists('MongoDB\BSON\Decimal128')) { die('skip MongoDB\BSON\Decimal128 is not available'); } ?>
--FILE--
<?php

$decimal = new MongoDB\BSON\Decimal128('1234.5678');

$clone = clone $decimal;

var_dump($clone == $decimal);
var_dump($clone === $decimal);

unset($decimal);

var_dump($clone);
?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
bool(true)
bool(false)
object(MongoDB\BSON\Decimal128)#%d (1) {
["dec"]=>
string(9) "1234.5678"
}
===DONE===
Loading