Skip to content

Commit 5965b7e

Browse files
committed
Rename ChangeStream iterator variable in Watch test
1 parent 3c35cc9 commit 5965b7e

File tree

1 file changed

+63
-63
lines changed

1 file changed

+63
-63
lines changed

tests/Operation/WatchFunctionalTest.php

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -24,40 +24,40 @@ public function testResume()
2424
$this->assertInstanceOf('MongoDB\InsertOneResult', $result);
2525
$this->assertSame(1, $result->getInsertedCount());
2626

27-
$changeStreamResult = $this->collection->watch();
28-
$changeStreamResult->rewind();
29-
$this->assertNull($changeStreamResult->current());
27+
$changeStream = $this->collection->watch();
28+
$changeStream->rewind();
29+
$this->assertNull($changeStream->current());
3030

3131
$result = $this->collection->insertOne(['x' => 2]);
3232
$this->assertInstanceOf('MongoDB\InsertOneResult', $result);
3333
$this->assertSame(1, $result->getInsertedCount());
3434

35-
$changeStreamResult->next();
35+
$changeStream->next();
3636
$expectedResult = (object) ([
37-
'_id' => $changeStreamResult->current()->_id,
37+
'_id' => $changeStream->current()->_id,
3838
'operationType' => 'insert',
3939
'fullDocument' => (object) ['_id' => $result->getInsertedId(), 'x' => 2],
4040
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'WatchFunctionalTest.e68b9f01'],
4141
'documentKey' => (object) ['_id' => $result->getInsertedId()]
4242
]);
43-
$this->assertEquals($changeStreamResult->current(), $expectedResult);
43+
$this->assertEquals($changeStream->current(), $expectedResult);
4444

45-
$operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStreamResult->getCursorId()]]);
45+
$operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStream->getCursorId()]]);
4646
$operation->execute($this->getPrimaryServer());
4747

4848
$result = $this->collection->insertOne(['x' => 3]);
4949
$this->assertInstanceOf('MongoDB\InsertOneResult', $result);
5050
$this->assertSame(1, $result->getInsertedCount());
5151

52-
$changeStreamResult->next();
52+
$changeStream->next();
5353
$expectedResult = (object) ([
54-
'_id' => $changeStreamResult->current()->_id,
54+
'_id' => $changeStream->current()->_id,
5555
'operationType' => 'insert',
5656
'fullDocument' => (object) ['_id' => $result->getInsertedId(), 'x' => 3],
5757
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'WatchFunctionalTest.e68b9f01'],
5858
'documentKey' => (object) ['_id' => $result->getInsertedId()]
5959
]);
60-
$this->assertEquals($changeStreamResult->current(), $expectedResult);
60+
$this->assertEquals($changeStream->current(), $expectedResult);
6161
}
6262

6363
public function testNoChangeAfterResumeBeforeInsert()
@@ -68,134 +68,134 @@ public function testNoChangeAfterResumeBeforeInsert()
6868
$this->assertInstanceOf('MongoDB\InsertOneResult', $result);
6969
$this->assertSame(1, $result->getInsertedCount());
7070

71-
$changeStreamResult = $this->collection->watch();
72-
$changeStreamResult->rewind();
73-
$this->assertNull($changeStreamResult->current());
71+
$changeStream = $this->collection->watch();
72+
$changeStream->rewind();
73+
$this->assertNull($changeStream->current());
7474

7575
$result = $this->collection->insertOne(['x' => 2]);
7676
$this->assertInstanceOf('MongoDB\InsertOneResult', $result);
7777
$this->assertSame(1, $result->getInsertedCount());
7878

79-
$changeStreamResult->next();
79+
$changeStream->next();
8080
$expectedResult = (object) ([
81-
'_id' => $changeStreamResult->current()->_id,
81+
'_id' => $changeStream->current()->_id,
8282
'operationType' => 'insert',
8383
'fullDocument' => (object) ['_id' => $result->getInsertedId(), 'x' => 2],
8484
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'WatchFunctionalTest.4a554985'],
8585
'documentKey' => (object) ['_id' => $result->getInsertedId()]
8686
]);
87-
$this->assertEquals($changeStreamResult->current(), $expectedResult);
87+
$this->assertEquals($changeStream->current(), $expectedResult);
8888

89-
$operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStreamResult->getCursorId()]]);
89+
$operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStream->getCursorId()]]);
9090
$operation->execute($this->getPrimaryServer());
9191

92-
$changeStreamResult->next();
93-
$this->assertNull($changeStreamResult->current());
92+
$changeStream->next();
93+
$this->assertNull($changeStream->current());
9494

9595
$result = $this->collection->insertOne(['x' => 3]);
9696
$this->assertInstanceOf('MongoDB\InsertOneResult', $result);
9797
$this->assertSame(1, $result->getInsertedCount());
9898

