/** * @param LifecycleEventArgs $args */ public function postPersist(LifecycleEventArgs $args) { /** @var $entity File */ $entity = $args->getEntity(); if ($entity instanceof File && $entity->isUploaded()) { $this->manager->upload($entity); $this->manager->checkOnDelete($entity, $args->getEntityManager()); } }
/** * {@inheritdoc} */ public function denormalize($data, $class, $format = null, array $context = []) { $result = null; $entity = $this->attachmentManager->prepareRemoteFile($data); if ($entity) { $violations = $this->validator->validate($context['entityName'], $entity, $context['fieldName']); if (!$violations->count()) { $this->attachmentManager->upload($entity); $result = $entity; } } return $result; }
public function testUpload() { $this->attachment->setEmptyFile(false); $file = $this->getMockBuilder('Symfony\\Component\\HttpFoundation\\File\\File')->setConstructorArgs([__DIR__ . '/../Fixtures/testFile/test.txt'])->getMock(); $this->attachment->setFile($file); $path = __DIR__ . '/../Fixtures/testFile/test.txt'; $file->expects($this->once())->method('getPathname')->will($this->returnValue(realpath($path))); $file->expects($this->once())->method('isFile')->will($this->returnValue(true)); $memoryBuffer = new InMemoryBuffer($this->filesystem, 'test.txt'); $this->filesystem->expects($this->once())->method('createStream')->with($this->attachment->getFilename())->will($this->returnValue($memoryBuffer)); $this->attachmentManager->upload($this->attachment); $memoryBuffer->open(new StreamMode('rb+')); $memoryBuffer->seek(0); $this->assertEquals('Test data', $memoryBuffer->read(100)); }