MongoGridFSCursorTest.php 1.6 KB

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