public function upload(ImageInterface $image) { if (!$image->hasFile()) { return; } if (null !== $image->getPath()) { $this->remove($image->getPath()); } do { $hash = md5(uniqid(mt_rand(), true)); $path = $this->expandPath($hash . '.' . $image->getFile()->guessExtension()); } while ($this->filesystem->has($path)); $image->setPath($path); $this->filesystem->write($image->getPath(), file_get_contents($image->getFile()->getPathname())); }
function let(Filesystem $filesystem, ImageInterface $image) { $filesystem->has(Argument::any())->willReturn(false); $file = new File(__FILE__, 'img.jpg'); $image->getFile()->willReturn($file); $this->beConstructedWith($filesystem); }