Skip to content

Commit 3028dfd

Browse files
committed
Return documents as objects from Collection findAndModify methods
1 parent 02e651c commit 3028dfd

8 files changed

+20
-20
lines changed

src/Collection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ public function findOne(array $filter = array(), array $options = array())
460460
* @see FindOneAndDelete::__construct() for supported options
461461
* @param array|object $filter Query by which to filter documents
462462
* @param array $options Command options
463-
* @return array|null
463+
* @return object|null
464464
*/
465465
public function findOneAndDelete($filter, array $options = array())
466466
{
@@ -482,7 +482,7 @@ public function findOneAndDelete($filter, array $options = array())
482482
* @param array|object $filter Query by which to filter documents
483483
* @param array|object $replacement Replacement document
484484
* @param array $options Command options
485-
* @return array|null
485+
* @return object|null
486486
*/
487487
public function findOneAndReplace($filter, $replacement, array $options = array())
488488
{
@@ -504,7 +504,7 @@ public function findOneAndReplace($filter, $replacement, array $options = array(
504504
* @param array|object $filter Query by which to filter documents
505505
* @param array|object $update Update to apply to the matched document
506506
* @param array $options Command options
507-
* @return array|null
507+
* @return object|null
508508
*/
509509
public function findOneAndUpdate($filter, $update, array $options = array())
510510
{

src/Operation/FindAndModify.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function __construct($databaseName, $collectionName, array $options)
113113
*
114114
* @see Executable::execute()
115115
* @param Server $server
116-
* @return array|null
116+
* @return object|null
117117
*/
118118
public function execute(Server $server)
119119
{
@@ -143,7 +143,7 @@ public function execute(Server $server)
143143
throw new UnexpectedValueException('findAndModify command did not return a "value" document');
144144
}
145145

146-
return (array) $result['value'];
146+
return $result['value'];
147147
}
148148

149149
/**

src/Operation/FindOneAndDelete.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function __construct($databaseName, $collectionName, $filter, array $opti
7474
*
7575
* @see Executable::execute()
7676
* @param Server $server
77-
* @return array|null
77+
* @return object|null
7878
*/
7979
public function execute(Server $server)
8080
{

src/Operation/FindOneAndReplace.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function __construct($databaseName, $collectionName, $filter, $replacemen
113113
*
114114
* @see Executable::execute()
115115
* @param Server $server
116-
* @return array|null
116+
* @return object|null
117117
*/
118118
public function execute(Server $server)
119119
{

src/Operation/FindOneAndUpdate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public function __construct($databaseName, $collectionName, $filter, $update, ar
113113
*
114114
* @see Executable::execute()
115115
* @param Server $server
116-
* @return array|null
116+
* @return object|null
117117
*/
118118
public function execute(Server $server)
119119
{

tests/Collection/CrudSpec/FindOneAndDeleteFunctionalTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function testFindOneAndDeleteWhenManyDocumentsMatch()
2525
);
2626

2727
$document = $this->collection->findOneAndDelete($filter, $options);
28-
$this->assertSame(array('x' => 22), $document);
28+
$this->assertEquals((object) array('x' => 22), $document);
2929

3030
$expected = array(
3131
array('_id' => 1, 'x' => 11),
@@ -44,7 +44,7 @@ public function testFindOneAndDeleteWhenOneDocumentMatches()
4444
);
4545

4646
$document = $this->collection->findOneAndDelete($filter, $options);
47-
$this->assertSame(array('x' => 22), $document);
47+
$this->assertEquals((object) array('x' => 22), $document);
4848

4949
$expected = array(
5050
array('_id' => 1, 'x' => 11),

tests/Collection/CrudSpec/FindOneAndReplaceFunctionalTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testFindOneAndReplaceWhenManyDocumentsMatchReturningDocumentBefo
2929
);
3030

3131
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
32-
$this->assertSame(array('x' => 22), $document);
32+
$this->assertEquals((object) array('x' => 22), $document);
3333

3434
$expected = array(
3535
array('_id' => 1, 'x' => 11),
@@ -51,7 +51,7 @@ public function testFindOneAndReplaceWhenManyDocumentsMatchReturningDocumentAfte
5151
);
5252

5353
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
54-
$this->assertSame(array('x' => 32), $document);
54+
$this->assertEquals((object) array('x' => 32), $document);
5555

5656
$expected = array(
5757
array('_id' => 1, 'x' => 11),
@@ -72,7 +72,7 @@ public function testFindOneAndReplaceWhenOneDocumentMatchesReturningDocumentBefo
7272
);
7373

7474
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
75-
$this->assertSame(array('x' => 22), $document);
75+
$this->assertEquals((object) array('x' => 22), $document);
7676

7777
$expected = array(
7878
array('_id' => 1, 'x' => 11),
@@ -94,7 +94,7 @@ public function testFindOneAndReplaceWhenOneDocumentMatchesReturningDocumentAfte
9494
);
9595

9696
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
97-
$this->assertSame(array('x' => 32), $document);
97+
$this->assertEquals((object) array('x' => 32), $document);
9898

9999
$expected = array(
100100
array('_id' => 1, 'x' => 11),
@@ -185,7 +185,7 @@ public function testFindOneAndReplaceWithUpsertWhenNoDocumentsMatchReturningDocu
185185
);
186186

187187
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
188-
$this->assertSame(array('x' => 44), $document);
188+
$this->assertEquals((object) array('x' => 44), $document);
189189

190190
$expected = array(
191191
array('_id' => 1, 'x' => 11),

tests/Collection/CrudSpec/FindOneAndUpdateFunctionalTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function testFindOneAndUpdateWhenManyDocumentsMatchReturningDocumentBefor
2929
);
3030

3131
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
32-
$this->assertSame(array('x' => 22), $document);
32+
$this->assertEquals((object) array('x' => 22), $document);
3333

3434
$expected = array(
3535
array('_id' => 1, 'x' => 11),
@@ -51,7 +51,7 @@ public function testFindOneAndUpdateWhenManyDocumentsMatchReturningDocumentAfter
5151
);
5252

5353
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
54-
$this->assertSame(array('x' => 23), $document);
54+
$this->assertEquals((object) array('x' => 23), $document);
5555

5656
$expected = array(
5757
array('_id' => 1, 'x' => 11),
@@ -72,7 +72,7 @@ public function testFindOneAndUpdateWhenOneDocumentMatchesReturningDocumentBefor
7272
);
7373

7474
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
75-
$this->assertSame(array('x' => 22), $document);
75+
$this->assertEquals((object) array('x' => 22), $document);
7676

7777
$expected = array(
7878
array('_id' => 1, 'x' => 11),
@@ -94,7 +94,7 @@ public function testFindOneAndUpdateWhenOneDocumentMatchesReturningDocumentAfter
9494
);
9595

9696
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
97-
$this->assertSame(array('x' => 23), $document);
97+
$this->assertEquals((object) array('x' => 23), $document);
9898

9999
$expected = array(
100100
array('_id' => 1, 'x' => 11),
@@ -183,7 +183,7 @@ public function testFindOneAndUpdateWithUpsertWhenNoDocumentsMatchReturningDocum
183183
);
184184

185185
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
186-
$this->assertSame(array('x' => 1), $document);
186+
$this->assertEquals((object) array('x' => 1), $document);
187187

188188
$expected = array(
189189
array('_id' => 1, 'x' => 11),

0 commit comments

Comments
 (0)