MongoCommandCursorTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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' => 0,
  18. 'skip' => 0,
  19. 'flags' => 0,
  20. 'query' => [
  21. 'aggregate' => 'test',
  22. 'pipeline' => [
  23. [
  24. '$match' => ['foo' => 'bar']
  25. ]
  26. ],
  27. 'cursor' => new \stdClass(),
  28. ],
  29. 'fields' => null,
  30. 'started_iterating' => false,
  31. ];
  32. $info = $cursor->info();
  33. $this->assertEquals($expected, $info);
  34. // Ensure cursor started iterating
  35. $array = iterator_to_array($cursor);
  36. $expected['started_iterating'] = true;
  37. $expected += [
  38. 'id' => 0,
  39. 'at' => 0,
  40. 'numReturned' => 0,
  41. 'server' => 'localhost:27017;-;.;' . getmypid(),
  42. 'host' => 'localhost',
  43. 'port' => 27017,
  44. 'connection_type_desc' => 'STANDALONE',
  45. ];
  46. $this->assertArraySubset($expected, $cursor->info());
  47. $i = 0;
  48. foreach ($array as $key => $value) {
  49. $this->assertEquals($i, $key);
  50. $i++;
  51. }
  52. }
  53. }