MongoCollectionTest.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace Alcaeus\MongoDbAdapter\Tests;
  3. /**
  4. * @author alcaeus <alcaeus@alcaeus.org>
  5. * @covers MongoCollection
  6. */
  7. class MongoCollectionTest extends TestCase
  8. {
  9. public function testCreateRecord()
  10. {
  11. $id = '54203e08d51d4a1f868b456e';
  12. $collection = $this->getCollection();
  13. $collection->insert(['_id' => new \MongoId($id), 'foo' => 'bar']);
  14. $newCollection = $this->getCheckDatabase()->selectCollection('test');
  15. $this->assertSame(1, $newCollection->count());
  16. $object = $newCollection->findOne();
  17. $this->assertNotNull($object);
  18. $this->assertAttributeInstanceOf('MongoDB\BSON\ObjectID', '_id', $object);
  19. $this->assertSame($id, (string) $object->_id);
  20. $this->assertObjectHasAttribute('foo', $object);
  21. $this->assertAttributeSame('bar', 'foo', $object);
  22. }
  23. /**
  24. * @return \MongoCollection
  25. */
  26. protected function getCollection($name = 'test')
  27. {
  28. $client = new \MongoClient();
  29. return $client->selectCollection('mongo-php-adapter', $name);
  30. }
  31. }