public function test_useGeneratedFilenameWhenAppendingNumbers()
 {
     // We set the default path on the listener
     $this->listener->setDefaultPath($this->destinationTestDir);
     $file = new FileWithAlphanumericName();
     $fileInfo = $this->generateUploadedFile('file', $this->testFileWithSpaces, $this->testFilenameWithSpaces);
     $this->listener->addEntityFileInfo($file, $fileInfo);
     $this->em->persist($file);
     $this->em->flush();
     $filePath = $file->getPath() . '/' . str_replace(' ', '-', $fileInfo['name']);
     $this->assertPathEquals($filePath, $file->getFilePath());
     $file = new FileWithAlphanumericName();
     $this->listener->addEntityFileInfo($file, $fileInfo);
     $this->em->persist($file);
     $this->em->flush();
     $filePath = $file->getPath() . '/' . str_replace(' ', '-', str_replace('.txt', '-2.txt', $fileInfo['name']));
     $this->assertPathEquals($filePath, $file->getFilePath());
 }
 /**
  * Set and validate default path
  * @param string $path
  * @throws FileNotFoundException
  * @throws InvalidStateException
  */
 public function setDefaultPath($path)
 {
     // Validate default path
     if (!file_exists($path) && !mkdir($path, 0777, TRUE)) {
         throw new FileNotFoundException("Default upload path: \"{$path}\" not found.");
     }
     if (!is_dir($path)) {
         throw new InvalidStateException("Default upload path: \"{$path}\" is not dir.");
     } else {
         if (!is_writable($path)) {
             throw new InvalidStateException("Default upload path: \"{$path}\" is not writable.");
         }
     }
     $path = self::normalizePath($path);
     parent::setDefaultPath($path);
 }