Skip to content

Commit

Permalink
Insert fixture through factory in test object
Browse files Browse the repository at this point in the history
  • Loading branch information
alcaeus committed Jul 31, 2023
1 parent 48889a9 commit 82a68e8
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 24 deletions.
5 changes: 1 addition & 4 deletions tests/Collection/CodecCollectionFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,10 +505,7 @@ private function createFixtures(int $n, array $executeBulkWriteOptions = []): vo
$bulkWrite = new BulkWrite(['ordered' => true]);

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

$result = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite, $executeBulkWriteOptions);
Expand Down
10 changes: 10 additions & 0 deletions tests/Fixtures/Document/TestObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

namespace MongoDB\Tests\Fixtures\Document;

use MongoDB\BSON\Document;

final class TestObject
{
public int $id;
Expand All @@ -25,6 +27,14 @@ final class TestObject

public bool $decoded = false;

public static function createDocument(int $id): Document
{
return Document::fromPHP([
'_id' => $id,
'x' => ['foo' => 'bar'],
]);
}

public static function createForFixture(int $id): self
{
$instance = new self();
Expand Down
5 changes: 1 addition & 4 deletions tests/Operation/AggregateFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,7 @@ private function createFixtures(int $n, array $executeBulkWriteOptions = []): vo
$bulkWrite = new BulkWrite(['ordered' => true]);

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

$result = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite, $executeBulkWriteOptions);
Expand Down
5 changes: 1 addition & 4 deletions tests/Operation/FindAndModifyFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,10 +334,7 @@ private function createFixtures(int $n): void
$bulkWrite = new BulkWrite(['ordered' => true]);

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

$result = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite);
Expand Down
5 changes: 1 addition & 4 deletions tests/Operation/FindFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,7 @@ private function createFixtures(int $n, array $executeBulkWriteOptions = []): vo
$bulkWrite = new BulkWrite(['ordered' => true]);

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

$result = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite, $executeBulkWriteOptions);
Expand Down
5 changes: 1 addition & 4 deletions tests/Operation/FindOneAndReplaceFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,7 @@ private function createFixtures(int $n): void
$bulkWrite = new BulkWrite(['ordered' => true]);

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

$result = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite);
Expand Down
5 changes: 1 addition & 4 deletions tests/Operation/FindOneFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ private function createFixtures(int $n): void
$bulkWrite = new BulkWrite(['ordered' => true]);

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

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

0 comments on commit 82a68e8

Please sign in to comment.