Skip to content

Commit

Permalink
Add explanatory comment for ID filling behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Aug 16, 2023
1 parent 2ac2b53 commit 325165a
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/Collection/CodecCollectionFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,8 @@ public function testInsertMany($expected, $options): void
$result = $this->collection->insertMany($documents, $options);
$this->assertSame(3, $result->getInsertedCount());

// Add missing identifiers. This is relevant for the "No codec" data set, as the encoded document will not have
// an "_id" field and the driver will automatically generate one.
foreach ($expected as $index => &$expectedDocument) {
if ($expectedDocument instanceof BSONDocument && $expectedDocument->_id === null) {
$expectedDocument->_id = $result->getInsertedIds()[$index];
Expand Down Expand Up @@ -434,6 +436,8 @@ public function testInsertOne($expected, $options): void
$result = $this->collection->insertOne(TestObject::createForFixture(1), $options);
$this->assertSame(1, $result->getInsertedCount());

// Add missing identifiers. This is relevant for the "No codec" data set, as the encoded document will not have
// an "_id" field and the driver will automatically generate one.
if ($expected instanceof BSONDocument && $expected->_id === null) {
$expected->_id = $result->getInsertedId();
}
Expand Down

0 comments on commit 325165a

Please sign in to comment.