|
13 | 13 | use MongoDB\Operation\Watch;
|
14 | 14 | use MongoDB\Tests\CommandObserver;
|
15 | 15 | use stdClass;
|
| 16 | +use ReflectionClass; |
16 | 17 |
|
17 | 18 | class WatchFunctionalTest extends FunctionalTestCase
|
18 | 19 | {
|
@@ -230,12 +231,31 @@ public function testNonEmptyPipeline()
|
230 | 231 | $this->assertSameDocument($expectedResult, $changeStream->current());
|
231 | 232 | }
|
232 | 233 |
|
233 |
| - public function testCursorWithEmptyBatchNotClosed() |
| 234 | + public function testInitialCursorIsNotClosed() |
234 | 235 | {
|
235 |
| - $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), [], ['maxAwaitTimeMS' => 100]); |
| 236 | + $operation = new Watch($this->manager, $this->getDatabaseName(), $this->getCollectionName(), []); |
236 | 237 | $changeStream = $operation->execute($this->getPrimaryServer());
|
237 | 238 |
|
238 |
| - $this->assertNotNull($changeStream); |
| 239 | + /* The spec requests that we assert that the cursor returned from the |
| 240 | + * aggregate command is not closed on the driver side. We will verify |
| 241 | + * this by checking that the cursor ID is non-zero and that libmongoc |
| 242 | + * reports the cursor as alive. While the cursor ID is easily accessed |
| 243 | + * through ChangeStream, we'll need to use reflection to access the |
| 244 | + * internal Cursor and call isDead(). */ |
| 245 | + $this->assertNotEquals('0', (string) $changeStream->getCursorId()); |
| 246 | + |
| 247 | + $rc = new ReflectionClass('MongoDB\ChangeStream'); |
| 248 | + $rp = $rc->getProperty('csIt'); |
| 249 | + $rp->setAccessible(true); |
| 250 | + |
| 251 | + $iterator = $rp->getValue($changeStream); |
| 252 | + |
| 253 | + $this->assertInstanceOf('IteratorIterator', $iterator); |
| 254 | + |
| 255 | + $cursor = $iterator->getInnerIterator(); |
| 256 | + |
| 257 | + $this->assertInstanceOf('MongoDB\Driver\Cursor', $cursor); |
| 258 | + $this->assertFalse($cursor->isDead()); |
239 | 259 | }
|
240 | 260 |
|
241 | 261 | /**
|
|
0 commit comments