/** * Should be able to attach images. */ public function testAttachImages() { /** @var BelongsToMany|MockObject $relationship */ $relationship = $this->makeMock(BelongsToMany::class); $this->product->setImagesRelationship($relationship); $imageIDs = [$this->generator()->anyInteger(), $this->generator()->anyInteger()]; $relationship->expects($this->atLeastOnce())->method('attach')->with($imageIDs); $this->product->attachImages($imageIDs); }
/** * @param FileBag|UploadedFile[] $images * @param Product $product * * @throws \Symfony\Component\HttpFoundation\File\Exception\FileException */ public function attachUploadedImagesToProduct($images, Product $product) { $product->attachImages(array_map(function (UploadedFile $image) { return $this->imageRepository->storeUploadedImage($image)->id; }, $images instanceof FileBag ? $images->all() : (array) $images)); }