/** * @param mixed $id * @param mixed $data * @return ImageInterface */ public function update($id, $data) { $blob = $this->searchBlob($data); if ($blob instanceof ApiProblem) { return $blob; } $this->imageManager->grab($blob, $id); $image = $this->imageManager->get($id); $entity = $this->getApigilityResponse($image, $id); $this->getEvent()->setParam('image', $entity); return $entity; }
public function testServiceGrab() { $image = new RightImage(__DIR__ . '/../Image/img/test.jpg'); $storage = $this->getMock('ImgMan\\Storage\\Adapter\\Mongo\\MongoAdapter'); $storage->expects($this->any())->method('hasImage')->will($this->returnValue(false)); $storage->expects($this->any())->method('saveImage')->will($this->returnValue(true)); $adapter = $this->getMock('ImgMan\\Core\\Adapter\\ImagickAdapter'); $adapter->expects($this->any())->method('clear')->will($this->returnValue(true)); $adapter->expects($this->any())->method('getBlob')->will($this->returnValue($image)); /* @var $pluginManager \Zend\ServiceManager\AbstractPluginManager */ $helper = $this->getMock('ImgMan\\Operation\\Helper\\Resize'); $helper->expects($this->any())->method('execute')->will($this->returnValue(true)); $pluginManager = $this->getMock('ImgMan\\Operation\\HelperPluginManager'); $pluginManager->expects($this->any())->method('get')->will($this->returnValue($helper)); /** @var $storage MongoAdapter */ /** @var $pluginManager HelperPluginManager */ /** @var $adapter ImagickAdapter */ $service = new ImageService($storage, $pluginManager, $adapter); $service->setRenditions(['thumb' => ['resize' => ['height' => 200, 'width' => 300]], 'thumbMaxi' => ['resize' => ['height' => 200, 'width' => 300]]]); $this->assertSame('test/test/', $service->grab($image, 'test/test/')); $storage = $this->getMock('ImgMan\\Storage\\Adapter\\Mongo\\MongoAdapter'); $storage->expects($this->any())->method('hasImage')->will($this->returnValue(true)); $storage->expects($this->any())->method('updateImage')->will($this->returnValue(true)); $adapter = $this->getMock('ImgMan\\Core\\Adapter\\ImagickAdapter'); $adapter->expects($this->any())->method('clear')->will($this->returnValue(true)); $adapter->expects($this->any())->method('getBlob')->will($this->returnValue($image)); /* @var $pluginManager \Zend\ServiceManager\AbstractPluginManager */ $helper = $this->getMock('ImgMan\\Operation\\Helper\\Resize'); $helper->expects($this->any())->method('execute')->will($this->returnValue(true)); $pluginManager = $this->getMock('ImgMan\\Operation\\HelperPluginManager'); $pluginManager->expects($this->any())->method('get')->will($this->returnValue($helper)); /** @var $storage MongoAdapter */ /** @var $pluginManager HelperPluginManager */ /** @var $adapter ImagickAdapter */ $service = new ImageService($storage, $pluginManager, $adapter); $service->setRenditions(['thumb' => ['resize' => ['height' => 200, 'width' => 300]], 'thumbMaxi' => ['resize' => ['height' => 200, 'width' => 300]]]); $this->assertSame('test/test/', $service->grab($image, 'test/test/')); }