Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
35aa9509
Commit
35aa9509
authored
Jan 18, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #94
parents
54b9605b
f0826b23
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
1 deletion
+56
-1
BSONDocument.php
src/Model/BSONDocument.php
+14
-1
BSONArrayTest.php
tests/Model/BSONArrayTest.php
+17
-0
BSONDocumentTest.php
tests/Model/BSONDocumentTest.php
+25
-0
No files found.
src/Model/BSONDocument.php
View file @
35aa9509
...
...
@@ -16,6 +16,19 @@ use ArrayObject;
*/
class
BSONDocument
extends
ArrayObject
implements
Serializable
,
Unserializable
{
/**
* Constructor.
*
* This overrides the parent constructor to allow property access of entries
* by default.
*
* @see http://php.net/arrayobject.construct
*/
public
function
__construct
(
$input
=
[],
$flags
=
ArrayObject
::
ARRAY_AS_PROPS
,
$iterator_class
=
'ArrayIterator'
)
{
parent
::
__construct
(
$input
,
$flags
,
$iterator_class
);
}
/**
* Serialize the document to BSON.
*
...
...
@@ -35,6 +48,6 @@ class BSONDocument extends ArrayObject implements Serializable, Unserializable
*/
public
function
bsonUnserialize
(
array
$data
)
{
self
::
__construct
(
$data
,
ArrayObject
::
ARRAY_AS_PROPS
);
parent
::
__construct
(
$data
,
ArrayObject
::
ARRAY_AS_PROPS
);
}
}
tests/Model/BSONArrayTest.php
0 → 100644
View file @
35aa9509
<?php
namespace
MongoDB\Tests
;
use
MongoDB\Model\BSONArray
;
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
());
}
}
tests/Model/BSONDocumentTest.php
0 → 100644
View file @
35aa9509
<?php
namespace
MongoDB\Tests
;
use
MongoDB\Model\BSONDocument
;
use
ArrayObject
;
class
BSONDocumentTest
extends
TestCase
{
public
function
testConstructorDefaultsToPropertyAccess
()
{
$document
=
new
BSONDocument
([
'foo'
=>
'bar'
]);
$this
->
assertEquals
(
ArrayObject
::
ARRAY_AS_PROPS
,
$document
->
getFlags
());
$this
->
assertSame
(
'bar'
,
$document
->
foo
);
}
public
function
testBsonSerializeCastsToObject
()
{
$data
=
[
0
=>
'foo'
,
2
=>
'bar'
];
$document
=
new
BSONDocument
(
$data
);
$this
->
assertSame
(
$data
,
$document
->
getArrayCopy
());
$this
->
assertEquals
((
object
)
[
0
=>
'foo'
,
2
=>
'bar'
],
$document
->
bsonSerialize
());
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment