/** * 임시저장 데이터 갱신 * * @param string $id 임시저장 아이디 * @param string $val 갱신될 data 값 * @param array $etc 기타 값들 * @return DraftEntity */ public function put($id, $val, array $etc = []) { if (($draft = $this->getById($id)) === null) { return null; } $draft->val = $val; $draft->etc = serialize($etc); return $this->repo->update($draft); }
public function testUpdate() { list($conn, $keygen, $query) = $this->getMocks(); $instance = new DraftRepository($conn, $keygen); $mockEntity = m::mock('Xpressengine\\Draft\\DraftEntity'); $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";}'; })); $draft = $instance->update($mockEntity); $this->assertEquals('qux', $draft->val); $this->assertEquals('a:1:{s:3:"foo";s:3:"baz";}', $draft->etc); }