Skip to content

Commit bdf1191

Browse files
committed
Extract factory to created decoded fixtures
1 parent 08f8761 commit bdf1191

8 files changed

+40
-33
lines changed

tests/Collection/CodecCollectionFunctionalTest.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public static function provideAggregateOptions(): Generator
3131
{
3232
yield 'Default codec' => [
3333
'expected' => [
34-
TestObject::createForFixture(2, true),
35-
TestObject::createForFixture(3, true),
34+
TestObject::createDecodedForFixture(2),
35+
TestObject::createDecodedForFixture(3),
3636
],
3737
'options' => [],
3838
];
@@ -77,15 +77,15 @@ public function testAggregateWithCodecAndTypemap(): void
7777

7878
public static function provideBulkWriteOptions(): Generator
7979
{
80-
$replacedObject = TestObject::createForFixture(3, true);
80+
$replacedObject = TestObject::createDecodedForFixture(3);
8181
$replacedObject->x->foo = 'baz';
8282

8383
yield 'Default codec' => [
8484
'expected' => [
85-
TestObject::createForFixture(1, true),
86-
TestObject::createForFixture(2, true),
85+
TestObject::createDecodedForFixture(1),
86+
TestObject::createDecodedForFixture(2),
8787
$replacedObject,
88-
TestObject::createForFixture(4, true),
88+
TestObject::createDecodedForFixture(4),
8989
],
9090
'options' => [],
9191
];
@@ -154,7 +154,7 @@ public function testBulkWrite($expected, $options): void
154154
public function provideFindOneAndModifyOptions(): Generator
155155
{
156156
yield 'Default codec' => [
157-
'expected' => TestObject::createForFixture(1, true),
157+
'expected' => TestObject::createDecodedForFixture(1),
158158
'options' => [],
159159
];
160160

@@ -213,7 +213,7 @@ public function testFindOneAndUpdateWithCodecAndTypemap(): void
213213

214214
public static function provideFindOneAndReplaceOptions(): Generator
215215
{
216-
$replacedObject = TestObject::createForFixture(1, true);
216+
$replacedObject = TestObject::createDecodedForFixture(1);
217217
$replacedObject->x->foo = 'baz';
218218

219219
yield 'Default codec' => [
@@ -267,9 +267,9 @@ public static function provideFindOptions(): Generator
267267
{
268268
yield 'Default codec' => [
269269
'expected' => [
270-
TestObject::createForFixture(1, true),
271-
TestObject::createForFixture(2, true),
272-
TestObject::createForFixture(3, true),
270+
TestObject::createDecodedForFixture(1),
271+
TestObject::createDecodedForFixture(2),
272+
TestObject::createDecodedForFixture(3),
273273
],
274274
'options' => [],
275275
];
@@ -317,7 +317,7 @@ public function testFindWithCodecAndTypemap(): void
317317
public static function provideFindOneOptions(): Generator
318318
{
319319
yield 'Default codec' => [
320-
'expected' => TestObject::createForFixture(1, true),
320+
'expected' => TestObject::createDecodedForFixture(1),
321321
'options' => [],
322322
];
323323

@@ -357,9 +357,9 @@ public static function provideInsertManyOptions(): Generator
357357
{
358358
yield 'Default codec' => [
359359
'expected' => [
360-
TestObject::createForFixture(1, true),
361-
TestObject::createForFixture(2, true),
362-
TestObject::createForFixture(3, true),
360+
TestObject::createDecodedForFixture(1),
361+
TestObject::createDecodedForFixture(2),
362+
TestObject::createDecodedForFixture(3),
363363
],
364364
'options' => [],
365365
];
@@ -413,7 +413,7 @@ public function testInsertMany($expected, $options): void
413413
public static function provideInsertOneOptions(): Generator
414414
{
415415
yield 'Default codec' => [
416-
'expected' => TestObject::createForFixture(1, true),
416+
'expected' => TestObject::createDecodedForFixture(1),
417417
'options' => [],
418418
];
419419

@@ -449,7 +449,7 @@ public function testInsertOne($expected, $options): void
449449

450450
public static function provideReplaceOneOptions(): Generator
451451
{
452-
$replacedObject = TestObject::createForFixture(1, true);
452+
$replacedObject = TestObject::createDecodedForFixture(1);
453453
$replacedObject->x->foo = 'baz';
454454

455455
yield 'Default codec' => [

tests/Fixtures/Document/TestObject.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,24 @@ final class TestObject
2323

2424
public TestNestedObject $x;
2525

26-
public bool $decoded;
26+
public bool $decoded = false;
2727

28-
public static function createForFixture(int $i, bool $decoded = false): self
28+
public static function createForFixture(int $id): self
2929
{
3030
$instance = new self();
31-
$instance->id = $i;
32-
$instance->decoded = $decoded;
31+
$instance->id = $id;
3332

3433
$instance->x = new TestNestedObject();
3534
$instance->x->foo = 'bar';
3635

3736
return $instance;
3837
}
38+
39+
public static function createDecodedForFixture(int $id): self
40+
{
41+
$instance = self::createForFixture($id);
42+
$instance->decoded = true;
43+
44+
return $instance;
45+
}
3946
}

tests/Operation/AggregateFunctionalTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ public function testCodecOption(): void
354354

355355
$this->assertEquals(
356356
[
357-
TestObject::createForFixture(2, true),
358-
TestObject::createForFixture(3, true),
357+
TestObject::createDecodedForFixture(2),
358+
TestObject::createDecodedForFixture(3),
359359
],
360360
$cursor->toArray(),
361361
);

tests/Operation/BulkWriteFunctionalTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,14 +479,14 @@ public function testCodecOption(): void
479479
$this->assertSame(1, $result->getMatchedCount());
480480
$this->assertSame(1, $result->getModifiedCount());
481481

482-
$replacedObject = TestObject::createForFixture(3, true);
482+
$replacedObject = TestObject::createDecodedForFixture(3);
483483
$replacedObject->x->foo = 'baz';
484484

485485
// Only read the last two documents as the other two don't fit our codec
486486
$this->assertEquals(
487487
[
488488
$replacedObject,
489-
TestObject::createForFixture(4, true),
489+
TestObject::createDecodedForFixture(4),
490490
],
491491
$this->collection->find(['_id' => ['$gte' => 3]], ['codec' => $codec])->toArray(),
492492
);

tests/Operation/FindAndModifyFunctionalTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ public function testFindOneAndDeleteWithCodec(): void
293293

294294
$result = $operation->execute($this->getPrimaryServer());
295295

296-
self::assertEquals(TestObject::createForFixture(1, true), $result);
296+
self::assertEquals(TestObject::createDecodedForFixture(1), $result);
297297
}
298298

299299
public function testFindOneAndUpdateWithCodec(): void
@@ -308,7 +308,7 @@ public function testFindOneAndUpdateWithCodec(): void
308308

309309
$result = $operation->execute($this->getPrimaryServer());
310310

311-
self::assertEquals(TestObject::createForFixture(1, true), $result);
311+
self::assertEquals(TestObject::createDecodedForFixture(1), $result);
312312
}
313313

314314
public function testFindOneAndReplaceWithCodec(): void
@@ -323,7 +323,7 @@ public function testFindOneAndReplaceWithCodec(): void
323323

324324
$result = $operation->execute($this->getPrimaryServer());
325325

326-
self::assertEquals(TestObject::createForFixture(1, true), $result);
326+
self::assertEquals(TestObject::createDecodedForFixture(1), $result);
327327
}
328328

329329
/**

tests/Operation/FindFunctionalTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,9 @@ public function testCodecOption(): void
209209

210210
$this->assertEquals(
211211
[
212-
TestObject::createForFixture(1, true),
213-
TestObject::createForFixture(2, true),
214-
TestObject::createForFixture(3, true),
212+
TestObject::createDecodedForFixture(1),
213+
TestObject::createDecodedForFixture(2),
214+
TestObject::createDecodedForFixture(3),
215215
],
216216
$cursor->toArray(),
217217
);

tests/Operation/FindOneAndReplaceFunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function (): void {
2828
);
2929

3030
$this->assertEquals(
31-
TestObject::createForFixture(1, true),
31+
TestObject::createDecodedForFixture(1),
3232
$operation->execute($this->getPrimaryServer()),
3333
);
3434
},

tests/Operation/FindOneFunctionalTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function testCodecOption(): void
4747
$operation = new FindOne($this->getDatabaseName(), $this->getCollectionName(), [], ['codec' => $codec]);
4848
$document = $operation->execute($this->getPrimaryServer());
4949

50-
$this->assertEquals(TestObject::createForFixture(1, true), $document);
50+
$this->assertEquals(TestObject::createDecodedForFixture(1), $document);
5151
}
5252

5353
/**

0 commit comments

Comments
 (0)