Skip to content

Commit df9654b

Browse files
committed
B2B:2037:[AWS S3] [Integration Tests]: Investigate Test Failures in MediaGallerySynchronization & MediaGallerySynchronizationMetadata modules
- Added static fixes
1 parent 95404ef commit df9654b

File tree

3 files changed

+40
-40
lines changed

3 files changed

+40
-40
lines changed

app/code/Magento/MediaGalleryMetadata/Model/Gif/ReadFile.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class ReadFile implements ReadFileInterface
5151
private $segmentNames;
5252

5353
/**
54-
* @param DriverInterface $driver
5554
* @param FileInterfaceFactory $fileFactory
5655
* @param SegmentInterfaceFactory $segmentFactory
5756
* @param SegmentNames $segmentNames
@@ -68,7 +67,6 @@ public function __construct(
6867
$this->segmentNames = $segmentNames;
6968
$this->filesystem = $filesystem;
7069
$this->driver = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA)->getDriver();
71-
7270
}
7371

7472
/**

app/code/Magento/MediaGalleryMetadata/Model/Jpeg/ReadFile.php

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
use Magento\MediaGalleryMetadataApi\Model\SegmentInterfaceFactory;
2222

2323
/**
24-
* Jpeg file reader.
24+
* Jpeg file reader
2525
*/
2626
class ReadFile implements ReadFileInterface
2727
{
@@ -79,7 +79,27 @@ public function __construct(
7979
}
8080

8181
/**
82-
* {@inheritdoc}
82+
* Is reader applicable
83+
*
84+
* @param string $path
85+
* @return bool
86+
* @throws FileSystemException
87+
*/
88+
private function isApplicable(string $path): bool
89+
{
90+
$resource = $this->driver->fileOpen($path, 'rb');
91+
try {
92+
$marker = $this->readMarker($resource);
93+
} catch (LocalizedException $exception) {
94+
return false;
95+
}
96+
$this->driver->fileClose($resource);
97+
98+
return $marker == self::MARKER_IMAGE_FILE_START;
99+
}
100+
101+
/**
102+
* @inheritdoc
83103
*/
84104
public function execute(string $path): FileInterface
85105
{
@@ -90,7 +110,7 @@ public function execute(string $path): FileInterface
90110
$resource = $this->driver->fileOpen($path, 'rb');
91111
$marker = $this->readMarker($resource);
92112

93-
if (self::MARKER_IMAGE_FILE_START != $marker) {
113+
if ($marker != self::MARKER_IMAGE_FILE_START) {
94114
$this->driver->fileClose($resource);
95115

96116
throw new ValidatorException(__('Not a JPEG image'));
@@ -99,56 +119,37 @@ public function execute(string $path): FileInterface
99119
do {
100120
$marker = $this->readMarker($resource);
101121
$segments[] = $this->readSegment($resource, ord($marker));
102-
} while ((self::MARKER_IMAGE_START != $marker) && (!$this->driver->endOfFile($resource)));
122+
} while (($marker != self::MARKER_IMAGE_START) && (!$this->driver->endOfFile($resource)));
103123

104-
if (self::MARKER_IMAGE_START != $marker) {
124+
if ($marker != self::MARKER_IMAGE_START) {
105125
throw new LocalizedException(__('File is corrupted'));
106126
}
107127

108128
$segments[] = $this->segmentFactory->create([
109129
'name' => 'CompressedImage',
110-
'data' => $this->readCompressedImage($resource),
130+
'data' => $this->readCompressedImage($resource)
111131
]);
112132

113133
$this->driver->fileClose($resource);
114134

115135
return $this->fileFactory->create([
116136
'path' => $path,
117-
'segments' => $segments,
137+
'segments' => $segments
118138
]);
119139
}
120140

121141
/**
122-
* Is reader applicable.
123-
*
124-
* @throws FileSystemException
125-
*/
126-
private function isApplicable(string $path): bool
127-
{
128-
$resource = $this->driver->fileOpen($path, 'rb');
129-
130-
try {
131-
$marker = $this->readMarker($resource);
132-
} catch (LocalizedException $exception) {
133-
return false;
134-
}
135-
$this->driver->fileClose($resource);
136-
137-
return self::MARKER_IMAGE_FILE_START == $marker;
138-
}
139-
140-
/**
141-
* Read jpeg marker.
142+
* Read jpeg marker
142143
*
143144
* @param resource $resource
144-
*
145+
* @return string
145146
* @throws FileSystemException
146147
*/
147148
private function readMarker($resource): string
148149
{
149150
$data = $this->read($resource, self::TWO_BYTES);
150151

151-
if (self::MARKER_PREFIX != $data[0]) {
152+
if ($data[0] != self::MARKER_PREFIX) {
152153
$this->driver->fileClose($resource);
153154

154155
throw new LocalizedException(__('File is corrupted'));
@@ -158,10 +159,10 @@ private function readMarker($resource): string
158159
}
159160

160161
/**
161-
* Read compressed image.
162+
* Read compressed image
162163
*
163164
* @param resource $resource
164-
*
165+
* @return string
165166
* @throws FileSystemException
166167
*/
167168
private function readCompressedImage($resource): string
@@ -173,18 +174,19 @@ private function readCompressedImage($resource): string
173174

174175
$endOfImageMarkerPosition = strpos($compressedImage, self::MARKER_PREFIX.self::MARKER_IMAGE_END);
175176

176-
if (false !== $endOfImageMarkerPosition) {
177+
if ($endOfImageMarkerPosition !== false) {
177178
$compressedImage = substr($compressedImage, 0, $endOfImageMarkerPosition);
178179
}
179180

180181
return $compressedImage;
181182
}
182183

183184
/**
184-
* Read jpeg segment.
185+
* Read jpeg segment
185186
*
186187
* @param resource $resource
187-
*
188+
* @param int $segmentType
189+
* @return SegmentInterface
188190
* @throws FileSystemException
189191
*/
190192
private function readSegment($resource, int $segmentType): SegmentInterface
@@ -194,15 +196,16 @@ private function readSegment($resource, int $segmentType): SegmentInterface
194196

195197
return $this->segmentFactory->create([
196198
'name' => $this->segmentNames->getSegmentName($segmentType),
197-
'data' => $this->read($resource, $segmentSize),
199+
'data' => $this->read($resource, $segmentSize)
198200
]);
199201
}
200202

201203
/**
202-
* Read wrapper.
204+
* Read wrapper
203205
*
204206
* @param resource $resource
205-
*
207+
* @param int $length
208+
* @return string
206209
* @throws FileSystemException
207210
*/
208211
private function read($resource, int $length): string

dev/tests/integration/testsuite/Magento/MediaGallerySynchronizationMetadata/Model/SynchronizeFilesTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public function testExecute(
9191

9292
$loadedAssets = $this->getAssetsByPath->execute([$file])[0];
9393
$loadedKeywords = $this->getKeywords($loadedAssets) ?: null;
94-
pathinfo($loadedAssets->getTitle(), PATHINFO_FILENAME);
9594
$this->assertEquals($title, pathinfo($loadedAssets->getTitle(), PATHINFO_FILENAME));
9695
$this->assertEquals($description, $loadedAssets->getDescription());
9796
$this->assertEquals($keywords, $loadedKeywords);

0 commit comments

Comments
 (0)