Skip to content

Commit

Permalink
scalar id support
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Bretterklieber committed May 7, 2021
1 parent aba6bcf commit 8883fb5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/Stk/MongoDB/Connector.php
Original file line number Diff line number Diff line change
Expand Up @@ -261,15 +261,15 @@ public function delete(ImmutableInterface $row): DeleteResult
/**
* delete a document by id
*
* @param string $id
* @param mixed $id
*
* @return DeleteResult
*/
public function deleteById(string $id): DeleteResult
public function deleteById($id): DeleteResult
{
$this->debug(__METHOD__ . ":$id");

return $this->_collection->deleteOne(['_id' => new ObjectId($id)]);
return $this->_collection->deleteOne(['_id' => is_string($id) ? new ObjectId($id) : $id]);
}

/**
Expand Down
11 changes: 11 additions & 0 deletions test/unit/Stk/MongoDB/ConntectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,17 @@ public function testDeleteById(): void
$this->connector->deleteById((string) $oid);
}

public function testDeleteByIntId(): void
{
$id = 99;

$this->collection->expects($this->once())
->method('deleteOne')
->with(['_id' => $id])
->willReturn($this->createMock(DeleteResult::class));
$this->connector->deleteById($id);
}

public function testDeleteMany(): void
{
$criteria = [
Expand Down

0 comments on commit 8883fb5

Please sign in to comment.