Skip to content

Commit 1933e89

Browse files
committed
Tests for BSON array and document serialize methods
1 parent 54b9605 commit 1933e89

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

tests/Model/BSONArrayTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace MongoDB\Tests;
4+
5+
use MongoDB\Model\BSONArray;
6+
7+
class BSONArrayTest extends TestCase
8+
{
9+
public function testBsonSerializeReindexesKeys()
10+
{
11+
$data = [0 => 'foo', 2 => 'bar'];
12+
13+
$array = new BSONArray($data);
14+
$this->assertSame($data, $array->getArrayCopy());
15+
$this->assertSame(['foo', 'bar'], $array->bsonSerialize());
16+
}
17+
}

tests/Model/BSONDocumentTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace MongoDB\Tests;
4+
5+
use MongoDB\Model\BSONDocument;
6+
use ArrayObject;
7+
8+
class BSONDocumentTest extends TestCase
9+
{
10+
public function testBsonSerializeCastsToObject()
11+
{
12+
$data = [0 => 'foo', 2 => 'bar'];
13+
14+
$document = new BSONDocument($data);
15+
$this->assertSame($data, $document->getArrayCopy());
16+
$this->assertEquals((object) [0 => 'foo', 2 => 'bar'], $document->bsonSerialize());
17+
}
18+
}

0 commit comments

Comments
 (0)