/**
  * @param \Dvs\FileBundle\Storage\Naming\NamingStrategy           $namingStrategy
  * @param \Dvs\FileBundle\Storage\PathGenerating\FilePathStrategy $filePathStrategy
  * @param \Dvs\FileBundle\Interfaces\FileSystem      $filesystem
  * @param \Dvs\FileBundle\Storage\Resource\Storageable            $storageable
  */
 public function it_should_store_resource_if_possible($namingStrategy, $filePathStrategy, $filesystem, $storageable)
 {
     // Given
     $fileInfo = new \SplFileInfo(__FILE__);
     $namingStrategy->generate($storageable)->willReturn($filename = 'filename');
     $filePathStrategy->generate($filename)->willReturn($path = 'path/to/file/filename');
     $filename .= '.' . $fileInfo->getExtension();
     $filePathWithName = $path . DIRECTORY_SEPARATOR . $filename;
     $filesystem->write($filePathWithName, file_get_contents(__FILE__))->willReturn(true);
     // When
     $this->store($storageable, $fileInfo)->shouldReturn(true);
     $storageable->setFileName($filename)->shouldHaveBeenCalled();
 }
 /**
  * @param Storageable $storageable
  * @param \SplFileInfo $fileInfo
  *
  * @return bool
  */
 public function store(Storageable $storageable, \SplFileInfo $fileInfo) : bool
 {
     $fileName = $this->namingStrategy->generate($storageable);
     $filePath = $this->filePathStrategy->generate($fileName);
     $fileExtension = $this->getFileExtension($fileInfo);
     if ($fileExtension) {
         $fileName .= '.' . $fileExtension;
     }
     $storageable->setFileName($fileName);
     $filePathWithName = $filePath . DIRECTORY_SEPARATOR . $fileName;
     if (!$this->filesystem->write($filePathWithName, file_get_contents($fileInfo->getPathname()))) {
         throw FileStoreException::notStored();
     }
     return true;
 }