public function testDoesNotPurgeNotExistingItem()
 {
     $purger = $this->createPurger(array('path/to/file.png'));
     $this->pathGeneratorMock->expects($this->once())->method('getVariationPath')->will($this->returnValue('path/to/file_large.png'));
     $this->ioServiceMock->expects($this->once())->method('exists')->will($this->returnValue(false));
     $this->ioServiceMock->expects($this->never())->method('loadBinaryFile');
     $this->ioServiceMock->expects($this->never())->method('deleteBinaryFile');
     $purger->purge(array('large'));
 }
 /**
  * Purge all variations generated for aliases in $aliasName.
  *
  * @param array $aliasNames
  */
 public function purge(array $aliasNames)
 {
     foreach ($this->imageFileList as $originalImageId) {
         foreach ($aliasNames as $aliasName) {
             $variationImageId = $this->variationPathGenerator->getVariationPath($originalImageId, $aliasName);
             if (!$this->ioService->exists($variationImageId)) {
                 continue;
             }
             $binaryFile = $this->ioService->loadBinaryFile($variationImageId);
             $this->ioService->deleteBinaryFile($binaryFile);
             if (isset($this->logger)) {
                 $this->logger->info("Purging {$aliasName} variation {$variationImageId} for original image {$originalImageId}");
             }
         }
     }
 }
 public function testRemoveWithFilters()
 {
     $originalPath = 'foo/bar/test.jpg';
     $filters = array('filter1', 'filter2', 'chaud_cacao');
     $this->configResolver->expects($this->never())->method('getParameter')->with('image_variations')->will($this->returnValue(array()));
     $this->variationPathGenerator->expects($this->exactly(count($filters)))->method('getVariationPath')->will($this->returnValueMap(array(array('foo/bar/test.jpg', 'filter1', 'foo/bar/test_filter1.jpg '), array('foo/bar/test.jpg', 'filter2', 'foo/bar/test_filter2.jpg '), array('foo/bar/test.jpg', 'chaud_cacao', 'foo/bar/test_chaud_cacao.jpg'))));
     $fileToDelete = 'foo/bar/test_chaud_cacao.jpg';
     $this->ioService->expects($this->exactly(count($filters)))->method('exists')->will($this->returnValueMap(array(array('foo/bar/test_filter1.jpg', false), array('foo/bar/test_filter2.jpg', false), array($fileToDelete, true))));
     $binaryFile = new BinaryFile(array('id' => $fileToDelete));
     $this->ioService->expects($this->once())->method('loadBinaryFile')->with($fileToDelete)->will($this->returnValue($binaryFile));
     $this->ioService->expects($this->once())->method('deleteBinaryFile')->with($binaryFile);
     $this->imageResolver->remove(array($originalPath), $filters);
 }
 /**
  * Returns path for filtered image from original path, using the VariationPathGenerator.
  *
  * @param string $path
  * @param string $filter
  *
  * @return string
  */
 public function getFilePath($path, $filter)
 {
     return $this->variationPathGenerator->getVariationPath($path, $filter);
 }