public function testFromNotWritableLocationWithNonWritablePath()
 {
     $path = sys_get_temp_dir() . '/' . uniqid('FileNotWritableExceptionTestNonWritable', true);
     mkdir($path, 0555);
     $exception = FileNotWritableException::fromNonWritableLocation($path . '/foo');
     $this->assertInstanceOf('ProxyManager\\Exception\\FileNotWritableException', $exception);
     $this->assertSame('Could not write to path "' . $path . '/foo": is not writable', $exception->getMessage());
 }
 /**
  * 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);
     }
 }