From 5a500f352734a22f8c0464d400130a8250a633e9 Mon Sep 17 00:00:00 2001 From: joweecaquicla Date: Tue, 11 Aug 2020 01:59:52 +0800 Subject: [PATCH 1/5] magento/adobe-stock-integration#1727: Introduce internal class wrapping SplFileInfo - implement class wrapping SplFileInfo and modified the files to use the newly added classes --- .../Model/CreateAssetFromFile.php | 14 +- .../Model/Filesystem/FileInfo.php | 296 ++++++++++++++++++ .../Model/Filesystem/GetFileInfo.php | 63 ++++ .../Model/GetAssetFromPath.php | 11 +- .../Model/SynchronizeFiles.php | 14 +- 5 files changed, 374 insertions(+), 24 deletions(-) create mode 100644 app/code/Magento/MediaGallerySynchronization/Model/Filesystem/FileInfo.php create mode 100644 app/code/Magento/MediaGallerySynchronization/Model/Filesystem/GetFileInfo.php diff --git a/app/code/Magento/MediaGallerySynchronization/Model/CreateAssetFromFile.php b/app/code/Magento/MediaGallerySynchronization/Model/CreateAssetFromFile.php index 87d477507b680..6f1f05a750085 100644 --- a/app/code/Magento/MediaGallerySynchronization/Model/CreateAssetFromFile.php +++ b/app/code/Magento/MediaGallerySynchronization/Model/CreateAssetFromFile.php @@ -16,7 +16,7 @@ use Magento\MediaGalleryApi\Api\Data\AssetInterface; use Magento\MediaGalleryApi\Api\Data\AssetInterfaceFactory; use Magento\MediaGalleryMetadataApi\Api\ExtractMetadataInterface; -use Magento\MediaGallerySynchronization\Model\Filesystem\SplFileInfoFactory; +use Magento\MediaGallerySynchronization\Model\Filesystem\GetFileInfo; use Magento\MediaGallerySynchronization\Model\GetContentHash; /** @@ -60,9 +60,9 @@ class CreateAssetFromFile private $extractMetadata; /** - * @var SplFileInfoFactory + * @var GetFileInfo */ - private $splFileInfoFactory; + private $getFileInfo; /** * @param Filesystem $filesystem @@ -71,7 +71,7 @@ class CreateAssetFromFile * @param AssetInterfaceFactory $assetFactory * @param GetContentHash $getContentHash * @param ExtractMetadataInterface $extractMetadata - * @param SplFileInfoFactory $splFileInfoFactory + * @param GetFileInfo $getFileInfo */ public function __construct( Filesystem $filesystem, @@ -80,7 +80,7 @@ public function __construct( AssetInterfaceFactory $assetFactory, GetContentHash $getContentHash, ExtractMetadataInterface $extractMetadata, - SplFileInfoFactory $splFileInfoFactory + GetFileInfo $getFileInfo ) { $this->filesystem = $filesystem; $this->driver = $driver; @@ -88,7 +88,7 @@ public function __construct( $this->assetFactory = $assetFactory; $this->getContentHash = $getContentHash; $this->extractMetadata = $extractMetadata; - $this->splFileInfoFactory = $splFileInfoFactory; + $this->getFileInfo = $getFileInfo; } /** @@ -101,7 +101,7 @@ public function __construct( public function execute(string $path): AssetInterface { $absolutePath = $this->getMediaDirectory()->getAbsolutePath($path); - $file = $this->splFileInfoFactory->create($absolutePath); + $file = $this->getFileInfo->execute($absolutePath); [$width, $height] = getimagesize($absolutePath); $metadata = $this->extractMetadata->execute($absolutePath); diff --git a/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/FileInfo.php b/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/FileInfo.php new file mode 100644 index 0000000000000..20acefe4ab034 --- /dev/null +++ b/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/FileInfo.php @@ -0,0 +1,296 @@ +path = $path; + $this->filename = $filename; + $this->extension = $extension; + $this->basename = $basename; + $this->pathname = $pathname; + $this->perms = $perms; + $this->inode = $inode; + $this->size = $size; + $this->owner = $owner; + $this->group = $group; + $this->aTime = $aTime; + $this->mTime = $mTime; + $this->cTime = $cTime; + $this->type = $type; + $this->realPath = $realPath; + $this->fileInfo = $fileInfo; + $this->pathInfo = $pathInfo; + } + + /** + * @inheritDoc + */ + public function getPath(): string + { + return $this->path; + } + + /** + * @inheritDoc + */ + public function getFilename(): string + { + return $this->filename; + } + + /** + * @inheritDoc + */ + public function getExtension(): string + { + return $this->extension; + } + + /** + * @inheritDoc + */ + public function getBasename($suffix = null): string + { + return $this->basename; + } + + /** + * @inheritDoc + */ + public function getPathname(): string + { + return $this->pathname; + } + + /** + * @inheritDoc + */ + public function getPerms(): int + { + return $this->perms; + } + + /** + * @inheritDoc + */ + public function getInode(): int + { + return $this->inode; + } + + /** + * @inheritDoc + */ + public function getSize(): int + { + return $this->size; + } + + /** + * @inheritDoc + */ + public function getOwner(): int + { + return $this->owner; + } + + /** + * @inheritDoc + */ + public function getGroup(): int + { + return $this->group; + } + + /** + * @inheritDoc + */ + public function getATime(): int + { + return $this->aTime; + } + + /** + * @inheritDoc + */ + public function getMTime(): int + { + return $this->mTime; + } + + /** + * @inheritDoc + */ + public function getCTime(): int + { + return $this->cTime; + } + + /** + * @inheritDoc + */ + public function getType(): string + { + return $this->type; + } + + /** + * @inheritDoc + */ + public function getRealPath() + { + return $this->realPath; + } + + /** + * @inheritDoc + */ + public function getFileInfo($class_name = null): \SplFileInfo + { + return $this->fileInfo; + } + + /** + * @inheritDoc + */ + public function getPathInfo($class_name = null): \SplFileInfo + { + return $this->pathInfo; + } +} diff --git a/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/GetFileInfo.php b/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/GetFileInfo.php new file mode 100644 index 0000000000000..ef382732275bd --- /dev/null +++ b/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/GetFileInfo.php @@ -0,0 +1,63 @@ +fileInfoFactory = $fileInfoFactory; + } + + /** + * Get file information based on path provided. + * + * @param string $path + * @return FileInfo + */ + public function execute(string $path): FileInfo + { + $splFileInfo = new \SplFileInfo($path); + + return $this->fileInfoFactory->create([ + 'file_name' => $path, + 'path' => $splFileInfo->getPath(), + 'filename' => $splFileInfo->getFilename(), + 'extension' => $splFileInfo->getExtension(), + 'basename' => $splFileInfo->getBasename(), + 'pathname' => $splFileInfo->getPathname(), + 'perms' => $splFileInfo->getPerms(), + 'inode' => $splFileInfo->getInode(), + 'size' => $splFileInfo->getSize(), + 'owner' => $splFileInfo->getOwner(), + 'group' => $splFileInfo->getGroup(), + 'aTime' => $splFileInfo->getATime(), + 'mTime' => $splFileInfo->getMTime(), + 'cTime' => $splFileInfo->getCTime(), + 'type' => $splFileInfo->getType(), + 'realPath' => $splFileInfo->getRealPath(), + 'fileInfo' => $splFileInfo->getFileInfo(), + 'pathInfo' => $splFileInfo->getPathInfo() + ]); + } +} diff --git a/app/code/Magento/MediaGallerySynchronization/Model/GetAssetFromPath.php b/app/code/Magento/MediaGallerySynchronization/Model/GetAssetFromPath.php index 5e825d57c5ce7..533d814c9f1d0 100644 --- a/app/code/Magento/MediaGallerySynchronization/Model/GetAssetFromPath.php +++ b/app/code/Magento/MediaGallerySynchronization/Model/GetAssetFromPath.php @@ -12,7 +12,6 @@ use Magento\MediaGalleryApi\Api\Data\AssetInterface; use Magento\MediaGalleryApi\Api\Data\AssetInterfaceFactory; use Magento\MediaGalleryApi\Api\GetAssetsByPathsInterface; -use Magento\MediaGallerySynchronization\Model\Filesystem\SplFileInfoFactory; /** * Create media asset object based on the file information @@ -34,27 +33,19 @@ class GetAssetFromPath */ private $createAssetFromFile; - /** - * @var SplFileInfoFactory - */ - private $splFileInfoFactory; - /** * @param AssetInterfaceFactory $assetFactory * @param GetAssetsByPathsInterface $getMediaGalleryAssetByPath * @param CreateAssetFromFile $createAssetFromFile - * @param SplFileInfoFactory $splFileInfoFactory */ public function __construct( AssetInterfaceFactory $assetFactory, GetAssetsByPathsInterface $getMediaGalleryAssetByPath, - CreateAssetFromFile $createAssetFromFile, - SplFileInfoFactory $splFileInfoFactory + CreateAssetFromFile $createAssetFromFile ) { $this->assetFactory = $assetFactory; $this->getAssetsByPaths = $getMediaGalleryAssetByPath; $this->createAssetFromFile = $createAssetFromFile; - $this->splFileInfoFactory= $splFileInfoFactory; } /** diff --git a/app/code/Magento/MediaGallerySynchronization/Model/SynchronizeFiles.php b/app/code/Magento/MediaGallerySynchronization/Model/SynchronizeFiles.php index 81e9629f703f3..eebb172e48202 100644 --- a/app/code/Magento/MediaGallerySynchronization/Model/SynchronizeFiles.php +++ b/app/code/Magento/MediaGallerySynchronization/Model/SynchronizeFiles.php @@ -16,7 +16,7 @@ use Magento\MediaGalleryApi\Api\GetAssetsByPathsInterface; use Magento\MediaGallerySynchronizationApi\Model\ImportFilesInterface; use Magento\MediaGallerySynchronizationApi\Api\SynchronizeFilesInterface; -use Magento\MediaGallerySynchronization\Model\Filesystem\SplFileInfoFactory; +use Magento\MediaGallerySynchronization\Model\Filesystem\GetFileInfo; use Psr\Log\LoggerInterface; /** @@ -50,9 +50,9 @@ class SynchronizeFiles implements SynchronizeFilesInterface private $driver; /** - * @var SplFileInfoFactory + * @var GetFileInfo */ - private $splFileInfoFactory; + private $getFileInfo; /** * @var ImportFilesInterface @@ -69,7 +69,7 @@ class SynchronizeFiles implements SynchronizeFilesInterface * @param Filesystem $filesystem * @param DateTime $date * @param LoggerInterface $log - * @param SplFileInfoFactory $splFileInfoFactory + * @param GetFileInfo $getFileInfo * @param GetAssetsByPathsInterface $getAssetsByPaths * @param ImportFilesInterface $importFiles */ @@ -78,7 +78,7 @@ public function __construct( Filesystem $filesystem, DateTime $date, LoggerInterface $log, - SplFileInfoFactory $splFileInfoFactory, + GetFileInfo $getFileInfo, GetAssetsByPathsInterface $getAssetsByPaths, ImportFilesInterface $importFiles ) { @@ -86,7 +86,7 @@ public function __construct( $this->filesystem = $filesystem; $this->date = $date; $this->log = $log; - $this->splFileInfoFactory = $splFileInfoFactory; + $this->getFileInfo = $getFileInfo; $this->getAssetsByPaths = $getAssetsByPaths; $this->importFiles = $importFiles; } @@ -150,7 +150,7 @@ private function getFileModificationTime(string $path): string { return $this->date->gmtDate( self::DATE_FORMAT, - $this->splFileInfoFactory->create($this->getMediaDirectory()->getAbsolutePath($path))->getMTime() + $this->getFileInfo->execute($this->getMediaDirectory()->getAbsolutePath($path))->getMTime() ); } From 9f02257226d4ac946c572ff4d23ce88ef5265fae Mon Sep 17 00:00:00 2001 From: joweecaquicla Date: Wed, 12 Aug 2020 01:37:46 +0800 Subject: [PATCH 2/5] magento/adobe-stock-integration#1727: Introduce internal class wrapping SplFileInfo - fix static and mftf fails, added integration tets --- .../Model/Filesystem/FileInfo.php | 55 +---------- .../Model/Filesystem/GetFileInfo.php | 6 +- .../Model/Filesystem/GetFileInfoTest.php | 94 +++++++++++++++++++ 3 files changed, 101 insertions(+), 54 deletions(-) create mode 100644 app/code/Magento/MediaGallerySynchronization/Test/Integration/Model/Filesystem/GetFileInfoTest.php diff --git a/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/FileInfo.php b/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/FileInfo.php index 20acefe4ab034..034ae7c0bff5a 100644 --- a/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/FileInfo.php +++ b/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/FileInfo.php @@ -8,7 +8,9 @@ namespace Magento\MediaGallerySynchronization\Model\Filesystem; /** - * Class FileInfo + * Internal class wrapping \SplFileInfo + * + * @SuppressWarnings(PHPMD.TooManyFields) */ class FileInfo extends \SplFileInfo { @@ -37,11 +39,6 @@ class FileInfo extends \SplFileInfo */ private $pathname; - /** - * @var int - */ - private $perms; - /** * @var int */ @@ -87,16 +84,6 @@ class FileInfo extends \SplFileInfo */ private $realPath; - /** - * @var \SplFileInfo - */ - private $fileInfo; - - /** - * @var \SplFileInfo - */ - private $pathInfo; - /** * FileInfo constructor. * @param string $file_name @@ -105,7 +92,6 @@ class FileInfo extends \SplFileInfo * @param string $extension * @param string $basename * @param string $pathname - * @param int $perms * @param int $inode * @param int $size * @param int $owner @@ -115,8 +101,7 @@ class FileInfo extends \SplFileInfo * @param int $cTime * @param string $type * @param false|string $realPath - * @param \SplFileInfo $fileInfo - * @param \SplFileInfo $pathInfo + * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( string $file_name, @@ -125,7 +110,6 @@ public function __construct( string $extension, string $basename, string $pathname, - int $perms, int $inode, int $size, int $owner, @@ -134,9 +118,7 @@ public function __construct( int $mTime, int $cTime, string $type, - $realPath, - \SplFileInfo $fileInfo, - \SplFileInfo $pathInfo + $realPath ) { parent::__construct($file_name); $this->path = $path; @@ -144,7 +126,6 @@ public function __construct( $this->extension = $extension; $this->basename = $basename; $this->pathname = $pathname; - $this->perms = $perms; $this->inode = $inode; $this->size = $size; $this->owner = $owner; @@ -154,8 +135,6 @@ public function __construct( $this->cTime = $cTime; $this->type = $type; $this->realPath = $realPath; - $this->fileInfo = $fileInfo; - $this->pathInfo = $pathInfo; } /** @@ -198,14 +177,6 @@ public function getPathname(): string return $this->pathname; } - /** - * @inheritDoc - */ - public function getPerms(): int - { - return $this->perms; - } - /** * @inheritDoc */ @@ -277,20 +248,4 @@ public function getRealPath() { return $this->realPath; } - - /** - * @inheritDoc - */ - public function getFileInfo($class_name = null): \SplFileInfo - { - return $this->fileInfo; - } - - /** - * @inheritDoc - */ - public function getPathInfo($class_name = null): \SplFileInfo - { - return $this->pathInfo; - } } diff --git a/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/GetFileInfo.php b/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/GetFileInfo.php index ef382732275bd..e2ffa39d0aba9 100644 --- a/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/GetFileInfo.php +++ b/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/GetFileInfo.php @@ -44,7 +44,7 @@ public function execute(string $path): FileInfo 'path' => $splFileInfo->getPath(), 'filename' => $splFileInfo->getFilename(), 'extension' => $splFileInfo->getExtension(), - 'basename' => $splFileInfo->getBasename(), + 'basename' => $splFileInfo->getBasename('.' . $splFileInfo->getExtension()), 'pathname' => $splFileInfo->getPathname(), 'perms' => $splFileInfo->getPerms(), 'inode' => $splFileInfo->getInode(), @@ -55,9 +55,7 @@ public function execute(string $path): FileInfo 'mTime' => $splFileInfo->getMTime(), 'cTime' => $splFileInfo->getCTime(), 'type' => $splFileInfo->getType(), - 'realPath' => $splFileInfo->getRealPath(), - 'fileInfo' => $splFileInfo->getFileInfo(), - 'pathInfo' => $splFileInfo->getPathInfo() + 'realPath' => $splFileInfo->getRealPath() ]); } } diff --git a/app/code/Magento/MediaGallerySynchronization/Test/Integration/Model/Filesystem/GetFileInfoTest.php b/app/code/Magento/MediaGallerySynchronization/Test/Integration/Model/Filesystem/GetFileInfoTest.php new file mode 100644 index 0000000000000..c88a6fe7d39d7 --- /dev/null +++ b/app/code/Magento/MediaGallerySynchronization/Test/Integration/Model/Filesystem/GetFileInfoTest.php @@ -0,0 +1,94 @@ +getFileInfo = Bootstrap::getObjectManager()->get(GetFileInfo::class); + } + + /** + * @dataProvider filesProvider + * @param string $file + */ + public function testExecute( + string $file + ): void { + + $path = $this->getImageFilePath($file); + + $fileInfo = $this->getFileInfo->execute($path); + $this->assertNotEmpty($fileInfo->getPath()); + $this->assertNotEmpty($fileInfo->getFilename()); + $this->assertNotEmpty($fileInfo->getExtension()); + $this->assertNotEmpty($fileInfo->getBasename()); + $this->assertNotEmpty($fileInfo->getPathname()); + $this->assertNotEmpty($fileInfo->getPerms()); + $this->assertNotEmpty($fileInfo->getInode()); + $this->assertNotEmpty($fileInfo->getSize()); + $this->assertNotEmpty($fileInfo->getOwner()); + $this->assertNotEmpty($fileInfo->getGroup()); + $this->assertNotEmpty($fileInfo->getATime()); + $this->assertNotEmpty($fileInfo->getMTime()); + $this->assertNotEmpty($fileInfo->getCTime()); + $this->assertNotEmpty($fileInfo->getType()); + $this->assertNotEmpty($fileInfo->getRealPath()); + + } + + /** + * Data provider for testExecute + * + * @return array[] + */ + public function filesProvider(): array + { + return [ + [ + 'magento.jpg', + 'magento_2.jpg' + ] + ]; + } + + /** + * Return image file path + * + * @param string $filename + * @return string + */ + private function getImageFilePath(string $filename): string + { + return dirname(__DIR__, 2) + . DIRECTORY_SEPARATOR + . implode( + DIRECTORY_SEPARATOR, + [ + '_files', + $filename + ] + ); + } +} From 0b6ba916edc17c9e6a231b7fb3598086c1c365c8 Mon Sep 17 00:00:00 2001 From: joweecaquicla Date: Wed, 12 Aug 2020 03:35:25 +0800 Subject: [PATCH 3/5] magento/adobe-stock-integration#1727: Introduce internal class wrapping SplFileInfo - fix static test --- .../Test/Integration/Model/Filesystem/GetFileInfoTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/code/Magento/MediaGallerySynchronization/Test/Integration/Model/Filesystem/GetFileInfoTest.php b/app/code/Magento/MediaGallerySynchronization/Test/Integration/Model/Filesystem/GetFileInfoTest.php index c88a6fe7d39d7..4031de4226105 100644 --- a/app/code/Magento/MediaGallerySynchronization/Test/Integration/Model/Filesystem/GetFileInfoTest.php +++ b/app/code/Magento/MediaGallerySynchronization/Test/Integration/Model/Filesystem/GetFileInfoTest.php @@ -55,7 +55,6 @@ public function testExecute( $this->assertNotEmpty($fileInfo->getCTime()); $this->assertNotEmpty($fileInfo->getType()); $this->assertNotEmpty($fileInfo->getRealPath()); - } /** From 89e7f22c2d86f2d281749774761d6dc6418e891b Mon Sep 17 00:00:00 2001 From: joweecaquicla Date: Thu, 13 Aug 2020 18:47:51 +0800 Subject: [PATCH 4/5] magento/adobe-stock-integration#1727: Introduce internal class wrapping SplFileInfo - apply requested changes --- .../Model/CreateAssetFromFile.php | 2 +- .../Model/Filesystem/FileInfo.php | 155 +++--------------- .../Model/Filesystem/GetFileInfo.php | 11 +- .../Model/Filesystem/GetFileInfoTest.php | 23 +-- 4 files changed, 36 insertions(+), 155 deletions(-) diff --git a/app/code/Magento/MediaGallerySynchronization/Model/CreateAssetFromFile.php b/app/code/Magento/MediaGallerySynchronization/Model/CreateAssetFromFile.php index 6f1f05a750085..b257c3da55c84 100644 --- a/app/code/Magento/MediaGallerySynchronization/Model/CreateAssetFromFile.php +++ b/app/code/Magento/MediaGallerySynchronization/Model/CreateAssetFromFile.php @@ -110,7 +110,7 @@ public function execute(string $path): AssetInterface [ 'id' => null, 'path' => $path, - 'title' => $metadata->getTitle() ?: $file->getBasename('.' . $file->getExtension()), + 'title' => $metadata->getTitle() ?: $file->getBasename(), 'description' => $metadata->getDescription(), 'createdAt' => $this->date->date($file->getCTime())->format(self::DATE_FORMAT), 'updatedAt' => $this->date->date($file->getMTime())->format(self::DATE_FORMAT), diff --git a/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/FileInfo.php b/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/FileInfo.php index 034ae7c0bff5a..5e523fd0e905a 100644 --- a/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/FileInfo.php +++ b/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/FileInfo.php @@ -8,11 +8,9 @@ namespace Magento\MediaGallerySynchronization\Model\Filesystem; /** - * Internal class wrapping \SplFileInfo - * - * @SuppressWarnings(PHPMD.TooManyFields) + * Class for getting image file information. */ -class FileInfo extends \SplFileInfo +class FileInfo { /** * @var string @@ -34,36 +32,11 @@ class FileInfo extends \SplFileInfo */ private $basename; - /** - * @var string - */ - private $pathname; - - /** - * @var int - */ - private $inode; - /** * @var int */ private $size; - /** - * @var int - */ - private $owner; - - /** - * @var int - */ - private $group; - - /** - * @var int - */ - private $aTime; - /** * @var int */ @@ -74,71 +47,39 @@ class FileInfo extends \SplFileInfo */ private $cTime; - /** - * @var string - */ - private $type; - - /** - * @var false|string - */ - private $realPath; - /** * FileInfo constructor. - * @param string $file_name + * * @param string $path * @param string $filename * @param string $extension * @param string $basename - * @param string $pathname - * @param int $inode * @param int $size - * @param int $owner - * @param int $group - * @param int $aTime * @param int $mTime * @param int $cTime - * @param string $type - * @param false|string $realPath - * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( - string $file_name, string $path, string $filename, string $extension, string $basename, - string $pathname, - int $inode, int $size, - int $owner, - int $group, - int $aTime, int $mTime, - int $cTime, - string $type, - $realPath + int $cTime ) { - parent::__construct($file_name); $this->path = $path; $this->filename = $filename; $this->extension = $extension; $this->basename = $basename; - $this->pathname = $pathname; - $this->inode = $inode; $this->size = $size; - $this->owner = $owner; - $this->group = $group; - $this->aTime = $aTime; $this->mTime = $mTime; $this->cTime = $cTime; - $this->type = $type; - $this->realPath = $realPath; } /** - * @inheritDoc + * Get path without filename. + * + * @return string */ public function getPath(): string { @@ -146,7 +87,9 @@ public function getPath(): string } /** - * @inheritDoc + * Get filename. + * + * @return string */ public function getFilename(): string { @@ -154,7 +97,9 @@ public function getFilename(): string } /** - * @inheritDoc + * Get file extension. + * + * @return string */ public function getExtension(): string { @@ -162,31 +107,19 @@ public function getExtension(): string } /** - * @inheritDoc + * Get file basename. + * + * @return string */ - public function getBasename($suffix = null): string + public function getBasename(): string { return $this->basename; } /** - * @inheritDoc - */ - public function getPathname(): string - { - return $this->pathname; - } - - /** - * @inheritDoc - */ - public function getInode(): int - { - return $this->inode; - } - - /** - * @inheritDoc + * Get file size. + * + * @return int */ public function getSize(): int { @@ -194,31 +127,9 @@ public function getSize(): int } /** - * @inheritDoc - */ - public function getOwner(): int - { - return $this->owner; - } - - /** - * @inheritDoc - */ - public function getGroup(): int - { - return $this->group; - } - - /** - * @inheritDoc - */ - public function getATime(): int - { - return $this->aTime; - } - - /** - * @inheritDoc + * Get last modified time. + * + * @return int */ public function getMTime(): int { @@ -226,26 +137,12 @@ public function getMTime(): int } /** - * @inheritDoc + * Get inode change time. + * + * @return int */ public function getCTime(): int { return $this->cTime; } - - /** - * @inheritDoc - */ - public function getType(): string - { - return $this->type; - } - - /** - * @inheritDoc - */ - public function getRealPath() - { - return $this->realPath; - } } diff --git a/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/GetFileInfo.php b/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/GetFileInfo.php index e2ffa39d0aba9..8f9080767d6e3 100644 --- a/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/GetFileInfo.php +++ b/app/code/Magento/MediaGallerySynchronization/Model/Filesystem/GetFileInfo.php @@ -40,22 +40,13 @@ public function execute(string $path): FileInfo $splFileInfo = new \SplFileInfo($path); return $this->fileInfoFactory->create([ - 'file_name' => $path, 'path' => $splFileInfo->getPath(), 'filename' => $splFileInfo->getFilename(), 'extension' => $splFileInfo->getExtension(), 'basename' => $splFileInfo->getBasename('.' . $splFileInfo->getExtension()), - 'pathname' => $splFileInfo->getPathname(), - 'perms' => $splFileInfo->getPerms(), - 'inode' => $splFileInfo->getInode(), 'size' => $splFileInfo->getSize(), - 'owner' => $splFileInfo->getOwner(), - 'group' => $splFileInfo->getGroup(), - 'aTime' => $splFileInfo->getATime(), 'mTime' => $splFileInfo->getMTime(), - 'cTime' => $splFileInfo->getCTime(), - 'type' => $splFileInfo->getType(), - 'realPath' => $splFileInfo->getRealPath() + 'cTime' => $splFileInfo->getCTime() ]); } } diff --git a/app/code/Magento/MediaGallerySynchronization/Test/Integration/Model/Filesystem/GetFileInfoTest.php b/app/code/Magento/MediaGallerySynchronization/Test/Integration/Model/Filesystem/GetFileInfoTest.php index 4031de4226105..cc9b70e623d9f 100644 --- a/app/code/Magento/MediaGallerySynchronization/Test/Integration/Model/Filesystem/GetFileInfoTest.php +++ b/app/code/Magento/MediaGallerySynchronization/Test/Integration/Model/Filesystem/GetFileInfoTest.php @@ -40,21 +40,14 @@ public function testExecute( $path = $this->getImageFilePath($file); $fileInfo = $this->getFileInfo->execute($path); - $this->assertNotEmpty($fileInfo->getPath()); - $this->assertNotEmpty($fileInfo->getFilename()); - $this->assertNotEmpty($fileInfo->getExtension()); - $this->assertNotEmpty($fileInfo->getBasename()); - $this->assertNotEmpty($fileInfo->getPathname()); - $this->assertNotEmpty($fileInfo->getPerms()); - $this->assertNotEmpty($fileInfo->getInode()); - $this->assertNotEmpty($fileInfo->getSize()); - $this->assertNotEmpty($fileInfo->getOwner()); - $this->assertNotEmpty($fileInfo->getGroup()); - $this->assertNotEmpty($fileInfo->getATime()); - $this->assertNotEmpty($fileInfo->getMTime()); - $this->assertNotEmpty($fileInfo->getCTime()); - $this->assertNotEmpty($fileInfo->getType()); - $this->assertNotEmpty($fileInfo->getRealPath()); + $expectedResult = new \SplFileInfo($path); + $this->assertEquals($expectedResult->getPath(), $fileInfo->getPath()); + $this->assertEquals($expectedResult->getFilename(), $fileInfo->getFilename()); + $this->assertEquals($expectedResult->getExtension(), $fileInfo->getExtension()); + $this->assertEquals($expectedResult->getBasename('.' . $expectedResult->getExtension()), $fileInfo->getBasename()); + $this->assertEquals($expectedResult->getSize(), $fileInfo->getSize()); + $this->assertEquals($expectedResult->getMTime(), $fileInfo->getMTime()); + $this->assertEquals($expectedResult->getCTime(), $fileInfo->getCTime()); } /** From beae26b45c3a175121bd4c0b307b94d513571997 Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Fri, 14 Aug 2020 10:16:54 +0100 Subject: [PATCH 5/5] Fixed static test --- .../Test/Integration/Model/Filesystem/GetFileInfoTest.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/MediaGallerySynchronization/Test/Integration/Model/Filesystem/GetFileInfoTest.php b/app/code/Magento/MediaGallerySynchronization/Test/Integration/Model/Filesystem/GetFileInfoTest.php index cc9b70e623d9f..6b1e8a676d02b 100644 --- a/app/code/Magento/MediaGallerySynchronization/Test/Integration/Model/Filesystem/GetFileInfoTest.php +++ b/app/code/Magento/MediaGallerySynchronization/Test/Integration/Model/Filesystem/GetFileInfoTest.php @@ -44,7 +44,10 @@ public function testExecute( $this->assertEquals($expectedResult->getPath(), $fileInfo->getPath()); $this->assertEquals($expectedResult->getFilename(), $fileInfo->getFilename()); $this->assertEquals($expectedResult->getExtension(), $fileInfo->getExtension()); - $this->assertEquals($expectedResult->getBasename('.' . $expectedResult->getExtension()), $fileInfo->getBasename()); + $this->assertEquals( + $expectedResult->getBasename('.' . $expectedResult->getExtension()), + $fileInfo->getBasename() + ); $this->assertEquals($expectedResult->getSize(), $fileInfo->getSize()); $this->assertEquals($expectedResult->getMTime(), $fileInfo->getMTime()); $this->assertEquals($expectedResult->getCTime(), $fileInfo->getCTime());