/** * 임시 데이터 저장 * * @param string $key 구분할 수 있는 키(중복가능) * @param mixed $val 저장될 내용 * @param array $etc 기타 값들 * @param bool $isAuto 자동 저장 인지 여부 * @return DraftEntity */ public function set($key, $val, array $etc = [], $isAuto = false) { if ($this->auth->guest()) { return null; } $draft = new DraftEntity(); $draft->fill(['userId' => $this->auth->user()->getId(), 'key' => $key, 'val' => $val, 'etc' => serialize($etc), 'isAuto' => $isAuto ? 1 : 0]); return $this->repo->insert($draft); }
public function testInsert() { list($conn, $keygen, $query) = $this->getMocks(); $instance = new DraftRepository($conn, $keygen); $mockEntity = m::mock('Xpressengine\\Draft\\DraftEntity'); $mockEntity->shouldReceive('getAttributes')->andReturn(['key' => 'someKey', 'val' => 'baz', 'etc' => 'a:1:{s:3:"foo";s:3:"bar";}']); $keygen->shouldReceive('generate')->andReturn('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'); $conn->shouldReceive('table')->andReturn($query); $query->shouldReceive('insert')->once()->with(m::on(function ($array) { return $array['key'] === 'someKey' && $array['val'] === 'baz' && $array['etc'] === 'a:1:{s:3:"foo";s:3:"bar";}' && $array['id'] === 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; })); $draft = $instance->insert($mockEntity); $this->assertEquals('xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', $draft->id); $this->assertEquals('someKey', $draft->key); }