Skip to content

Commit 2e8d013

Browse files
committed
Return documents as objects from Collection findAndModify methods
1 parent ee4369b commit 2e8d013

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
@@ -28,7 +28,7 @@ public function testFindOneAndReplaceWhenManyDocumentsMatchReturningDocumentBefo
2828
);
2929

3030
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
31-
$this->assertSame(array('x' => 22), $document);
31+
$this->assertEquals((object) array('x' => 22), $document);
3232

3333
$expected = array(
3434
array('_id' => 1, 'x' => 11),
@@ -50,7 +50,7 @@ public function testFindOneAndReplaceWhenManyDocumentsMatchReturningDocumentAfte
5050
);
5151

5252
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
53-
$this->assertSame(array('x' => 32), $document);
53+
$this->assertEquals((object) array('x' => 32), $document);
5454

5555
$expected = array(
5656
array('_id' => 1, 'x' => 11),
@@ -71,7 +71,7 @@ public function testFindOneAndReplaceWhenOneDocumentMatchesReturningDocumentBefo
7171
);
7272

7373
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
74-
$this->assertSame(array('x' => 22), $document);
74+
$this->assertEquals((object) array('x' => 22), $document);
7575

7676
$expected = array(
7777
array('_id' => 1, 'x' => 11),
@@ -93,7 +93,7 @@ public function testFindOneAndReplaceWhenOneDocumentMatchesReturningDocumentAfte
9393
);
9494

9595
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
96-
$this->assertSame(array('x' => 32), $document);
96+
$this->assertEquals((object) array('x' => 32), $document);
9797

9898
$expected = array(
9999
array('_id' => 1, 'x' => 11),
@@ -184,7 +184,7 @@ public function testFindOneAndReplaceWithUpsertWhenNoDocumentsMatchReturningDocu
184184
);
185185

186186
$document = $this->collection->findOneAndReplace($filter, $replacement, $options);
187-
$this->assertSame(array('x' => 44), $document);
187+
$this->assertEquals((object) array('x' => 44), $document);
188188

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

tests/Collection/CrudSpec/FindOneAndUpdateFunctionalTest.php

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

3030
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
31-
$this->assertSame(array('x' => 22), $document);
31+
$this->assertEquals((object) array('x' => 22), $document);
3232

3333
$expected = array(
3434
array('_id' => 1, 'x' => 11),
@@ -50,7 +50,7 @@ public function testFindOneAndUpdateWhenManyDocumentsMatchReturningDocumentAfter
5050
);
5151

5252
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
53-
$this->assertSame(array('x' => 23), $document);
53+
$this->assertEquals((object) array('x' => 23), $document);
5454

5555
$expected = array(
5656
array('_id' => 1, 'x' => 11),
@@ -71,7 +71,7 @@ public function testFindOneAndUpdateWhenOneDocumentMatchesReturningDocumentBefor
7171
);
7272

7373
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
74-
$this->assertSame(array('x' => 22), $document);
74+
$this->assertEquals((object) array('x' => 22), $document);
7575

7676
$expected = array(
7777
array('_id' => 1, 'x' => 11),
@@ -93,7 +93,7 @@ public function testFindOneAndUpdateWhenOneDocumentMatchesReturningDocumentAfter
9393
);
9494

9595
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
96-
$this->assertSame(array('x' => 23), $document);
96+
$this->assertEquals((object) array('x' => 23), $document);
9797

9898
$expected = array(
9999
array('_id' => 1, 'x' => 11),
@@ -182,7 +182,7 @@ public function testFindOneAndUpdateWithUpsertWhenNoDocumentsMatchReturningDocum
182182
);
183183

184184
$document = $this->collection->findOneAndUpdate($filter, $update, $options);
185-
$this->assertSame(array('x' => 1), $document);
185+
$this->assertEquals((object) array('x' => 1), $document);
186186

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

0 commit comments

Comments
 (0)