Skip to content

Commit 67c9af7

Browse files
author
Hwashiang Yu
committed
MC-31227: Media folder update
- Resolved MHI and static test failures
1 parent 8b30469 commit 67c9af7

File tree

2 files changed

+26
-13
lines changed
  • app/code/Magento/Theme/Test/Unit/Model/Design/Backend
  • lib/internal/Magento/Framework/Filesystem/Driver

2 files changed

+26
-13
lines changed

app/code/Magento/Theme/Test/Unit/Model/Design/Backend/ImageTest.php

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
use Magento\Framework\App\Config\ScopeConfigInterface;
1414
use Magento\Framework\Data\Collection\AbstractDb;
1515
use Magento\Framework\Filesystem;
16-
use Magento\Framework\Filesystem\Io\File;
16+
use Magento\Framework\Filesystem\Io\File as IoFile;
1717
use Magento\Framework\Model\Context;
1818
use Magento\Framework\Model\ResourceModel\AbstractResource;
1919
use Magento\Framework\Registry;
2020
use Magento\Framework\UrlInterface;
2121
use Magento\MediaStorage\Helper\File\Storage\Database;
2222
use Magento\MediaStorage\Model\File\UploaderFactory;
2323
use Magento\Theme\Model\Design\Backend\Image;
24-
use PHPUnit_Framework_MockObject_MockObject;
24+
use Magento\Framework\Filesystem\Directory\ReadFactory;
2525

2626
/**
2727
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -31,9 +31,14 @@ class ImageTest extends \PHPUnit\Framework\TestCase
3131
/** @var Image */
3232
private $imageBackend;
3333

34-
/** @var File */
34+
/** @var IoFile */
3535
private $ioFileSystem;
3636

37+
/**
38+
* @var ReadFactory||\PHPUnit_Framework_MockObject_MockObject
39+
*/
40+
private $tmpDirectory;
41+
3742
/**
3843
* @inheritdoc
3944
*/
@@ -50,7 +55,9 @@ public function setUp()
5055
$databaseHelper = $this->getMockObject(Database::class);
5156
$abstractResource = $this->getMockObject(AbstractResource::class);
5257
$abstractDb = $this->getMockObject(AbstractDb::class);
53-
$this->ioFileSystem = $this->getMockObject(File::class);
58+
$this->ioFileSystem = $this->getMockObject(IoFile::class);
59+
$this->tmpDirectory = $this->getMockObject(ReadFactory::class);
60+
5461
$this->imageBackend = new Image(
5562
$context,
5663
$registry,
@@ -64,7 +71,8 @@ public function setUp()
6471
$abstractDb,
6572
[],
6673
$databaseHelper,
67-
$this->ioFileSystem
74+
$this->ioFileSystem,
75+
$this->tmpDirectory
6876
);
6977
}
7078

@@ -79,9 +87,9 @@ public function tearDown()
7987
/**
8088
* @param string $class
8189
* @param array $methods
82-
* @return PHPUnit_Framework_MockObject_MockObject
90+
* @return \PHPUnit_Framework_MockObject_MockObject
8391
*/
84-
private function getMockObject(string $class, array $methods = []): PHPUnit_Framework_MockObject_MockObject
92+
protected function getMockObject($class, $methods = [])
8593
{
8694
$builder = $this->getMockBuilder($class)
8795
->disableOriginalConstructor();
@@ -95,7 +103,7 @@ private function getMockObject(string $class, array $methods = []): PHPUnit_Fram
95103
* Test for beforeSave method with invalid file extension.
96104
*
97105
* @expectedException \Magento\Framework\Exception\LocalizedException
98-
* @expectedExceptionMessage Something is wrong with the file upload settings.
106+
* @expectedExceptionMessage Invalid file provided.
99107
*/
100108
public function testBeforeSaveWithInvalidExtensionFile()
101109
{

lib/internal/Magento/Framework/Filesystem/Driver/File.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@
1313
use Magento\Framework\Filesystem\Glob;
1414

1515
/**
16-
* Class File
16+
* Class File for Filesystem Driver
1717
*
18-
* @package Magento\Framework\Filesystem\Driver
1918
* @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
2019
*/
2120
class File implements DriverInterface
@@ -593,13 +592,19 @@ public function fileOpen($path, $mode)
593592
*/
594593
public function fileReadLine($resource, $length, $ending = null)
595594
{
596-
$result = @stream_get_line($resource, $length, $ending);
597-
if (false === $result) {
595+
try {
596+
$result = @stream_get_line($resource, $length, $ending);
597+
if (false === $result) {
598+
throw new FileSystemException(
599+
new \Magento\Framework\Phrase('File cannot be read %1', [$this->getWarningMessage()])
600+
);
601+
}
602+
return $result;
603+
} catch (\Exception $e) {
598604
throw new FileSystemException(
599605
new \Magento\Framework\Phrase('File cannot be read %1', [$this->getWarningMessage()])
600606
);
601607
}
602-
return $result;
603608
}
604609

605610
/**

0 commit comments

Comments
 (0)