Skip to content

Commit 44836eb

Browse files
committed
PR 32814 feedback
1 parent f6aacc1 commit 44836eb

File tree

2 files changed

+24
-25
lines changed

2 files changed

+24
-25
lines changed

app/code/Magento/MediaStorage/Model/File/Storage/File.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -291,9 +291,8 @@ public function saveFile($file, $overwrite = true)
291291
&& isset($file['content'])
292292
&& !empty($file['content'])
293293
) {
294-
$filename = isset(
295-
$file['directory']
296-
) && !empty($file['directory']) ? $file['directory'] . '/' . $file['filename'] : $file['filename'];
294+
$directory = !empty($file['directory'] ?? '') ? $file['directory'] . '/' : '';
295+
$filename = $directory . $file['filename'];
297296

298297
try {
299298
return $this->_fileUtility->saveFile($filename, $file['content'], $overwrite);

app/code/Magento/MediaStorage/Test/Unit/Model/File/Storage/FileTest.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,80 +22,80 @@ class FileTest extends TestCase
2222
/**
2323
* @var File
2424
*/
25-
protected $_file;
25+
private $file;
2626

2727
/**
2828
* @var Media
2929
*/
30-
protected $_loggerMock;
30+
private $loggerMock;
3131

3232
/**
3333
* @var Database
3434
*/
35-
protected $_storageHelperMock;
35+
private $storageHelperMock;
3636

3737
/**
3838
* @var DateTime
3939
*/
40-
protected $_mediaHelperMock;
40+
private $mediaHelperMock;
4141

4242
/**
4343
* @var \Magento\MediaStorage\Model\ResourceModel\File\Storage\File
4444
*/
45-
protected $_fileUtilityMock;
45+
private $fileUtilityMock;
4646

4747
protected function setUp(): void
4848
{
49-
$this->_loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
50-
$this->_storageHelperMock = $this->createMock(Database::class);
51-
$this->_mediaHelperMock = $this->createMock(Media::class);
52-
$this->_fileUtilityMock = $this->createMock(\Magento\MediaStorage\Model\ResourceModel\File\Storage\File::class);
49+
$this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
50+
$this->storageHelperMock = $this->createMock(Database::class);
51+
$this->mediaHelperMock = $this->createMock(Media::class);
52+
$this->fileUtilityMock = $this->createMock(\Magento\MediaStorage\Model\ResourceModel\File\Storage\File::class);
5353

54-
$this->_file = new File(
55-
$this->_loggerMock,
56-
$this->_storageHelperMock,
57-
$this->_mediaHelperMock,
58-
$this->_fileUtilityMock
54+
$this->file = new File(
55+
$this->loggerMock,
56+
$this->storageHelperMock,
57+
$this->mediaHelperMock,
58+
$this->fileUtilityMock
5959
);
6060
}
6161

6262
protected function tearDown(): void
6363
{
64-
unset($this->_file);
64+
unset($this->file);
6565
}
6666

6767
public function testSaveFileWithWrongFileFormat(): void
6868
{
6969
$this->expectException(LocalizedException::class);
7070
$this->expectExceptionMessage('Wrong file info format');
71-
$this->_file->saveFile([]);
71+
$this->file->saveFile([]);
7272
}
7373

74-
public function testSaveFileUnsuccessfullyWithMissingDirectory()
74+
public function testSaveFileUnsuccessfullyWithMissingDirectory(): void
7575
{
76-
$this->_fileUtilityMock
76+
$this->fileUtilityMock
7777
->expects($this->once())
7878
->method('saveFile')
7979
->willThrowException(new Exception());
8080

8181
$this->expectException(LocalizedException::class);
8282
$this->expectExceptionMessage('Unable to save file "filename.ext" at "filename.ext"');
83-
$this->_file->saveFile([
83+
$this->file->saveFile([
8484
'filename' => 'filename.ext',
8585
'content' => 'content',
8686
]);
8787
}
8888

89-
public function testSaveFileUnsuccessfullyWithoutMissingDirectory()
89+
public function testSaveFileUnsuccessfullyWithoutMissingDirectory(): void
9090
{
91-
$this->_fileUtilityMock
91+
$this->fileUtilityMock
9292
->expects($this->once())
9393
->method('saveFile')
9494
->willThrowException(new Exception());
9595

9696
$this->expectException(LocalizedException::class);
9797
$this->expectExceptionMessage('Unable to save file "filename.ext" at "directory/filename.ext"');
98-
$this->_file->saveFile([
98+
$this->file->saveFile([
9999
'directory' => 'directory',
100100
'filename' => 'filename.ext',
101101
'content' => 'content',

0 commit comments

Comments
 (0)