Skip to content

Commit 7f485f9

Browse files
committed
PHPC-761: Tests can rely on MongoDB\BSON namespace
1 parent 441a1d7 commit 7f485f9

File tree

72 files changed

+193
-297
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+193
-297
lines changed

tests/bson/bson-binary-001.phpt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,19 @@ BSON BSON\Binary #001
55

66
require_once __DIR__ . '/../utils/tools.php';
77

8-
$classname = BSON_NAMESPACE . "\\Binary";
9-
108
$types = array(
11-
$classname::TYPE_GENERIC,
12-
$classname::TYPE_FUNCTION,
13-
$classname::TYPE_OLD_BINARY,
14-
$classname::TYPE_OLD_UUID,
15-
$classname::TYPE_UUID,
16-
$classname::TYPE_MD5,
17-
$classname::TYPE_USER_DEFINED,
18-
$classname::TYPE_USER_DEFINED+5,
9+
MongoDB\BSON\Binary::TYPE_GENERIC,
10+
MongoDB\BSON\Binary::TYPE_FUNCTION,
11+
MongoDB\BSON\Binary::TYPE_OLD_BINARY,
12+
MongoDB\BSON\Binary::TYPE_OLD_UUID,
13+
MongoDB\BSON\Binary::TYPE_UUID,
14+
MongoDB\BSON\Binary::TYPE_MD5,
15+
MongoDB\BSON\Binary::TYPE_USER_DEFINED,
16+
MongoDB\BSON\Binary::TYPE_USER_DEFINED+5,
1917
);
2018
$tests = array();
2119
foreach($types as $type) {
22-
$binary = new $classname("random binary data", $type);
20+
$binary = new MongoDB\BSON\Binary("random binary data", $type);
2321
var_dump($binary->getData() == "random binary data");
2422
var_dump($binary->getType() == $type);
2523
$tests[] = array("binary" => $binary);

tests/bson/bson-binary_error-001.phpt

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,21 @@ BSON BSON\Binary #001 error
77

88
require_once __DIR__ . '/../utils/tools.php';
99

10-
$classname = BSON_NAMESPACE . "\\Binary";
11-
12-
$binary = new $classname("random binary data", $classname::TYPE_GENERIC);
10+
$binary = new MongoDB\BSON\Binary("random binary data", MongoDB\BSON\Binary::TYPE_GENERIC);
1311
$binary->getData(2);
1412
$binary->getType(2);
1513

16-
throws(function() use($classname) {
17-
new $classname("random binary data without type");
14+
throws(function() {
15+
new MongoDB\BSON\Binary("random binary data without type");
1816
}, "MongoDB\\Driver\\Exception\\InvalidArgumentException");
1917

2018
?>
2119
===DONE===
2220
<?php exit(0); ?>
2321
--EXPECTF--
24-
Warning: %s\Binary::getData() expects exactly 0 parameters, 1 given in %s on line %d
22+
Warning: MongoDB\BSON\Binary::getData() expects exactly 0 parameters, 1 given in %s on line %d
2523

26-
Warning: %s\Binary::getType() expects exactly 0 parameters, 1 given in %s on line %d
24+
Warning: MongoDB\BSON\Binary::getType() expects exactly 0 parameters, 1 given in %s on line %d
2725
OK: Got MongoDB\Driver\Exception\InvalidArgumentException
2826
===DONE===
2927

tests/bson/bson-binary_error-002.phpt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ BSON BSON\Binary cannot be extended
33
--FILE--
44
<?php
55

6-
use MongoDB\BSON as BSON;
7-
8-
class MyBinary extends BSON\Binary {}
6+
class MyBinary extends MongoDB\BSON\Binary {}
97

108
?>
119
===DONE===
1210
<?php exit(0); ?>
1311
--EXPECTF--
14-
Fatal error: Class MyBinary may not inherit from final class (%SBSON\Binary) in %s on line %d
12+
Fatal error: Class MyBinary may not inherit from final class (MongoDB\BSON\Binary) in %s on line %d

tests/bson/bson-binary_error-003.phpt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,12 @@ BSON BSON\Binary constructor requires unsigned 8-bit integer for type
55

66
require_once __DIR__ . '/../utils/tools.php';
77

8-
use MongoDB\BSON as BSON;
9-
108
echo throws(function() {
11-
new BSON\Binary('foo', -1);
9+
new MongoDB\BSON\Binary('foo', -1);
1210
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
1311

1412
echo throws(function() {
15-
new BSON\Binary('foo', 256);
13+
new MongoDB\BSON\Binary('foo', 256);
1614
}, 'MongoDB\Driver\Exception\InvalidArgumentException'), "\n";
1715

1816
?>

tests/bson/bson-decode-002.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
BSON encoding: Encoding object/arrays data into user specificied classes
33
--FILE--
44
<?php
5-
use MongoDB\BSON as BSON;
65

76
require_once __DIR__ . '/../utils/tools.php';
87

9-
class MyArrayObject extends ArrayObject implements BSON\Unserializable {
8+
class MyArrayObject extends ArrayObject implements MongoDB\BSON\Unserializable {
109
function bsonUnserialize(array $data) {
1110
parent::__construct($data);
1211
}

tests/bson/bson-encode-001.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
BSON encoding: Encoding data into BSON representation, and BSON into Extended JSON
33
--FILE--
44
<?php
5-
use MongoDB\BSON as BSON;
65

76
require_once __DIR__ . '/../utils/tools.php';
87

tests/bson/bson-encode-002.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
BSON encoding: Encoding objects into BSON representation
33
--FILE--
44
<?php
5-
use MongoDB\BSON as BSON;
65

76
require_once __DIR__ . '/../utils/tools.php';
87

9-
class AssociativeArray implements BSON\Serializable, BSON\Unserializable
8+
class AssociativeArray implements MongoDB\BSON\Serializable, MongoDB\BSON\Unserializable
109
{
1110
public function bsonSerialize()
1211
{
@@ -20,7 +19,7 @@ class AssociativeArray implements BSON\Serializable, BSON\Unserializable
2019
}
2120
}
2221

23-
class NumericArray implements BSON\Serializable, BSON\Unserializable
22+
class NumericArray implements MongoDB\BSON\Serializable, MongoDB\BSON\Unserializable
2423
{
2524
public function bsonSerialize()
2625
{

tests/bson/bson-encode-003.phpt

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ BSON encoding: Encoding objects into BSON representation
44
<?php if (defined("HHVM_VERSION_ID")) exit("skip HHVM encodes __pclass last"); ?>
55
--FILE--
66
<?php
7-
use MongoDB\BSON as BSON;
87

98
require_once __DIR__ . '/../utils/tools.php';
109

11-
class MyClass implements BSON\Persistable {
10+
class MyClass implements MongoDB\BSON\Persistable {
1211
function bsonSerialize() {
1312
return array(
1413
"random" => "class",
@@ -19,7 +18,7 @@ class MyClass implements BSON\Persistable {
1918
$this->props = $data;
2019
}
2120
}
22-
class MyClass2 implements BSON\Persistable {
21+
class MyClass2 implements MongoDB\BSON\Persistable {
2322
function bsonSerialize() {
2423
return array(
2524
1, 2, 3,
@@ -59,7 +58,7 @@ object(stdClass)#%d (1) {
5958
["props"]=>
6059
array(3) {
6160
["__pclass"]=>
62-
object(%SBSON\Binary)#%d (2) {
61+
object(MongoDB\BSON\Binary)#%d (2) {
6362
["data"]=>
6463
string(7) "MyClass"
6564
["type"]=>
@@ -83,7 +82,7 @@ object(stdClass)#%d (1) {
8382
["props"]=>
8483
array(4) {
8584
["__pclass"]=>
86-
object(%SBSON\Binary)#%d (2) {
85+
object(MongoDB\BSON\Binary)#%d (2) {
8786
["data"]=>
8887
string(8) "MyClass2"
8988
["type"]=>
@@ -116,7 +115,7 @@ object(stdClass)#%d (1) {
116115
["props"]=>
117116
array(3) {
118117
["__pclass"]=>
119-
object(%SBSON\Binary)#%d (2) {
118+
object(MongoDB\BSON\Binary)#%d (2) {
120119
["data"]=>
121120
string(7) "MyClass"
122121
["type"]=>
@@ -133,7 +132,7 @@ object(stdClass)#%d (1) {
133132
["props"]=>
134133
array(4) {
135134
["__pclass"]=>
136-
object(%SBSON\Binary)#%d (2) {
135+
object(MongoDB\BSON\Binary)#%d (2) {
137136
["data"]=>
138137
string(8) "MyClass2"
139138
["type"]=>

tests/bson/bson-encode-004.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ BSON encoding: Object Document Mapper
44
<?php if (defined("HHVM_VERSION_ID")) exit("skip HHVM encodes __pclass last"); ?>
55
--FILE--
66
<?php
7-
use MongoDB\BSON as BSON;
87

98
require_once __DIR__ . '/../utils/tools.php';
109
require_once __DIR__ . "/../utils/classes.inc";

tests/bson/bson-encode-005.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
BSON encoding: Object Document Mapper
33
--FILE--
44
<?php
5-
use MongoDB\BSON as BSON;
65

76
require_once __DIR__ . '/../utils/tools.php';
87

tests/bson/bson-fromPHP-001.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
BSON\fromPHP(): bsonSerialize() allows array and stdClass
33
--FILE--
44
<?php
5-
use MongoDB\BSON as BSON;
65

76
require_once __DIR__ . '/../utils/tools.php';
87

9-
class MyDocument implements BSON\Serializable
8+
class MyDocument implements MongoDB\BSON\Serializable
109
{
1110
private $data;
1211

tests/bson/bson-fromPHP-002.phpt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ BSON\fromPHP(): Encoding non-Persistable objects as a document
44
date.timezone=America/Los_Angeles
55
--FILE--
66
<?php
7-
use MongoDB\BSON as BSON;
87

98
require_once __DIR__ . '/../utils/tools.php';
109

tests/bson/bson-fromPHP-003.phpt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ BSON\fromPHP(): Encoding non-Persistable objects as a document field value
44
date.timezone=America/Los_Angeles
55
--FILE--
66
<?php
7-
use MongoDB\BSON as BSON;
87

98
require_once __DIR__ . '/../utils/tools.php';
109

@@ -15,8 +14,8 @@ class MyDocument {
1514
}
1615

1716
$tests = array(
18-
array(new BSON\UTCDateTime('1416445411987')),
19-
array('x' => new BSON\UTCDateTime('1416445411987')),
17+
array(new MongoDB\BSON\UTCDateTime('1416445411987')),
18+
array('x' => new MongoDB\BSON\UTCDateTime('1416445411987')),
2019
array(new MyDocument),
2120
array('x' => new MyDocument),
2221
);

tests/bson/bson-fromPHP_error-001.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
BSON\fromPHP(): bsonSerialize() must return an array or stdClass
33
--FILE--
44
<?php
5-
use MongoDB\BSON as BSON;
65

76
require_once __DIR__ . '/../utils/tools.php';
87

9-
class MyDocument implements BSON\Serializable
8+
class MyDocument implements MongoDB\BSON\Serializable
109
{
1110
private $data;
1211

tests/bson/bson-fromPHP_error-002.phpt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22
BSON\fromPHP(): Encoding unknown Type objects as a document field value
33
--FILE--
44
<?php
5-
use MongoDB\BSON as BSON;
65

76
require_once __DIR__ . '/../utils/tools.php';
87

9-
class UnknownType implements BSON\Type {}
8+
class UnknownType implements MongoDB\BSON\Type {}
109

1110
$tests = array(
1211
array(new UnknownType()),
@@ -24,7 +23,7 @@ foreach ($tests as $document) {
2423
<?php exit(0); ?>
2524
--EXPECTF--
2625
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
27-
Unexpected %SBSON\Type instance: UnknownType
26+
Unexpected MongoDB\BSON\Type instance: UnknownType
2827
OK: Got MongoDB\Driver\Exception\UnexpectedValueException
29-
Unexpected %SBSON\Type instance: UnknownType
28+
Unexpected MongoDB\BSON\Type instance: UnknownType
3029
===DONE===

tests/bson/bson-fromPHP_error-003.phpt

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,21 @@ BSON\fromPHP(): Encoding non-Serializable Type objects as a root element
44
date.timezone=America/Los_Angeles
55
--FILE--
66
<?php
7-
use MongoDB\BSON as BSON;
87

98
require_once __DIR__ . '/../utils/tools.php';
109

11-
class UnknownType implements BSON\Type {}
10+
class UnknownType implements MongoDB\BSON\Type {}
1211

1312
$tests = array(
1413
new UnknownType,
15-
new BSON\Binary('foobar', BSON\Binary::TYPE_GENERIC),
16-
new BSON\Javascript('function foo(bar) {var baz = bar; var bar = foo; return bar; }'),
17-
new BSON\MinKey,
18-
new BSON\MaxKey,
19-
new BSON\ObjectId,
20-
new BSON\Regex('regexp', 'i'),
21-
new BSON\Timestamp(1234, 5678),
22-
new BSON\UTCDateTime('1416445411987'),
14+
new MongoDB\BSON\Binary('foobar', MongoDB\BSON\Binary::TYPE_GENERIC),
15+
new MongoDB\BSON\Javascript('function foo(bar) {var baz = bar; var bar = foo; return bar; }'),
16+
new MongoDB\BSON\MinKey,
17+
new MongoDB\BSON\MaxKey,
18+
new MongoDB\BSON\ObjectId,
19+
new MongoDB\BSON\Regex('regexp', 'i'),
20+
new MongoDB\BSON\Timestamp(1234, 5678),
21+
new MongoDB\BSON\UTCDateTime('1416445411987'),
2322
);
2423

2524
foreach ($tests as $document) {

tests/bson/bson-javascript-001.phpt

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ BSON BSON\Javascript #001
55

66
require_once __DIR__ . '/../utils/tools.php';
77

8-
$classname = BSON_NAMESPACE . "\\Javascript";
9-
10-
$js = new $classname("function foo(bar) {var baz = bar; var bar = foo; return bar; }");
11-
$jswscope = new $classname("function foo(bar) {var baz = bar; var bar = foo; return bar; }", array("foo" => 42));
8+
$js = new MongoDB\BSON\Javascript("function foo(bar) {var baz = bar; var bar = foo; return bar; }");
9+
$jswscope = new MongoDB\BSON\Javascript("function foo(bar) {var baz = bar; var bar = foo; return bar; }", array("foo" => 42));
1210
$tests = array(
1311
array("js" => $js),
1412
array("js" => $jswscope),
@@ -18,8 +16,8 @@ foreach($tests as $n => $test) {
1816
echo "Test#{$n}", "\n";
1917
$s = fromPHP($test);
2018
$testagain = toPHP($s);
21-
var_dump($test['js'] instanceof $classname);
22-
var_dump($testagain->js instanceof $classname);
19+
var_dump($test['js'] instanceof MongoDB\BSON\Javascript);
20+
var_dump($testagain->js instanceof MongoDB\BSON\Javascript);
2321
}
2422

2523
?>

tests/bson/bson-javascript-002.phpt

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ BSON BSON\Javascript debug handler
33
--FILE--
44
<?php
55

6-
require_once __DIR__ . '/../utils/tools.php';
7-
8-
$jsClassname = BSON_NAMESPACE . '\Javascript';
9-
$oidClassname = BSON_NAMESPACE . '\ObjectId';
10-
116
$tests = array(
127
array(
138
'function foo(bar) { return bar; }',
@@ -19,29 +14,29 @@ $tests = array(
1914
),
2015
array(
2116
'function foo() { return id; }',
22-
array('id' => new $oidClassname('53e2a1c40640fd72175d4603')),
17+
array('id' => new MongoDB\BSON\ObjectID('53e2a1c40640fd72175d4603')),
2318
),
2419
);
2520

2621
foreach ($tests as $test) {
2722
list($code, $scope) = $test;
2823

29-
$js = new $jsClassname($code, $scope);
24+
$js = new MongoDB\BSON\Javascript($code, $scope);
3025
var_dump($js);
3126
}
3227

3328
?>
3429
===DONE===
3530
<?php exit(0); ?>
3631
--EXPECTF--
37-
object(%SBSON\Javascript)#%d (%d) {
32+
object(MongoDB\BSON\Javascript)#%d (%d) {
3833
["code"]=>
3934
string(33) "function foo(bar) { return bar; }"
4035
["scope"]=>
4136
object(stdClass)#%d (%d) {
4237
}
4338
}
44-
object(%SBSON\Javascript)#%d (%d) {
39+
object(MongoDB\BSON\Javascript)#%d (%d) {
4540
["code"]=>
4641
string(30) "function foo() { return foo; }"
4742
["scope"]=>
@@ -50,7 +45,7 @@ object(%SBSON\Javascript)#%d (%d) {
5045
int(42)
5146
}
5247
}
53-
object(%SBSON\Javascript)#%d (%d) {
48+
object(MongoDB\BSON\Javascript)#%d (%d) {
5449
["code"]=>
5550
string(29) "function foo() { return id; }"
5651
["scope"]=>

0 commit comments

Comments
 (0)