MongoGridFSCursorTest.php 1014 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace Alcaeus\MongoDbAdapter\Tests;
  3. class MongoGridFSCursorTest extends TestCase
  4. {
  5. public function testCursor()
  6. {
  7. $cursor = $this->getCursor();
  8. $array = iterator_to_array($cursor);
  9. $this->assertCount(2, $array);
  10. $this->assertArrayHasKey('One.txt', $array);
  11. $this->assertArrayHasKey('Two.txt', $array);
  12. $firstFile = $array['One.txt'];
  13. $this->assertInstanceOf('MongoGridFSFile', $firstFile);
  14. $this->assertArraySubset(['length' => 3, 'filename' => 'One.txt'], $firstFile->file);
  15. $secondFile = $array['Two.txt'];
  16. $this->assertInstanceOf('MongoGridFSFile', $secondFile);
  17. $this->assertArraySubset(['length' => 3, 'filename' => 'Two.txt'], $secondFile->file);
  18. }
  19. private function getCursor()
  20. {
  21. $gridFS = $this->getGridFS();
  22. $gridFS->storeBytes('One', ['filename' => 'One.txt']);
  23. $gridFS->storeBytes('Two', ['filename' => 'Two.txt']);
  24. return $gridFS->find();
  25. }
  26. }