![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/vendor/magento/module-media-storage/Test/Unit/Model/File/Storage/ |
<?php /** * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ declare(strict_types=1); namespace Magento\MediaStorage\Test\Unit\Model\File\Storage; use Exception; use Magento\Framework\Exception\LocalizedException; use Magento\Framework\Stdlib\DateTime\DateTime; use Magento\MediaStorage\Helper\File\Media; use Magento\MediaStorage\Helper\File\Storage\Database; use Magento\MediaStorage\Model\File\Storage\File; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; /** Unit tests for \Magento\MediaStorage\Model\File\Storage\File class */ class FileTest extends TestCase { /** * @var File */ private $file; /** * @var Media */ private $loggerMock; /** * @var Database */ private $storageHelperMock; /** * @var DateTime */ private $mediaHelperMock; /** * @var \Magento\MediaStorage\Model\ResourceModel\File\Storage\File */ private $fileUtilityMock; protected function setUp(): void { $this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class); $this->storageHelperMock = $this->createMock(Database::class); $this->mediaHelperMock = $this->createMock(Media::class); $this->fileUtilityMock = $this->createMock(\Magento\MediaStorage\Model\ResourceModel\File\Storage\File::class); $this->file = new File( $this->loggerMock, $this->storageHelperMock, $this->mediaHelperMock, $this->fileUtilityMock ); } protected function tearDown(): void { unset($this->file); } public function testSaveFileWithWrongFileFormat(): void { $this->expectException(LocalizedException::class); $this->expectExceptionMessage('Wrong file info format'); $this->file->saveFile([]); } public function testSaveFileUnsuccessfullyWithMissingDirectory(): void { $this->fileUtilityMock ->expects($this->once()) ->method('saveFile') ->willThrowException(new Exception()); $this->expectException(LocalizedException::class); $this->expectExceptionMessage('Unable to save file "filename.ext" at "filename.ext"'); $this->file->saveFile([ 'filename' => 'filename.ext', 'content' => 'content', ]); } public function testSaveFileUnsuccessfullyWithoutMissingDirectory(): void { $this->fileUtilityMock ->expects($this->once()) ->method('saveFile') ->willThrowException(new Exception()); $this->expectException(LocalizedException::class); $this->expectExceptionMessage('Unable to save file "filename.ext" at "directory/filename.ext"'); $this->file->saveFile([ 'directory' => 'directory', 'filename' => 'filename.ext', 'content' => 'content', ]); } }