/**
  * @dataProvider getEntity
  *
  * @param \PHPUnit_Framework_MockObject_MockObject $entity
  * @param string $filename
  */
 public function testPrePersist(\PHPUnit_Framework_MockObject_MockObject $entity, $filename)
 {
     $this->args->expects($this->once())->method('getEntity')->will($this->returnValue($entity));
     if ($entity instanceof Item || $entity instanceof Image) {
         /* @var $entity \PHPUnit_Framework_MockObject_MockObject|Item|Image */
         $time = $this->getMock('\\DateTime');
         $time->expects($this->once())->method('format')->with('Y/m/d/His/')->will($this->returnValue('some/path'));
         if ($entity instanceof Item) {
             $entity->expects($this->once())->method('getDateAdd')->will($this->returnValue($time));
         } else {
             $item = $this->getMock('\\AnimeDb\\Bundle\\CatalogBundle\\Entity\\Item');
             $entity->expects($this->once())->method('getItem')->will($this->returnValue($item));
             $item->expects($this->once())->method('getDateAdd')->will($this->returnValue($time));
         }
         $entity->expects($this->at(1))->method('getFilename')->will($this->returnValue($filename));
         if ($filename) {
             $entity->expects($this->at(2))->method('getFilename')->will($this->returnValue($filename));
         }
         if (strpos($filename, 'tmp') !== false) {
             $entity->expects($this->at(3))->method('getFilename')->will($this->returnValue($filename));
             $entity->expects($this->at(6))->method('getFilename')->will($this->returnValue('new_filename'));
             $entity->expects($this->once())->method('setFilename')->with('some/path' . pathinfo($filename, PATHINFO_BASENAME));
             $entity->expects($this->once())->method('getDownloadPath')->will($this->returnValue('web'));
             $this->fs->expects($this->once())->method('copy')->with($this->root . 'web/' . $filename, $this->root . 'web/new_filename', true);
         }
     } else {
         $entity->expects($this->never())->method('getFilename');
     }
     $this->listener->prePersist($this->args);
 }
 protected function setUp()
 {
     $this->entity = new \stdClass();
     $this->keeper = $this->getNoConstructorMock(Keeper::class);
     $this->builder = $this->getNoConstructorMock(CacheKeyBuilder::class);
     $this->args = $this->getNoConstructorMock(LifecycleEventArgs::class);
     $this->args->expects($this->atLeastOnce())->method('getEntity')->will($this->returnValue($this->entity));
 }
 private function getEntityExpectations($setSize = true)
 {
     $fileSize = filesize(__DIR__ . '/../Fixtures/test.gif');
     $file = new UploadedFile(__DIR__ . '/../Fixtures/test.gif', 'original.gif', null, $fileSize, UPLOAD_ERR_OK, true);
     $this->entity->expects($this->any())->method('getFile')->willReturn($file);
     $this->entity->expects($this->any())->method('getRemoteDir')->willReturn('remote/dir');
     $this->args->expects($this->any())->method('getEntity')->willReturn($this->entity);
     if ($setSize) {
         $this->entity->expects($this->once())->method('setSize')->with($fileSize);
     }
 }