MongoCommandCursorTest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace Alcaeus\MongoDbAdapter\Tests;
  3. use MongoDB\Driver\ReadPreference;
  4. use MongoDB\Operation\Find;
  5. /**
  6. * @author alcaeus <alcaeus@alcaeus.org>
  7. */
  8. class MongoCommandCursorTest extends TestCase
  9. {
  10. public function testInfo()
  11. {
  12. $this->prepareData();
  13. $cursor = $this->getCollection()->aggregateCursor([['$match' => ['foo' => 'bar']]]);
  14. $expected = [
  15. 'ns' => 'mongo-php-adapter.test',
  16. 'limit' => 0,
  17. 'batchSize' => null,
  18. 'skip' => 0,
  19. 'flags' => 0,
  20. 'query' => [
  21. 'aggregate' => 'test',
  22. 'pipeline' => [
  23. [
  24. '$match' => ['foo' => 'bar']
  25. ]
  26. ],
  27. 'cursor' => true,
  28. ],
  29. 'fields' => null,
  30. 'started_iterating' => false,
  31. ];
  32. $this->assertEquals($expected, $cursor->info());
  33. // Ensure cursor started iterating
  34. iterator_to_array($cursor);
  35. $expected['started_iterating'] = true;
  36. $expected += [
  37. 'id' => '0',
  38. 'at' => null,
  39. 'numReturned' => null,
  40. 'server' => null,
  41. 'host' => 'localhost',
  42. 'port' => 27017,
  43. 'connection_type_desc' => 'STANDALONE'
  44. ];
  45. $this->assertEquals($expected, $cursor->info());
  46. }
  47. }