Skip to content

Commit fe3c8c6

Browse files
committed
Merge pull request #223
2 parents 51707d8 + 41cadec commit fe3c8c6

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed

src/BSON/ObjectID.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ PHP_METHOD(ObjectID, __construct)
6666
}
6767
zend_restore_error_handling(&error_handling TSRMLS_CC);
6868

69-
70-
if (ZEND_NUM_ARGS()) {
69+
if (id) {
7170
if (bson_oid_is_valid(id, id_len)) {
7271
bson_oid_t oid;
7372

tests/bson/bson-objectid-002.phpt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--TEST--
2+
BSON BSON\ObjectID #002 generates ObjectID for null or missing constructor argument
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
$classname = BSON_NAMESPACE . "\\ObjectID";
10+
11+
var_dump(new $classname());
12+
var_dump(new $classname(null));
13+
14+
?>
15+
===DONE===
16+
<?php exit(0); ?>
17+
--EXPECTF--
18+
object(MongoDB\BSON\ObjectID)#%d (%d) {
19+
["oid"]=>
20+
string(24) "%x"
21+
}
22+
object(MongoDB\BSON\ObjectID)#%d (%d) {
23+
["oid"]=>
24+
string(24) "%x"
25+
}
26+
===DONE===

tests/bson/bson-objectid-003.phpt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
--TEST--
2+
BSON BSON\ObjectID #001 construction with string argument
3+
--SKIPIF--
4+
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
5+
--FILE--
6+
<?php
7+
require_once __DIR__ . "/../utils/basic.inc";
8+
9+
$classname = BSON_NAMESPACE . "\\ObjectID";
10+
11+
class StringObject
12+
{
13+
private $value;
14+
15+
public function __construct($value)
16+
{
17+
$this->value = (string) $value;
18+
}
19+
20+
public function __toString()
21+
{
22+
return $this->value;
23+
}
24+
}
25+
26+
$oid = new $classname('53e2a1c40640fd72175d4603');
27+
$str = new StringObject('53e2a1c40640fd72175d4603');
28+
29+
var_dump($oid);
30+
var_dump(new $classname($oid));
31+
var_dump(new $classname($str));
32+
33+
?>
34+
===DONE===
35+
<?php exit(0); ?>
36+
--EXPECTF--
37+
object(MongoDB\BSON\ObjectID)#%d (%d) {
38+
["oid"]=>
39+
string(24) "53e2a1c40640fd72175d4603"
40+
}
41+
object(MongoDB\BSON\ObjectID)#%d (%d) {
42+
["oid"]=>
43+
string(24) "53e2a1c40640fd72175d4603"
44+
}
45+
object(MongoDB\BSON\ObjectID)#%d (%d) {
46+
["oid"]=>
47+
string(24) "53e2a1c40640fd72175d4603"
48+
}
49+
===DONE===

0 commit comments

Comments
 (0)