Exemplo n.º 1
0
 /**
  * @return Attachment
  */
 public static function create()
 {
     $fileFactory = new FileFactory();
     $file = $fileFactory->create();
     $attachment = new TestAttachment();
     $attachment->setFile($file)->setDescription('This is a test description.');
     return $attachment;
 }
Exemplo n.º 2
-1
 /**
  * Test if entity persistence and removal is handled correctly.
  * Tests also that associated physical file exists/is removed.
  */
 public function testPersistenceAndRemoval()
 {
     $container = static::$kernel->getContainer();
     $filesystem = new Filesystem();
     $repoFile = $this->em->getRepository('ReskumeFileBundle:File');
     $fileFactory = new FileFactory();
     $file = $fileFactory->create();
     // test only one entry in database table
     $this->em->persist($file);
     $this->em->flush();
     $result = $repoFile->findAll();
     $this->assertCount(1, $result);
     // @important clear em and refetch entity to suppress foreign key mapping errors
     $this->em->clear();
     $result = $repoFile->findAll();
     $result = $result[0];
     // check that associated file exists
     $fileStorageConfig = $container->get('reskume_file.configuration.file_storage_configuration');
     $filePath = sprintf('%s%s', $fileStorageConfig->getFileDir(), $result->getKey());
     $this->assertTrue($filesystem->exists($filePath));
     // test correct removal
     $this->em->remove($result);
     $this->em->flush();
     $result = $repoFile->findAll();
     $this->assertEmpty($result);
     // test that associated file is deleted from filesystem
     $this->assertFalse($filesystem->exists($filePath));
 }