1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
namespace MongoDB\Tests;
use MongoDB\Model\BSONArray;
use MongoDB\Model\BSONDocument;
class BSONArrayTest extends TestCase
{
public function testBsonSerializeReindexesKeys()
{
$data = [0 => 'foo', 2 => 'bar'];
$array = new BSONArray($data);
$this->assertSame($data, $array->getArrayCopy());
$this->assertSame(['foo', 'bar'], $array->bsonSerialize());
}
public function testJsonSerialize()
{
$document = new BSONArray([
'foo',
new BSONArray(['foo' => 1, 'bar' => 2, 'baz' => 3]),
new BSONDocument(['foo' => 1, 'bar' => 2, 'baz' => 3]),
new BSONArray([new BSONArray([new BSONArray])]),
]);
$expectedJson = '["foo",[1,2,3],{"foo":1,"bar":2,"baz":3},[[[]]]]';
$this->assertSame($expectedJson, json_encode($document));
}
public function testJsonSerializeReindexesKeys()
{
$data = [0 => 'foo', 2 => 'bar'];
$array = new BSONArray($data);
$this->assertSame($data, $array->getArrayCopy());
$this->assertSame(['foo', 'bar'], $array->jsonSerialize());
}
public function testSetState()
{
$data = ['foo', 'bar'];
$array = BSONArray::__set_state($data);
$this->assertInstanceOf('MongoDB\Model\BSONArray', $array);
$this->assertSame($data, $array->getArrayCopy());
}
}