mirror of
https://github.com/macintoshplus/mongo-php-driver.git
synced 2026-04-02 06:12:08 +02:00
Merge pull request #223
This commit is contained in:
@@ -66,8 +66,7 @@ PHP_METHOD(ObjectID, __construct)
|
||||
}
|
||||
zend_restore_error_handling(&error_handling TSRMLS_CC);
|
||||
|
||||
|
||||
if (ZEND_NUM_ARGS()) {
|
||||
if (id) {
|
||||
if (bson_oid_is_valid(id, id_len)) {
|
||||
bson_oid_t oid;
|
||||
|
||||
|
||||
26
tests/bson/bson-objectid-002.phpt
Normal file
26
tests/bson/bson-objectid-002.phpt
Normal file
@@ -0,0 +1,26 @@
|
||||
--TEST--
|
||||
BSON BSON\ObjectID #002 generates ObjectID for null or missing constructor argument
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . "/../utils/basic.inc";
|
||||
|
||||
$classname = BSON_NAMESPACE . "\\ObjectID";
|
||||
|
||||
var_dump(new $classname());
|
||||
var_dump(new $classname(null));
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
<?php exit(0); ?>
|
||||
--EXPECTF--
|
||||
object(MongoDB\BSON\ObjectID)#%d (%d) {
|
||||
["oid"]=>
|
||||
string(24) "%x"
|
||||
}
|
||||
object(MongoDB\BSON\ObjectID)#%d (%d) {
|
||||
["oid"]=>
|
||||
string(24) "%x"
|
||||
}
|
||||
===DONE===
|
||||
49
tests/bson/bson-objectid-003.phpt
Normal file
49
tests/bson/bson-objectid-003.phpt
Normal file
@@ -0,0 +1,49 @@
|
||||
--TEST--
|
||||
BSON BSON\ObjectID #001 construction with string argument
|
||||
--SKIPIF--
|
||||
<?php require __DIR__ . "/../utils/basic-skipif.inc"?>
|
||||
--FILE--
|
||||
<?php
|
||||
require_once __DIR__ . "/../utils/basic.inc";
|
||||
|
||||
$classname = BSON_NAMESPACE . "\\ObjectID";
|
||||
|
||||
class StringObject
|
||||
{
|
||||
private $value;
|
||||
|
||||
public function __construct($value)
|
||||
{
|
||||
$this->value = (string) $value;
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
{
|
||||
return $this->value;
|
||||
}
|
||||
}
|
||||
|
||||
$oid = new $classname('53e2a1c40640fd72175d4603');
|
||||
$str = new StringObject('53e2a1c40640fd72175d4603');
|
||||
|
||||
var_dump($oid);
|
||||
var_dump(new $classname($oid));
|
||||
var_dump(new $classname($str));
|
||||
|
||||
?>
|
||||
===DONE===
|
||||
<?php exit(0); ?>
|
||||
--EXPECTF--
|
||||
object(MongoDB\BSON\ObjectID)#%d (%d) {
|
||||
["oid"]=>
|
||||
string(24) "53e2a1c40640fd72175d4603"
|
||||
}
|
||||
object(MongoDB\BSON\ObjectID)#%d (%d) {
|
||||
["oid"]=>
|
||||
string(24) "53e2a1c40640fd72175d4603"
|
||||
}
|
||||
object(MongoDB\BSON\ObjectID)#%d (%d) {
|
||||
["oid"]=>
|
||||
string(24) "53e2a1c40640fd72175d4603"
|
||||
}
|
||||
===DONE===
|
||||
Reference in New Issue
Block a user