Esempio n. 1
0
 /**
  * {@inheritdoc}
  */
 protected function handleFiles(FileBag $files, $project)
 {
     $image = $files->get('image');
     if ($image instanceof UploadedFile) {
         $media = $this->mediaFactory->create($image);
         $this->uploader->upload($media);
         $project->setImage($media);
     }
 }
Esempio n. 2
0
 function it_handles_form_that_tests_handle_project_image(Request $request, ProjectInterface $project, FormFactory $formFactory, FormBuilderInterface $formBuilder, FormInterface $form, FileBag $fileBag, MediaFactory $mediaFactory, MediaInterface $media, ObjectManager $manager, MediaUploader $uploader)
 {
     $image = new UploadedFile('', '', null, null, 99, true);
     // Avoids file not found exception
     $formFactory->createNamedBuilder('', 'kreta_project_project_type', $project, [])->shouldBeCalled()->willReturn($formBuilder);
     $formBuilder->getForm()->shouldBeCalled()->willReturn($form);
     $request->isMethod('POST')->shouldBeCalled()->willReturn(true);
     $form->handleRequest($request)->shouldBeCalled();
     $form->isValid()->shouldBeCalled()->willReturn(true);
     $fileBag->get('image')->shouldBeCalled()->willReturn($image);
     $request->files = $fileBag;
     $mediaFactory->create($image)->shouldBeCalled()->willReturn($media);
     $uploader->upload($media)->shouldBeCalled();
     $project->setImage($media)->shouldBeCalled()->willReturn($project);
     $manager->persist($project)->shouldBeCalled();
     $manager->flush()->shouldBeCalled();
     $this->handleForm($request, $project, []);
 }