Skip to content

Commit

Permalink
Return documents as objects from Collection findAndModify methods
Browse files Browse the repository at this point in the history
  • Loading branch information
jmikola committed Jun 18, 2015
1 parent 02e651c commit 3028dfd
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 20 deletions.
6 changes: 3 additions & 3 deletions src/Collection.php
Expand Up @@ -460,7 +460,7 @@ public function findOne(array $filter = array(), array $options = array())
* @see FindOneAndDelete::__construct() for supported options
* @param array|object $filter Query by which to filter documents
* @param array $options Command options
* @return array|null
* @return object|null
*/
public function findOneAndDelete($filter, array $options = array())
{
Expand All @@ -482,7 +482,7 @@ public function findOneAndDelete($filter, array $options = array())
* @param array|object $filter Query by which to filter documents
* @param array|object $replacement Replacement document
* @param array $options Command options
* @return array|null
* @return object|null
*/
public function findOneAndReplace($filter, $replacement, array $options = array())
{
Expand All @@ -504,7 +504,7 @@ public function findOneAndReplace($filter, $replacement, array $options = array(
* @param array|object $filter Query by which to filter documents
* @param array|object $update Update to apply to the matched document
* @param array $options Command options
* @return array|null
* @return object|null
*/
public function findOneAndUpdate($filter, $update, array $options = array())
{
Expand Down
4 changes: 2 additions & 2 deletions src/Operation/FindAndModify.php
Expand Up @@ -113,7 +113,7 @@ public function __construct($databaseName, $collectionName, array $options)
*
* @see Executable::execute()
* @param Server $server
* @return array|null
* @return object|null
*/
public function execute(Server $server)
{
Expand Down Expand Up @@ -143,7 +143,7 @@ public function execute(Server $server)
throw new UnexpectedValueException('findAndModify command did not return a "value" document');
}

return (array) $result['value'];
return $result['value'];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/FindOneAndDelete.php
Expand Up @@ -74,7 +74,7 @@ public function __construct($databaseName, $collectionName, $filter, array $opti
*
* @see Executable::execute()
* @param Server $server
* @return array|null
* @return object|null
*/
public function execute(Server $server)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/FindOneAndReplace.php
Expand Up @@ -113,7 +113,7 @@ public function __construct($databaseName, $collectionName, $filter, $replacemen
*
* @see Executable::execute()
* @param Server $server
* @return array|null
* @return object|null
*/
public function execute(Server $server)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/FindOneAndUpdate.php
Expand Up @@ -113,7 +113,7 @@ public function __construct($databaseName, $collectionName, $filter, $update, ar
*
* @see Executable::execute()
* @param Server $server
* @return array|null
* @return object|null
*/
public function execute(Server $server)
{
Expand Down
4 changes: 2 additions & 2 deletions tests/Collection/CrudSpec/FindOneAndDeleteFunctionalTest.php
Expand Up @@ -25,7 +25,7 @@ public function testFindOneAndDeleteWhenManyDocumentsMatch()
);

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

$expected = array(
array('_id' => 1, 'x' => 11),
Expand All @@ -44,7 +44,7 @@ public function testFindOneAndDeleteWhenOneDocumentMatches()
);

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

$expected = array(
array('_id' => 1, 'x' => 11),
Expand Down
10 changes: 5 additions & 5 deletions tests/Collection/CrudSpec/FindOneAndReplaceFunctionalTest.php
Expand Up @@ -29,7 +29,7 @@ public function testFindOneAndReplaceWhenManyDocumentsMatchReturningDocumentBefo
);

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

$expected = array(
array('_id' => 1, 'x' => 11),
Expand All @@ -51,7 +51,7 @@ public function testFindOneAndReplaceWhenManyDocumentsMatchReturningDocumentAfte
);

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

$expected = array(
array('_id' => 1, 'x' => 11),
Expand All @@ -72,7 +72,7 @@ public function testFindOneAndReplaceWhenOneDocumentMatchesReturningDocumentBefo
);

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

$expected = array(
array('_id' => 1, 'x' => 11),
Expand All @@ -94,7 +94,7 @@ public function testFindOneAndReplaceWhenOneDocumentMatchesReturningDocumentAfte
);

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

$expected = array(
array('_id' => 1, 'x' => 11),
Expand Down Expand Up @@ -185,7 +185,7 @@ public function testFindOneAndReplaceWithUpsertWhenNoDocumentsMatchReturningDocu
);

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

$expected = array(
array('_id' => 1, 'x' => 11),
Expand Down
10 changes: 5 additions & 5 deletions tests/Collection/CrudSpec/FindOneAndUpdateFunctionalTest.php
Expand Up @@ -29,7 +29,7 @@ public function testFindOneAndUpdateWhenManyDocumentsMatchReturningDocumentBefor
);

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

$expected = array(
array('_id' => 1, 'x' => 11),
Expand All @@ -51,7 +51,7 @@ public function testFindOneAndUpdateWhenManyDocumentsMatchReturningDocumentAfter
);

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

$expected = array(
array('_id' => 1, 'x' => 11),
Expand All @@ -72,7 +72,7 @@ public function testFindOneAndUpdateWhenOneDocumentMatchesReturningDocumentBefor
);

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

$expected = array(
array('_id' => 1, 'x' => 11),
Expand All @@ -94,7 +94,7 @@ public function testFindOneAndUpdateWhenOneDocumentMatchesReturningDocumentAfter
);

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

$expected = array(
array('_id' => 1, 'x' => 11),
Expand Down Expand Up @@ -183,7 +183,7 @@ public function testFindOneAndUpdateWithUpsertWhenNoDocumentsMatchReturningDocum
);

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

$expected = array(
array('_id' => 1, 'x' => 11),
Expand Down

0 comments on commit 3028dfd

Please sign in to comment.