/**
  * Transforms a collection os files on session on entities
  *
  * @throws TransformationFailedException if object (issue) is not found.
  */
 public function reverseTransform($id)
 {
     // Pasar los ficheros almacenados en la sesión a la carpeta web y devolver el array de ficheros
     $manager = $this->orphanageManager->get('gallery');
     $images = $manager->uploadFiles();
     if (count($images) == 0) {
         return null;
     } else {
         if (count($images) == 1) {
             $file = $this->om->getRepository('AppBundle:File')->findOneByPath('uploads/gallery/' . $images[0]->getFilename());
             if ($file == null) {
                 $file = new File();
                 $file->setPath('uploads/gallery/' . $images[0]->getFilename());
                 $this->om->persist($file);
                 $this->om->flush();
             }
             $data = $file;
         } else {
             $data = array();
             foreach ($images as $image) {
                 $file = $this->om->getRepository('AppBundle:File')->findOneByPath('uploads/gallery/' . $image->getFilename());
                 if ($file == null) {
                     $file = new File();
                     $file->setPath('uploads/gallery/' . $image->getFilename());
                     $this->om->persist($file);
                     $this->om->flush();
                 }
                 $data[] = $file;
             }
             $this->om->flush();
         }
     }
     return $data;
 }
 public function testClearIfDirectoryDoesNotExist()
 {
     $filesystem = new Filesystem();
     $filesystem->remove($this->mockConfig['directory']);
     $manager = new OrphanageManager($this->mockContainer, $this->mockConfig);
     $manager->clear();
     // yey, no exception
     $this->assertTrue(true);
 }