From 9b9f7742546b422df6c29a653663e2b177187e23 Mon Sep 17 00:00:00 2001 From: Jeremy Mikola Date: Thu, 26 Sep 2024 11:18:02 -0400 Subject: [PATCH] PHPC-2458: Deprecate float arg for UTCDateTime constructor (#1695) --- src/BSON/UTCDateTime.c | 2 ++ tests/bson/bson-document-toCanonicalJSON-002.phpt | 2 +- tests/bson/bson-document-toRelaxedJSON-002.phpt | 2 +- tests/bson/bson-packedarray-toCanonicalJSON-002.phpt | 2 +- tests/bson/bson-packedarray-toRelaxedExtendedJSON-002.phpt | 2 +- tests/bson/bson-toCanonicalJSON-002.phpt | 2 +- tests/bson/bson-toJSON-002.phpt | 2 +- tests/bson/bson-toRelaxedJSON-002.phpt | 2 +- tests/bson/bson-utcdatetime-007.phpt | 5 +++++ 9 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/BSON/UTCDateTime.c b/src/BSON/UTCDateTime.c index 4bdc45b93..a33f78334 100644 --- a/src/BSON/UTCDateTime.c +++ b/src/BSON/UTCDateTime.c @@ -218,6 +218,8 @@ static PHP_METHOD(MongoDB_BSON_UTCDateTime, __construct) return; case IS_DOUBLE: + php_error_docref(NULL, E_DEPRECATED, "Creating a %s instance with a float is deprecated and will be removed in ext-mongodb 2.0", ZSTR_VAL(php_phongo_utcdatetime_ce->name)); + php_phongo_utcdatetime_init_from_double(intern, Z_DVAL_P(milliseconds)); return; diff --git a/tests/bson/bson-document-toCanonicalJSON-002.phpt b/tests/bson/bson-document-toCanonicalJSON-002.phpt index 87c90a3c0..d854d2ee4 100644 --- a/tests/bson/bson-document-toCanonicalJSON-002.phpt +++ b/tests/bson/bson-document-toCanonicalJSON-002.phpt @@ -8,7 +8,7 @@ require_once __DIR__ . '/../utils/basic.inc'; $tests = [ [ '_id' => new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1') ], [ 'binary' => new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ], - [ 'date' => new MongoDB\BSON\UTCDateTime(1445990400000) ], + [ 'date' => new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1445990400000')) ], [ 'timestamp' => new MongoDB\BSON\Timestamp(1234, 5678) ], [ 'regex' => new MongoDB\BSON\Regex('pattern', 'i') ], [ 'code' => new MongoDB\BSON\Javascript('function() { return 1; }') ], diff --git a/tests/bson/bson-document-toRelaxedJSON-002.phpt b/tests/bson/bson-document-toRelaxedJSON-002.phpt index 9a11748b2..b77033554 100644 --- a/tests/bson/bson-document-toRelaxedJSON-002.phpt +++ b/tests/bson/bson-document-toRelaxedJSON-002.phpt @@ -8,7 +8,7 @@ require_once __DIR__ . '/../utils/basic.inc'; $tests = [ [ '_id' => new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1') ], [ 'binary' => new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ], - [ 'date' => new MongoDB\BSON\UTCDateTime(1445990400000) ], + [ 'date' => new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1445990400000')) ], [ 'timestamp' => new MongoDB\BSON\Timestamp(1234, 5678) ], [ 'regex' => new MongoDB\BSON\Regex('pattern', 'i') ], [ 'code' => new MongoDB\BSON\Javascript('function() { return 1; }') ], diff --git a/tests/bson/bson-packedarray-toCanonicalJSON-002.phpt b/tests/bson/bson-packedarray-toCanonicalJSON-002.phpt index 004d8c41f..3f3fa6c4d 100644 --- a/tests/bson/bson-packedarray-toCanonicalJSON-002.phpt +++ b/tests/bson/bson-packedarray-toCanonicalJSON-002.phpt @@ -8,7 +8,7 @@ require_once __DIR__ . '/../utils/basic.inc'; $tests = [ [new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1') ], [new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ], - [new MongoDB\BSON\UTCDateTime(1445990400000) ], + [new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1445990400000')) ], [new MongoDB\BSON\Timestamp(1234, 5678) ], [new MongoDB\BSON\Regex('pattern', 'i') ], [new MongoDB\BSON\Javascript('function() { return 1; }') ], diff --git a/tests/bson/bson-packedarray-toRelaxedExtendedJSON-002.phpt b/tests/bson/bson-packedarray-toRelaxedExtendedJSON-002.phpt index 3fb07f974..d1ca50910 100644 --- a/tests/bson/bson-packedarray-toRelaxedExtendedJSON-002.phpt +++ b/tests/bson/bson-packedarray-toRelaxedExtendedJSON-002.phpt @@ -8,7 +8,7 @@ require_once __DIR__ . '/../utils/basic.inc'; $tests = [ [ new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1') ], [ new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ], - [ new MongoDB\BSON\UTCDateTime(1445990400000) ], + [ new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1445990400000')) ], [ new MongoDB\BSON\Timestamp(1234, 5678) ], [ new MongoDB\BSON\Regex('pattern', 'i') ], [ new MongoDB\BSON\Javascript('function() { return 1; }') ], diff --git a/tests/bson/bson-toCanonicalJSON-002.phpt b/tests/bson/bson-toCanonicalJSON-002.phpt index d9807ce2a..eecae0315 100644 --- a/tests/bson/bson-toCanonicalJSON-002.phpt +++ b/tests/bson/bson-toCanonicalJSON-002.phpt @@ -8,7 +8,7 @@ require_once __DIR__ . '/../utils/basic.inc'; $tests = [ [ '_id' => new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1') ], [ 'binary' => new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ], - [ 'date' => new MongoDB\BSON\UTCDateTime(1445990400000) ], + [ 'date' => new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1445990400000')) ], [ 'timestamp' => new MongoDB\BSON\Timestamp(1234, 5678) ], [ 'regex' => new MongoDB\BSON\Regex('pattern', 'i') ], [ 'code' => new MongoDB\BSON\Javascript('function() { return 1; }') ], diff --git a/tests/bson/bson-toJSON-002.phpt b/tests/bson/bson-toJSON-002.phpt index 1d13e504a..5df4d5cc2 100644 --- a/tests/bson/bson-toJSON-002.phpt +++ b/tests/bson/bson-toJSON-002.phpt @@ -8,7 +8,7 @@ require_once __DIR__ . '/../utils/basic.inc'; $tests = [ [ '_id' => new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1') ], [ 'binary' => new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ], - [ 'date' => new MongoDB\BSON\UTCDateTime(1445990400000) ], + [ 'date' => new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1445990400000')) ], [ 'timestamp' => new MongoDB\BSON\Timestamp(1234, 5678) ], [ 'regex' => new MongoDB\BSON\Regex('pattern', 'i') ], [ 'code' => new MongoDB\BSON\Javascript('function() { return 1; }') ], diff --git a/tests/bson/bson-toRelaxedJSON-002.phpt b/tests/bson/bson-toRelaxedJSON-002.phpt index a324d1580..fb2f0ef33 100644 --- a/tests/bson/bson-toRelaxedJSON-002.phpt +++ b/tests/bson/bson-toRelaxedJSON-002.phpt @@ -8,7 +8,7 @@ require_once __DIR__ . '/../utils/basic.inc'; $tests = [ [ '_id' => new MongoDB\BSON\ObjectId('56315a7c6118fd1b920270b1') ], [ 'binary' => new MongoDB\BSON\Binary('foo', MongoDB\BSON\Binary::TYPE_GENERIC) ], - [ 'date' => new MongoDB\BSON\UTCDateTime(1445990400000) ], + [ 'date' => new MongoDB\BSON\UTCDateTime(new MongoDB\BSON\Int64('1445990400000')) ], [ 'timestamp' => new MongoDB\BSON\Timestamp(1234, 5678) ], [ 'regex' => new MongoDB\BSON\Regex('pattern', 'i') ], [ 'code' => new MongoDB\BSON\Javascript('function() { return 1; }') ], diff --git a/tests/bson/bson-utcdatetime-007.phpt b/tests/bson/bson-utcdatetime-007.phpt index ec6e53789..9b4cbcd1c 100644 --- a/tests/bson/bson-utcdatetime-007.phpt +++ b/tests/bson/bson-utcdatetime-007.phpt @@ -17,6 +17,11 @@ foreach ($tests as $test) { ===DONE=== --EXPECTF-- +Deprecated: MongoDB\BSON\UTCDateTime::__construct(): Creating a MongoDB\BSON\UTCDateTime instance with a float is deprecated and will be removed in ext-mongodb 2.0 in %s on line %d + +Deprecated: MongoDB\BSON\UTCDateTime::__construct(): Creating a MongoDB\BSON\UTCDateTime instance with a float is deprecated and will be removed in ext-mongodb 2.0 in %s on line %d + +Deprecated: MongoDB\BSON\UTCDateTime::__construct(): Creating a MongoDB\BSON\UTCDateTime instance with a float is deprecated and will be removed in ext-mongodb 2.0 in %s on line %d object(MongoDB\BSON\UTCDateTime)#%d (%d) { ["milliseconds"]=> string(13) "1416445411987"