Skip to content

Commit 9036b03

Browse files
committed
Extract default options in Watch tests to class property
1 parent 899b43c commit 9036b03

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

tests/Operation/WatchFunctionalTest.php

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

1818
class WatchFunctionalTest extends FunctionalTestCase
1919
{
20+
private $defaultOptions = ['maxAwaitTimeMS' => 100];
21+
2022
public function setUp()
2123
{
2224
parent::setUp();
@@ -34,7 +36,7 @@ public function testNextResumesAfterCursorNotFound()
3436
{
3537
$this->insertDocument(['_id' => 1, 'x' => 'foo']);
3638

37-
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], ['maxAwaitTimeMS' => 100]);
39+
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions);
3840
$changeStream = $operation->execute($this->getPrimaryServer());
3941

4042
$changeStream->rewind();
@@ -81,7 +83,7 @@ public function testNextResumesAfterConnectionException()
8183
$manager = new Manager($this->getUri(), ['socketTimeoutMS' => 50]);
8284
$primaryServer = $manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
8385

84-
$operation = new Watch($manager, $this->getDatabaseName(), $this->getCollectionName(), [], ['maxAwaitTimeMS' => 100]);
86+
$operation = new Watch($manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions);
8587
$changeStream = $operation->execute($primaryServer);
8688

8789
/* Note: we intentionally do not start iteration with rewind() to ensure
@@ -134,7 +136,7 @@ public function testRewindResumesAfterConnectionException()
134136
$manager = new Manager($this->getUri(), ['socketTimeoutMS' => 50]);
135137
$primaryServer = $manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
136138

137-
$operation = new Watch($manager, $this->getDatabaseName(), $this->getCollectionName(), [], ['maxAwaitTimeMS' => 100]);
139+
$operation = new Watch($manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions);
138140
$changeStream = $operation->execute($primaryServer);
139141

140142
$commands = [];
@@ -180,7 +182,7 @@ public function testNoChangeAfterResumeBeforeInsert()
180182
{
181183
$this->insertDocument(['_id' => 1, 'x' => 'foo']);
182184

183-
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], ['maxAwaitTimeMS' => 100]);
185+
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions);
184186
$changeStream = $operation->execute($this->getPrimaryServer());
185187

186188
$changeStream->rewind();
@@ -225,7 +227,7 @@ public function testNoChangeAfterResumeBeforeInsert()
225227

226228
public function testKey()
227229
{
228-
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], ['maxAwaitTimeMS' => 100]);
230+
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions);
229231
$changeStream = $operation->execute($this->getPrimaryServer());
230232

231233
$this->assertFalse($changeStream->valid());
@@ -262,7 +264,7 @@ public function testNonEmptyPipeline()
262264
{
263265
$pipeline = [['$project' => ['foo' => [0]]]];
264266

265-
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, ['maxAwaitTimeMS' => 100]);
267+
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, $this->defaultOptions);
266268
$changeStream = $operation->execute($this->getPrimaryServer());
267269

268270
$this->insertDocument(['_id' => 1]);
@@ -313,7 +315,7 @@ public function testNextResumeTokenNotFound()
313315
{
314316
$pipeline = [['$project' => ['_id' => 0 ]]];
315317

316-
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, ['maxAwaitTimeMS' => 100]);
318+
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, $this->defaultOptions);
317319
$changeStream = $operation->execute($this->getPrimaryServer());
318320

319321
/* Note: we intentionally do not start iteration with rewind() to ensure
@@ -331,7 +333,7 @@ public function testRewindResumeTokenNotFound()
331333
{
332334
$pipeline = [['$project' => ['_id' => 0 ]]];
333335

334-
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, ['maxAwaitTimeMS' => 100]);
336+
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, $this->defaultOptions);
335337
$changeStream = $operation->execute($this->getPrimaryServer());
336338

337339
$this->insertDocument(['x' => 1]);
@@ -347,7 +349,7 @@ public function testNextResumeTokenInvalidType()
347349
{
348350
$pipeline = [['$project' => ['_id' => ['$literal' => 'foo']]]];
349351

350-
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, ['maxAwaitTimeMS' => 100]);
352+
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, $this->defaultOptions);
351353
$changeStream = $operation->execute($this->getPrimaryServer());
352354

353355
/* Note: we intentionally do not start iteration with rewind() to ensure
@@ -365,7 +367,7 @@ public function testRewindResumeTokenInvalidType()
365367
{
366368
$pipeline = [['$project' => ['_id' => ['$literal' => 'foo']]]];
367369

368-
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, ['maxAwaitTimeMS' => 100]);
370+
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), $pipeline, $this->defaultOptions);
369371
$changeStream = $operation->execute($this->getPrimaryServer());
370372

371373
$this->insertDocument(['x' => 1]);
@@ -424,7 +426,7 @@ public function testMaxAwaitTimeMS()
424426

425427
public function testRewindResumesAfterCursorNotFound()
426428
{
427-
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], ['maxAwaitTimeMS' => 100]);
429+
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions);
428430
$changeStream = $operation->execute($this->getPrimaryServer());
429431

430432
$this->killChangeStreamCursor($changeStream);
@@ -436,7 +438,7 @@ public function testRewindResumesAfterCursorNotFound()
436438

437439
public function testRewindExtractsResumeTokenAndNextResumes()
438440
{
439-
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], ['maxAwaitTimeMS' => 100]);
441+
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], $this->defaultOptions);
440442
$changeStream = $operation->execute($this->getPrimaryServer());
441443

442444
$this->insertDocument(['_id' => 1, 'x' => 'foo']);
@@ -473,7 +475,7 @@ public function testRewindExtractsResumeTokenAndNextResumes()
473475
*/
474476
public function testTypeMapOption(array $typeMap, $expectedChangeDocument)
475477
{
476-
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], ['maxAwaitTimeMS' => 100, 'typeMap' => $typeMap]);
478+
$operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], ['typeMap' => $typeMap] + $this->defaultOptions);
477479
$changeStream = $operation->execute($this->getPrimaryServer());
478480

479481
$changeStream->rewind();

0 commit comments

Comments
 (0)