99-
$changeStreamResult->next();
99+
$changeStream->next();
100100
$expectedResult = (object) ([
101-
'_id' => $changeStreamResult->current()->_id,
101+
'_id' => $changeStream->current()->_id,
102102
'operationType' => 'insert',
103103
'fullDocument' => (object) ['_id' => $result->getInsertedId(), 'x' => 3],
104104
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'WatchFunctionalTest.4a554985'],
105105
'documentKey' => (object) ['_id' => $result->getInsertedId()]
106106
]);
107-
$this->assertEquals($changeStreamResult->current(), $expectedResult);
107+
$this->assertEquals($changeStream->current(), $expectedResult);
108108
}
109109

110110
public function testResumeAfterKillThenNoOperations()
111111
{
112112
$this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName());
113113

114-
$changeStreamResult = $this->collection->watch();
114+
$changeStream = $this->collection->watch();
115115

116-
$operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStreamResult->getCursorId()]]);
116+
$operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStream->getCursorId()]]);
117117
$operation->execute($this->getPrimaryServer());
118118

119-
$changeStreamResult->next();
120-
$this->assertNull($changeStreamResult->current());
119+
$changeStream->next();
120+
$this->assertNull($changeStream->current());
121121
}
122122

123123
public function testResumeAfterKillThenOperation()
124124
{
125125
$this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName());
126126

127-
$changeStreamResult = $this->collection->watch();
127+
$changeStream = $this->collection->watch();
128128

129-
$operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStreamResult->getCursorId()]]);
129+
$operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStream->getCursorId()]]);
130130
$operation->execute($this->getPrimaryServer());
131131

132132
$result = $this->collection->insertOne(['x' => 3]);
133133
$this->assertInstanceOf('MongoDB\InsertOneResult', $result);
134134
$this->assertSame(1, $result->getInsertedCount());
135135

136-
$changeStreamResult->next();
137-
$this->assertNull($changeStreamResult->current());
136+
$changeStream->next();
137+
$this->assertNull($changeStream->current());
138138
}
139139

140140
public function testKey()
141141
{
142142
$this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName());
143143

144-
$changeStreamResult = $this->collection->watch();
144+
$changeStream = $this->collection->watch();
145145

146-
$this->assertNull($changeStreamResult->key());
146+
$this->assertNull($changeStream->key());
147147

148148
$result = $this->collection->insertOne(['x' => 1]);
149149
$this->assertInstanceOf('MongoDB\InsertOneResult', $result);
150150
$this->assertSame(1, $result->getInsertedCount());
151151

152-
$changeStreamResult->next();
153-
$this->assertSame(1, $changeStreamResult->key());
152+
$changeStream->next();
153+
$this->assertSame(1, $changeStream->key());
154154

155-
$changeStreamResult->next();
156-
$this->assertNull($changeStreamResult->key());
157-
$changeStreamResult->next();
158-
$this->assertNull($changeStreamResult->key());
155+
$changeStream->next();
156+
$this->assertNull($changeStream->key());
157+
$changeStream->next();
158+
$this->assertNull($changeStream->key());
159159

160-
$operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStreamResult->getCursorId()]]);
160+
$operation = new DatabaseCommand($this->getDatabaseName(), ["killCursors" => $this->getCollectionName(), "cursors" => [$changeStream->getCursorId()]]);
161161
$operation->execute($this->getPrimaryServer());
162162

163-
$changeStreamResult->next();
164-
$this->assertNull($changeStreamResult->key());
163+
$changeStream->next();
164+
$this->assertNull($changeStream->key());
165165

166166
$result = $this->collection->insertOne(['x' => 2]);
167167
$this->assertInstanceOf('MongoDB\InsertOneResult', $result);
168168
$this->assertSame(1, $result->getInsertedCount());
169169

170-
$changeStreamResult->next();
171-
$this->assertSame(2, $changeStreamResult->key());
170+
$changeStream->next();
171+
$this->assertSame(2, $changeStream->key());
172172
}
173173

174174
public function testNonEmptyPipeline()
175175
{
176176
$this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName());
177177

178178
$pipeline = [['$project' => ['foo' => [0]]]];
179-
$changeStreamResult = $this->collection->watch($pipeline, []);
179+
$changeStream = $this->collection->watch($pipeline, []);
180180

181181
$result = $this->collection->insertOne(['x' => 1]);
182182
$this->assertInstanceOf('MongoDB\InsertOneResult', $result);
183183
$this->assertSame(1, $result->getInsertedCount());
184184

185-
$changeStreamResult->next();
185+
$changeStream->next();
186186
$expectedResult = (object) ([
187-
'_id' => $changeStreamResult->current()->_id,
187+
'_id' => $changeStream->current()->_id,
188188
'foo' => [0]
189189
]);
190-
$this->assertEquals($changeStreamResult->current(), $expectedResult);
190+
$this->assertEquals($changeStream->current(), $expectedResult);
191191
}
192192

193193
public function testCursorWithEmptyBatchNotClosed()
194194
{
195195
$this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName());
196196

