Alcaeus\MongoDbAdapter\Tests\Mongo\MongoCollectionTest::testSaveInsert PHP Method

testSaveInsert() public method

public testSaveInsert ( )
    public function testSaveInsert()
    {
        $id = '54203e08d51d4a1f868b456e';
        $collection = $this->getCollection();
        $objectId = new \MongoId($id);
        $expected = ['ok' => 1.0, 'nModified' => 0, 'n' => 1, 'err' => null, 'errmsg' => null, 'upserted' => $objectId, 'updatedExisting' => false];
        $document = ['_id' => $objectId, 'foo' => 'bar'];
        $this->assertEquals($expected, $collection->save($document));
        $newCollection = $this->getCheckDatabase()->selectCollection('test');
        $this->assertSame(1, $newCollection->count());
        $object = $newCollection->findOne();
        $this->assertNotNull($object);
        $this->assertAttributeInstanceOf('MongoDB\\BSON\\ObjectID', '_id', $object);
        $this->assertSame($id, (string) $object->_id);
        $this->assertObjectHasAttribute('foo', $object);
        $this->assertAttributeSame('bar', 'foo', $object);
    }
MongoCollectionTest