/** * @param LifecycleEventArgs $args */ public function prePersist(LifecycleEventArgs $args) { /** @var $entity File */ $entity = $args->getEntity(); if ($entity instanceof File && $entity->isUploaded()) { $this->manager->preUpload($entity); } }
public function testPreUpload() { $file = new File(__DIR__ . '/../Fixtures/testFile/test.txt'); $this->attachment->setEmptyFile(false)->setFile($file); $adapter = $this->getMockBuilder('Gaufrette\\Adapter\\Cache')->disableOriginalConstructor()->getMock(); $this->filesystem->expects($this->any())->method('getAdapter')->will($this->returnValue($adapter)); $adapter->expects($this->once())->method('setMetadata'); $this->attachmentManager->preUpload($this->attachment); $this->assertEquals('test.txt', $this->attachment->getOriginalFilename()); $this->assertEquals('txt', $this->attachment->getExtension()); $this->assertEquals('text/plain', $this->attachment->getMimeType()); $this->assertEquals(9, $this->attachment->getFileSize()); }