Repository: doctrine-extensions/DoctrineExtensions (language: php)

Issue:
[Uploadable] Wrong renaming with appendNumber for files without extension
When file has no extension, file path is replaced with file name.

Reproduction test case (in `tests/Gedmo/Uploadable/UploadableEntityTest.php`):

```php
public function dataProvider_moveFile() {
    return [
        'With extension' => [
            'Filename' => 'test.txt',
            'Expected renamed filename' => 'test-2.txt',
        ],
        'Without extension' => [
            'Filename' => 'test',
            'Expected renamed filename' => 'test-2',
        ],
    ];
}

/**
 * @dataProvider dataProvider_moveFile
 */
public function test_moveFile_usingAppendNumberOptionAppendsNumberToFilenameIfItAlreadyExistsRelativePath(string $filename, string $renamedFilename)
{
    $file = new FileAppendNumber();
    $file2 = new FileAppendNumber();

    $fileInfo = $this->generateUploadedFile('image', __DIR__ . '/../../data/' . $filename, $filename);

    $this->listener->addEntityFileInfo($file, $fileInfo);

    $this->em->persist($file);
    $this->em->flush();

    $this->listener->addEntityFileInfo($file2, $fileInfo);

    $this->em->persist($file2);
    $this->em->flush();

    $this->em->refresh($file2);

    $this->assertStringEndsWith(
        '/temp/uploadable/' . $renamedFilename,
        $file2->getFilePath()
    );

    $this->assertEquals(
        \realpath(__DIR__ . '/../../temp/uploadable/' . $renamedFilename),
        \realpath($file2->getFilePath())
    );
}
```

Test run result:

```bash
/var/www# bin/phpunit -c tests/ --filter "/test_moveFile_AppendNumberWithoutExtension/" /var/www/tests/Gedmo/Uploadable
PHPUnit 8.5.15 by Sebastian Bergmann and contributors.

.F                                                                  2 / 2 (100%)

Time: 92 ms, Memory: 10.00 MB

There was 1 failure:

1) Gedmo\Uploadable\UploadableEntityTest::test_moveFile_AppendNumberWithoutExtension with data set "Without extension" ('test', 'test-2')
Failed asserting that 'test-21' ends with "/temp/uploadable/test-2".

/var/www/tests/Gedmo/Uploadable/UploadableEntityTest.php:471

FAILURES!
Tests: 2, Assertions: 3, Failures: 1.
```

I think there should be no difference between files with extension and without. But maybe I'm wrong, it works this way for a long time.



Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 2dba027c7..4814fbce9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -27,6 +27,9 @@ a release.
 - Dropped support for doctrine/mongodb-odm < 2.3.
 - Make doctrine/cache an optional dependency.
 
+## Fixed
+- Loggable: Fix `appendNumber` renaming for files without extension (#2228)
+
 ## [3.6.0] - 2022-03-19
 ### Added
 - Translatable: Add defaultTranslationValue option to allow null or string value (#2167). TranslatableListener can hydrate object properties with null value, but it may cause a Type error for non-nullable getter upon a missing translation.
diff --git a/src/Uploadable/UploadableListener.php b/src/Uploadable/UploadableListener.php
index 73d07e982..0bba006e7 100644
--- a/src/Uploadable/UploadableListener.php
+++ b/src/Uploadable/UploadableListener.php
@@ -445,7 +445,7 @@ public function moveFile(FileInfoInterface $fileInfo, $path, $filenameGeneratorC
             $info['fileExtension'] = substr($info['filePath'], strrpos($info['filePath'], '.'));
             $info['fileWithoutExt'] = substr($info['filePath'], 0, strrpos($info['filePath'], '.'));
         } else {
-            $info['fileWithoutExt'] = $info['fileName'];
+            $info['fileWithoutExt'] = $info['filePath'];
         }
 
         // Save the original filename for later use


Test patch:
diff --git a/tests/Gedmo/Uploadable/UploadableEntityTest.php b/tests/Gedmo/Uploadable/UploadableEntityTest.php
index 52445b5c2..4166f0972 100644
--- a/tests/Gedmo/Uploadable/UploadableEntityTest.php
+++ b/tests/Gedmo/Uploadable/UploadableEntityTest.php
@@ -477,7 +477,24 @@ public function testRemoveFileIfItsNotAFileThenReturnFalse(): void
         static::assertFalse($this->listener->removeFile('non_existent_file'));
     }
 
-    public function testMoveFileUsingAppendNumberOptionAppendsNumberToFilenameIfItAlreadyExists(): void
+    public function dataProvider_testMoveFileUsingAppendNumberOptionAppendsNumberToFilenameIfItAlreadyExists(): array
+    {
+        return [
+            'With extension' => [
+                'Filename' => 'test.txt',
+                'Expected filename' => 'test-2.txt',
+            ],
+            'Without extension' => [
+                'Filename' => 'test',
+                'Expected filename' => 'test-2',
+            ],
+        ];
+    }
+
+    /**
+     * @dataProvider dataProvider_testMoveFileUsingAppendNumberOptionAppendsNumberToFilenameIfItAlreadyExists
+     */
+    public function testMoveFileUsingAppendNumberOptionAppendsNumberToFilenameIfItAlreadyExists(string $filename, string $expectedFilename): void
     {
         $file = new FileAppendNumber();
         $file2 = new FileAppendNumber();
@@ -485,7 +502,7 @@ public function testMoveFileUsingAppendNumberOptionAppendsNumberToFilenameIfItAl
         $file->setTitle('test');
         $file2->setTitle('test2');
 
-        $fileInfo = $this->generateUploadedFile();
+        $fileInfo = $this->generateUploadedFile(false, $filename);
 
         $this->listener->addEntityFileInfo($file, $fileInfo);
 
@@ -499,9 +516,7 @@ public function testMoveFileUsingAppendNumberOptionAppendsNumberToFilenameIfItAl
 
         $this->em->refresh($file2);
 
-        $filename = substr($file2->getFilePath(), strrpos($file2->getFilePath(), '/') + 1);
-
-        static::assertSame('test-2.txt', $filename);
+        static::assertSame($expectedFilename, basename($file2->getFilePath()));
     }
 
     public function testMoveFileUsingAppendNumberOptionAppendsNumberToFilenameIfItAlreadyExistsRelativePath(): void