Skip to content

Commit 9f02257

Browse files
author
joweecaquicla
committed
magento/adobe-stock-integration#1727: Introduce internal class wrapping SplFileInfo - fix static and mftf fails, added integration tets
1 parent bc24c44 commit 9f02257

File tree

3 files changed

+101
-54
lines changed

3 files changed

+101
-54
lines changed

app/code/Magento/MediaGallerySynchronization/Model/Filesystem/FileInfo.php

Lines changed: 5 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
namespace Magento\MediaGallerySynchronization\Model\Filesystem;
99

1010
/**
11-
* Class FileInfo
11+
* Internal class wrapping \SplFileInfo
12+
*
13+
* @SuppressWarnings(PHPMD.TooManyFields)
1214
*/
1315
class FileInfo extends \SplFileInfo
1416
{
@@ -37,11 +39,6 @@ class FileInfo extends \SplFileInfo
3739
*/
3840
private $pathname;
3941

40-
/**
41-
* @var int
42-
*/
43-
private $perms;
44-
4542
/**
4643
* @var int
4744
*/
@@ -87,16 +84,6 @@ class FileInfo extends \SplFileInfo
8784
*/
8885
private $realPath;
8986

90-
/**
91-
* @var \SplFileInfo
92-
*/
93-
private $fileInfo;
94-
95-
/**
96-
* @var \SplFileInfo
97-
*/
98-
private $pathInfo;
99-
10087
/**
10188
* FileInfo constructor.
10289
* @param string $file_name
@@ -105,7 +92,6 @@ class FileInfo extends \SplFileInfo
10592
* @param string $extension
10693
* @param string $basename
10794
* @param string $pathname
108-
* @param int $perms
10995
* @param int $inode
11096
* @param int $size
11197
* @param int $owner
@@ -115,8 +101,7 @@ class FileInfo extends \SplFileInfo
115101
* @param int $cTime
116102
* @param string $type
117103
* @param false|string $realPath
118-
* @param \SplFileInfo $fileInfo
119-
* @param \SplFileInfo $pathInfo
104+
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
120105
*/
121106
public function __construct(
122107
string $file_name,
@@ -125,7 +110,6 @@ public function __construct(
125110
string $extension,
126111
string $basename,
127112
string $pathname,
128-
int $perms,
129113
int $inode,
130114
int $size,
131115
int $owner,
@@ -134,17 +118,14 @@ public function __construct(
134118
int $mTime,
135119
int $cTime,
136120
string $type,
137-
$realPath,
138-
\SplFileInfo $fileInfo,
139-
\SplFileInfo $pathInfo
121+
$realPath
140122
) {
141123
parent::__construct($file_name);
142124
$this->path = $path;
143125
$this->filename = $filename;
144126
$this->extension = $extension;
145127
$this->basename = $basename;
146128
$this->pathname = $pathname;
147-
$this->perms = $perms;
148129
$this->inode = $inode;
149130
$this->size = $size;
150131
$this->owner = $owner;
@@ -154,8 +135,6 @@ public function __construct(
154135
$this->cTime = $cTime;
155136
$this->type = $type;
156137
$this->realPath = $realPath;
157-
$this->fileInfo = $fileInfo;
158-
$this->pathInfo = $pathInfo;
159138
}
160139

161140
/**
@@ -198,14 +177,6 @@ public function getPathname(): string
198177
return $this->pathname;
199178
}
200179

201-
/**
202-
* @inheritDoc
203-
*/
204-
public function getPerms(): int
205-
{
206-
return $this->perms;
207-
}
208-
209180
/**
210181
* @inheritDoc
211182
*/
@@ -277,20 +248,4 @@ public function getRealPath()
277248
{
278249
return $this->realPath;
279250
}
280-
281-
/**
282-
* @inheritDoc
283-
*/
284-
public function getFileInfo($class_name = null): \SplFileInfo
285-
{
286-
return $this->fileInfo;
287-
}
288-
289-
/**
290-
* @inheritDoc
291-
*/
292-
public function getPathInfo($class_name = null): \SplFileInfo
293-
{
294-
return $this->pathInfo;
295-
}
296251
}

app/code/Magento/MediaGallerySynchronization/Model/Filesystem/GetFileInfo.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function execute(string $path): FileInfo
4444
'path' => $splFileInfo->getPath(),
4545
'filename' => $splFileInfo->getFilename(),
4646
'extension' => $splFileInfo->getExtension(),
47-
'basename' => $splFileInfo->getBasename(),
47+
'basename' => $splFileInfo->getBasename('.' . $splFileInfo->getExtension()),
4848
'pathname' => $splFileInfo->getPathname(),
4949
'perms' => $splFileInfo->getPerms(),
5050
'inode' => $splFileInfo->getInode(),
@@ -55,9 +55,7 @@ public function execute(string $path): FileInfo
5555
'mTime' => $splFileInfo->getMTime(),
5656
'cTime' => $splFileInfo->getCTime(),
5757
'type' => $splFileInfo->getType(),
58-
'realPath' => $splFileInfo->getRealPath(),
59-
'fileInfo' => $splFileInfo->getFileInfo(),
60-
'pathInfo' => $splFileInfo->getPathInfo()
58+
'realPath' => $splFileInfo->getRealPath()
6159
]);
6260
}
6361
}
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\MediaGallerySynchronization\Test\Integration\Model\Filesystem;
9+
10+
use Magento\MediaGallerySynchronization\Model\Filesystem\GetFileInfo;
11+
use Magento\TestFramework\Helper\Bootstrap;
12+
use PHPUnit\Framework\TestCase;
13+
14+
/**
15+
* Integration test for GetFileInfo
16+
*/
17+
class GetFileInfoTest extends TestCase
18+
{
19+
/**
20+
* @var GetFileInfo
21+
*/
22+
private $getFileInfo;
23+
24+
/**
25+
* @inheritdoc
26+
*/
27+
protected function setUp(): void
28+
{
29+
$this->getFileInfo = Bootstrap::getObjectManager()->get(GetFileInfo::class);
30+
}
31+
32+
/**
33+
* @dataProvider filesProvider
34+
* @param string $file
35+
*/
36+
public function testExecute(
37+
string $file
38+
): void {
39+
40+
$path = $this->getImageFilePath($file);
41+
42+
$fileInfo = $this->getFileInfo->execute($path);
43+
$this->assertNotEmpty($fileInfo->getPath());
44+
$this->assertNotEmpty($fileInfo->getFilename());
45+
$this->assertNotEmpty($fileInfo->getExtension());
46+
$this->assertNotEmpty($fileInfo->getBasename());
47+
$this->assertNotEmpty($fileInfo->getPathname());
48+
$this->assertNotEmpty($fileInfo->getPerms());
49+
$this->assertNotEmpty($fileInfo->getInode());
50+
$this->assertNotEmpty($fileInfo->getSize());
51+
$this->assertNotEmpty($fileInfo->getOwner());
52+
$this->assertNotEmpty($fileInfo->getGroup());
53+
$this->assertNotEmpty($fileInfo->getATime());
54+
$this->assertNotEmpty($fileInfo->getMTime());
55+
$this->assertNotEmpty($fileInfo->getCTime());
56+
$this->assertNotEmpty($fileInfo->getType());
57+
$this->assertNotEmpty($fileInfo->getRealPath());
58+
59+
}
60+
61+
/**
62+
* Data provider for testExecute
63+
*
64+
* @return array[]
65+
*/
66+
public function filesProvider(): array
67+
{
68+
return [
69+
[
70+
'magento.jpg',
71+
'magento_2.jpg'
72+
]
73+
];
74+
}
75+
76+
/**
77+
* Return image file path
78+
*
79+
* @param string $filename
80+
* @return string
81+
*/
82+
private function getImageFilePath(string $filename): string
83+
{
84+
return dirname(__DIR__, 2)
85+
. DIRECTORY_SEPARATOR
86+
. implode(
87+
DIRECTORY_SEPARATOR,
88+
[
89+
'_files',
90+
$filename
91+
]
92+
);
93+
}
94+
}

0 commit comments

Comments
 (0)