MongoGridFSCursorTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace Alcaeus\MongoDbAdapter\Tests\Mongo;
  3. use Alcaeus\MongoDbAdapter\Tests\TestCase;
  4. class MongoGridFSCursorTest extends TestCase
  5. {
  6. public function testSerialize()
  7. {
  8. $gridfs = $this->getGridFS();
  9. $gridfs->storeBytes('foo', ['filename' => 'foo.txt']);
  10. $gridfs->storeBytes('bar', ['filename' => 'bar.txt']);
  11. $cursor = $gridfs->find(['filename' => 'foo.txt']);
  12. $this->assertInternalType('string', serialize($cursor));
  13. }
  14. public function testCursorItems()
  15. {
  16. $gridfs = $this->getGridFS();
  17. $id = $gridfs->storeBytes('foo', ['filename' => 'foo.txt']);
  18. $gridfs->storeBytes('bar', ['filename' => 'bar.txt']);
  19. $cursor = $gridfs->find(['filename' => 'foo.txt']);
  20. $this->assertCount(1, $cursor);
  21. foreach ($cursor as $key => $value) {
  22. $this->assertSame((string)$id, $key);
  23. $this->assertInstanceOf('MongoGridFSFile', $value);
  24. $this->assertSame('foo', $value->getBytes());
  25. $this->assertArraySubset([
  26. 'filename' => 'foo.txt',
  27. 'chunkSize' => 261120,
  28. 'length' => 3,
  29. 'md5' => 'acbd18db4cc2f85cedef654fccc4a4d8'
  30. ], $value->file);
  31. }
  32. }
  33. }