public function testCreateOverwritesIfExists()
 {
     $stream = fopen('php://memory', 'rb');
     $spiBinaryFileCreateStruct = new SPIBinaryFileCreateStruct();
     $spiBinaryFileCreateStruct->id = 'prefix/my/file.png';
     $spiBinaryFileCreateStruct->mimeType = 'image/png';
     $spiBinaryFileCreateStruct->size = 123;
     $spiBinaryFileCreateStruct->mtime = 1307155200;
     $spiBinaryFileCreateStruct->setInputStream($stream);
     $this->filesystem->expects($this->once())->method('writeStream')->with($this->equalTo($spiBinaryFileCreateStruct->id), $this->equalTo($stream), $this->equalTo(array('mimetype' => 'image/png', 'visibility' => 'public')))->will($this->throwException(new FileExistsException('prefix/my/file.png')));
     $this->filesystem->expects($this->once())->method('updateStream')->with($this->equalTo($spiBinaryFileCreateStruct->id), $this->equalTo($stream), $this->equalTo(array('mimetype' => 'image/png', 'visibility' => 'public')));
     $this->handler->create($spiBinaryFileCreateStruct);
 }
 public function createBinaryFile(BinaryFileCreateStruct $binaryFileCreateStruct)
 {
     if (empty($binaryFileCreateStruct->id) || !is_string($binaryFileCreateStruct->id)) {
         throw new InvalidArgumentValue('id', $binaryFileCreateStruct->id, 'BinaryFileCreateStruct');
     }
     if (!is_int($binaryFileCreateStruct->size) || $binaryFileCreateStruct->size < 0) {
         throw new InvalidArgumentValue('size', $binaryFileCreateStruct->size, 'BinaryFileCreateStruct');
     }
     if (!is_resource($binaryFileCreateStruct->inputStream)) {
         throw new InvalidArgumentValue('inputStream', 'property is not a file resource', 'BinaryFileCreateStruct');
     }
     if (!isset($binaryFileCreateStruct->mimeType)) {
         $buffer = fread($binaryFileCreateStruct->inputStream, $binaryFileCreateStruct->size);
         $binaryFileCreateStruct->mimeType = $this->mimeTypeDetector->getFromBuffer($buffer);
         unset($buffer);
     }
     $spiBinaryCreateStruct = $this->buildSPIBinaryFileCreateStructObject($binaryFileCreateStruct);
     try {
         $this->binarydataHandler->create($spiBinaryCreateStruct);
     } catch (Exception $e) {
         throw new IOException('An error occured creating binarydata', $e);
     }
     $spiBinaryFile = $this->metadataHandler->create($spiBinaryCreateStruct);
     if (!isset($spiBinaryFile->uri)) {
         $spiBinaryFile->uri = $this->binarydataHandler->getUri($spiBinaryFile->id);
     }
     return $this->buildDomainBinaryFileObject($spiBinaryFile);
 }