public function searchByRange($from, $to) { $models = $this->keyValue->newQuery()->where('key', '>=', $from)->where('key', '<=', $to)->get(); $keyValues = []; foreach ($models as $model) { $keyValues[$model->key] = $model->value; } return $keyValues; }
public function increase_value_of_key_by_N() { $this->model->shouldReceive('newQuery')->once()->andReturn($this->builder); $key = 'key-name:1'; $this->builder->shouldReceive('where')->once()->with('key', '=', $key)->andReturnSelf(); $this->builder->shouldReceive('firstOrFail')->once()->andReturn($this->model); $value = 2; $this->model->shouldReceive('getAttribute')->once()->with('value')->andReturn($value); $this->model->shouldReceive('setAttribute')->once()->with('value', 4); $this->model->shouldReceive('save')->once()->andReturn(true); $this->store->increase($key, $value); }