197-
$changeStreamResult = $this->collection->watch();
198-
$this->assertNotNull($changeStreamResult);
197+
$changeStream = $this->collection->watch();
198+
$this->assertNotNull($changeStream);
199199
}
200200

201201
/**
@@ -206,36 +206,36 @@ public function testFailureAfterResumeTokenRemoved()
206206
$this->collection = new Collection($this->manager, $this->getDatabaseName(), $this->getCollectionName());
207207

208208
$pipeline = [['$project' => ['_id' => 0 ]]];
209-
$changeStreamResult = $this->collection->watch($pipeline, []);
209+
$changeStream = $this->collection->watch($pipeline, []);
210210

211211
$result = $this->collection->insertOne(['x' => 1]);
212212
$this->assertInstanceOf('MongoDB\InsertOneResult', $result);
213213
$this->assertSame(1, $result->getInsertedCount());
214214

215-
$changeStreamResult->next();
215+
$changeStream->next();
216216
}
217217

218218
public function testConnectionException()
219219
{
220220
$client = new Client($this->getUri(), ['socketTimeoutMS' => 1005], []);
221221
$collection = $client->selectCollection($this->getDatabaseName(), $this->getCollectionName());
222222

223-
$changeStreamResult = $collection->watch();
224-
$changeStreamResult->next();
223+
$changeStream = $collection->watch();
224+
$changeStream->next();
225225

226226
$result = $collection->insertOne(['x' => 1]);
227227
$this->assertInstanceOf('MongoDB\InsertOneResult', $result);
228228
$this->assertSame(1, $result->getInsertedCount());
229229

230-
$changeStreamResult->next();
230+
$changeStream->next();
231231
$expectedResult = (object) ([
232-
'_id' => $changeStreamResult->current()->_id,
232+
'_id' => $changeStream->current()->_id,
233233
'operationType' => 'insert',
234234
'fullDocument' => (object) ['_id' => $result->getInsertedId(), 'x' => 1],
235235
'ns' => (object) ['db' => 'phplib_test', 'coll' => 'WatchFunctionalTest.226d95f1'],
236236
'documentKey' => (object) ['_id' => $result->getInsertedId()]
237237
]);
238-
$this->assertEquals($changeStreamResult->current(), $expectedResult);
238+
$this->assertEquals($changeStream->current(), $expectedResult);
239239
}
240240

241241
public function testMaxAwaitTimeMS()
@@ -245,30 +245,30 @@ public function testMaxAwaitTimeMS()
245245
* change stream on the server so we'll use a higher maxAwaitTimeMS to
246246
* ensure we see the write. */
247247
$maxAwaitTimeMS = 100;
248-
$changeStreamResult = $this->collection->watch([], ['maxAwaitTimeMS' => $maxAwaitTimeMS]);
248+
$changeStream = $this->collection->watch([], ['maxAwaitTimeMS' => $maxAwaitTimeMS]);
249249

250250
/* The initial change stream is empty so we should expect a delay when
251251
* we call rewind, since it issues a getMore. Expect to wait at least
252252
* maxAwaitTimeMS, since no new documents should be inserted to wake up
253253
* the server's query thread. Also ensure we don't wait too long (server
254254
* default is one second). */
255255
$startTime = microtime(true);
256-
$changeStreamResult->rewind();
256+
$changeStream->rewind();
257257
$duration = microtime(true) - $startTime;
258258
$this->assertGreaterThanOrEqual($maxAwaitTimeMS * 0.001, $duration);
259259
$this->assertLessThan(0.5, $duration);
260260

261-
$this->assertFalse($changeStreamResult->valid());
261+
$this->assertFalse($changeStream->valid());
262262

263263
/* Advancing again on a change stream will issue a getMore, so we should
264264
* expect a delay again. */
265265
$startTime = microtime(true);
266-
$changeStreamResult->next();
266+
$changeStream->next();
267267
$duration = microtime(true) - $startTime;
268268
$this->assertGreaterThanOrEqual($maxAwaitTimeMS * 0.001, $duration);
269269
$this->assertLessThan(0.5, $duration);
270270

271-
$this->assertFalse($changeStreamResult->valid());
271+
$this->assertFalse($changeStream->valid());
272272

273273
/* After inserting a document, the change stream will not issue a
274274
* getMore so we should not expect a delay. */
@@ -277,9 +277,9 @@ public function testMaxAwaitTimeMS()
277277
$this->assertSame(1, $result->getInsertedCount());
278278

279279
$startTime = microtime(true);
280-
$changeStreamResult->next();
280+
$changeStream->next();
281281
$duration = microtime(true) - $startTime;
282282
$this->assertLessThan($maxAwaitTimeMS * 0.001, $duration);
283-
$this->assertTrue($changeStreamResult->valid());
283+
$this->assertTrue($changeStream->valid());
284284
}
285285
}

0 commit comments

Comments
 (0)