Sokil\Mongo\BatchTest::testUpdate PHP Method

testUpdate() public method

public testUpdate ( )
    public function testUpdate()
    {
        // insert
        $this->collection->batchInsert(array(array('a' => 1, 'b' => 1), array('a' => 2, 'b' => 2), array('a' => 3, 'b' => 3)));
        // update
        $batch = new BatchUpdate($this->collection);
        $batch->update(array('a' => 1), array('$set' => array('b' => 'updated1')))->update($this->collection->expression()->where('a', 2), $this->collection->operator()->set('b', 'updated2'))->update(function (Expression $e) {
            $e->where('a', 3);
        }, function (Operator $o) {
            $o->set('b', 'updated3');
        })->execute();
        // test
        $result = $this->collection->findAsArray()->sort(array('a' => 1))->map(function ($data) {
            unset($data['_id']);
            return $data;
        });
        $this->assertEquals(array_values($result), array(array('a' => 1, 'b' => 'updated1'), array('a' => 2, 'b' => 'updated2'), array('a' => 3, 'b' => 'updated3')));
    }