예제 #1
0
 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->contribution = (new Contribution())->setAuthProvider('github')->setIdentifier('woecifaun');
     $this->pathGenerator = $this->getMockBuilder('AFUP\\HaphpyBirthdayBundle\\Service\\PathGenerator')->disableOriginalConstructor()->getMock();
     // Attacher just need a file (any file) to attach to contribution
     // The only one file to be sure to exist, is this file itself :p
     $this->pathGenerator->method('getFileAbsolutePath')->willReturn(__FILE__);
 }
 /**
  * @param Contribution $contribution
  */
 public function remove(Contribution $contribution)
 {
     if (!$contribution->getFileName()) {
         return;
     }
     unlink($this->pathGenerator->getFileAbsolutePath($contribution));
     $this->entityManager->remove($contribution);
     $this->entityManager->flush();
 }
 /**
  * Test if generated relative path for new contribution is ok
  */
 public function testGenerateRelativePath()
 {
     $pathGenerator = new PathGenerator($this->directory);
     $path = $this->contribution->getAuthProvider() . DIRECTORY_SEPARATOR;
     $path .= $this->contribution->getIdentifier();
     $path .= '.' . $this->extension;
     $relativePath = $pathGenerator->generateRelativePath($this->contribution, $this->file);
     $this->assertEquals($relativePath, $path);
 }
 /**
  * Save Contribution file to file system
  * and perist Contribution info to database
  *
  * @param Contribution $contribution
  * @param \SplFileInfo $file
  */
 public function persist(Contribution $contribution, \SplFileInfo $file)
 {
     // File
     $path = $this->pathGenerator->generateAbsolutePath($contribution, $file);
     $file->move(dirname($path), basename($path));
     // Data persistence
     $contribution->setModifiedAt(new \DateTime());
     $this->entityManager->persist($contribution);
     $this->entityManager->flush();
 }