/** * 임시저장 데이터 갱신 * * @param string $id 임시저장 아이디 * @param string $val 갱신될 data 값 * @param array $etc 기타 값들 * @return TemporaryEntity */ public function put($id, $val, array $etc = []) { if (($temporary = $this->getById($id)) === null) { return null; } $temporary->val = $val; $temporary->etc = serialize($etc); return $this->repo->update($temporary); }
public function testUpdate() { list($conn, $keygen, $query) = $this->getMocks(); $instance = new TemporaryRepository($conn, $keygen); $mockEntity = m::mock('Xpressengine\\Temporary\\TemporaryEntity'); $mockEntity->shouldReceive('getDirty')->andReturn(['val' => 'qux', 'etc' => 'a:1:{s:3:"foo";s:3:"baz";}']); $mockEntity->shouldReceive('getOriginal')->andReturn(['id' => 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', 'key' => 'someKey', 'val' => 'baz', 'etc' => 'a:1:{s:3:"foo";s:3:"bar";}']); $mockEntity->shouldReceive('get')->with('id')->andReturn('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'); $conn->shouldReceive('table')->andReturn($query); $query->shouldReceive('where')->once()->with('id', 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx')->andReturnSelf(); $query->shouldReceive('update')->once()->with(m::on(function ($array) { return $array['val'] === 'qux' && $array['etc'] === 'a:1:{s:3:"foo";s:3:"baz";}'; })); $temporary = $instance->update($mockEntity); $this->assertEquals('qux', $temporary->val); $this->assertEquals('a:1:{s:3:"foo";s:3:"baz";}', $temporary->etc); }