Skip to content

Commit 82a68e8

Browse files
committed
Insert fixture through factory in test object
1 parent 48889a9 commit 82a68e8

File tree

7 files changed

+16
-24
lines changed

7 files changed

+16
-24
lines changed

tests/Collection/CodecCollectionFunctionalTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -505,10 +505,7 @@ private function createFixtures(int $n, array $executeBulkWriteOptions = []): vo
505505
$bulkWrite = new BulkWrite(['ordered' => true]);
506506

507507
for ($i = 1; $i <= $n; $i++) {
508-
$bulkWrite->insert([
509-
'_id' => $i,
510-
'x' => (object) ['foo' => 'bar'],
511-
]);
508+
$bulkWrite->insert(TestObject::createDocument($i));
512509
}
513510

514511
$result = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite, $executeBulkWriteOptions);

tests/Fixtures/Document/TestObject.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
namespace MongoDB\Tests\Fixtures\Document;
1919

20+
use MongoDB\BSON\Document;
21+
2022
final class TestObject
2123
{
2224
public int $id;
@@ -25,6 +27,14 @@ final class TestObject
2527

2628
public bool $decoded = false;
2729

30+
public static function createDocument(int $id): Document
31+
{
32+
return Document::fromPHP([
33+
'_id' => $id,
34+
'x' => ['foo' => 'bar'],
35+
]);
36+
}
37+
2838
public static function createForFixture(int $id): self
2939
{
3040
$instance = new self();

tests/Operation/AggregateFunctionalTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -369,10 +369,7 @@ private function createFixtures(int $n, array $executeBulkWriteOptions = []): vo
369369
$bulkWrite = new BulkWrite(['ordered' => true]);
370370

371371
for ($i = 1; $i <= $n; $i++) {
372-
$bulkWrite->insert([
373-
'_id' => $i,
374-
'x' => (object) ['foo' => 'bar'],
375-
]);
372+
$bulkWrite->insert(TestObject::createDocument($i));
376373
}
377374

378375
$result = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite, $executeBulkWriteOptions);

tests/Operation/FindAndModifyFunctionalTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -334,10 +334,7 @@ private function createFixtures(int $n): void
334334
$bulkWrite = new BulkWrite(['ordered' => true]);
335335

336336
for ($i = 1; $i <= $n; $i++) {
337-
$bulkWrite->insert([
338-
'_id' => $i,
339-
'x' => (object) ['foo' => 'bar'],
340-
]);
337+
$bulkWrite->insert(TestObject::createDocument($i));
341338
}
342339

343340
$result = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite);

tests/Operation/FindFunctionalTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,10 +323,7 @@ private function createFixtures(int $n, array $executeBulkWriteOptions = []): vo
323323
$bulkWrite = new BulkWrite(['ordered' => true]);
324324

325325
for ($i = 1; $i <= $n; $i++) {
326-
$bulkWrite->insert([
327-
'_id' => $i,
328-
'x' => (object) ['foo' => 'bar'],
329-
]);
326+
$bulkWrite->insert(TestObject::createDocument($i));
330327
}
331328

332329
$result = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite, $executeBulkWriteOptions);

tests/Operation/FindOneAndReplaceFunctionalTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ private function createFixtures(int $n): void
5353
$bulkWrite = new BulkWrite(['ordered' => true]);
5454

5555
for ($i = 1; $i <= $n; $i++) {
56-
$bulkWrite->insert([
57-
'_id' => $i,
58-
'x' => (object) ['foo' => 'bar'],
59-
]);
56+
$bulkWrite->insert(TestObject::createDocument($i));
6057
}
6158

6259
$result = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite);

tests/Operation/FindOneFunctionalTest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,7 @@ private function createFixtures(int $n): void
5858
$bulkWrite = new BulkWrite(['ordered' => true]);
5959

6060
for ($i = 1; $i <= $n; $i++) {
61-
$bulkWrite->insert([
62-
'_id' => $i,
63-
'x' => (object) ['foo' => 'bar'],
64-
]);
61+
$bulkWrite->insert(TestObject::createDocument($i));
6562
}
6663

6764
$result = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite);

0 commit comments

Comments
 (0)