/**
  * Writes the source file in such a way that race conditions are avoided when the same file is written
  * multiple times in a short time period
  *
  * @param string $source
  * @param string $location
  *
  * @throws FileNotWritableException
  */
 private function writeFile($source, $location)
 {
     $tmpFileName = $location . '.' . uniqid('', true);
     if (!file_put_contents($tmpFileName, $source)) {
         throw FileNotWritableException::fromNonWritableLocation($tmpFileName);
     }
     if (!rename($tmpFileName, $location)) {
         unlink($tmpFileName);
         throw FileNotWritableException::fromInvalidMoveOperation($tmpFileName, $location);
     }
 }
 public function testFromInvalidMoveOperation()
 {
     $exception = FileNotWritableException::fromInvalidMoveOperation('/tmp/a', '/tmp/b');
     $this->assertInstanceOf('ProxyManager\\Exception\\FileNotWritableException', $exception);
     $this->assertSame('Could not move file "/tmp/a" to location "/tmp/b": either the source file is not readable,' . ' or the destination is not writable', $exception->getMessage());
 }