MongoGridFSCursorTest.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace Alcaeus\MongoDbAdapter\Tests\Mongo;
  3. use Alcaeus\MongoDbAdapter\Tests\Constraint\Matches;
  4. use Alcaeus\MongoDbAdapter\Tests\TestCase;
  5. use Countable;
  6. class MongoGridFSCursorTest extends TestCase
  7. {
  8. public function testSerialize()
  9. {
  10. $gridfs = $this->getGridFS();
  11. $gridfs->storeBytes('foo', ['filename' => 'foo.txt']);
  12. $gridfs->storeBytes('bar', ['filename' => 'bar.txt']);
  13. $cursor = $gridfs->find(['filename' => 'foo.txt']);
  14. $this->assertIsString(serialize($cursor));
  15. }
  16. public function testCursorItems()
  17. {
  18. $gridfs = $this->getGridFS();
  19. $id = $gridfs->storeBytes('foo', ['filename' => 'foo.txt']);
  20. $gridfs->storeBytes('bar', ['filename' => 'bar.txt']);
  21. $cursor = $gridfs->find(['filename' => 'foo.txt']);
  22. $this->assertCount(1, $cursor);
  23. foreach ($cursor as $key => $value) {
  24. $this->assertSame((string) $id, $key);
  25. $this->assertInstanceOf('MongoGridFSFile', $value);
  26. $this->assertSame('foo', $value->getBytes());
  27. $this->assertMatches([
  28. 'filename' => 'foo.txt',
  29. 'chunkSize' => 261120,
  30. 'length' => 3,
  31. 'md5' => 'acbd18db4cc2f85cedef654fccc4a4d8'
  32. ], $value->file);
  33. }
  34. }
  35. public function testInterfaces()
  36. {
  37. $this->skipTestIf(extension_loaded('mongo'));
  38. $gridfs = $this->getGridFS();
  39. $id = $gridfs->storeBytes('foo', ['filename' => 'foo.txt']);
  40. $gridfs->storeBytes('bar', ['filename' => 'bar.txt']);
  41. $cursor = $gridfs->find(['filename' => 'foo.txt']);
  42. $this->assertInstanceOf(Countable::class, $cursor);
  43. }
  44. }