public function testFind() { list($conn, $query) = $this->getMocks(); $instance = new ImageRepository($conn); $id = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; $conn->shouldReceive('table')->andReturn($query); $query->shouldReceive('where')->once()->with('id', $id)->andReturnSelf(); $query->shouldReceive('first')->once()->andReturn(['id' => $id, 'width' => 100, 'height' => 100]); $meta = $instance->find($id); $this->assertInstanceOf('Xpressengine\\Media\\Meta', $meta); $query->shouldReceive('where')->once()->with('id', $id)->andReturnSelf(); $query->shouldReceive('first')->once()->andReturnNull(); $this->assertNull($instance->find($id)); }
/** * media 객체로 반환 * * @param File $file file instance * @param array $addInfo additional information * @return Image * @throws NotAvailableException */ public function make(File $file, array $addInfo = []) { if ($this->isAvailable($file->getMime()) !== true) { throw new NotAvailableException(); } if (!($meta = $this->repo->find($file->getId()))) { $meta = $this->extractInformation($file); foreach ($addInfo as $key => $value) { $meta->{$key} = $value; } $meta = $this->repo->insert($meta); } return $this->createModel($file, $meta); }