Skip to content

Commit f50a148

Browse files
committed
B2B-2036: [AWS S3] [Integration Tests]: Investigate Test Failures in MediaGalleryRenditions module
1 parent 227cf92 commit f50a148

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

app/code/Magento/MediaGalleryRenditions/Model/GenerateRenditions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private function createResizedRendition(string $absolutePath, string $absoluteRe
205205
*/
206206
private function shouldFileBeResized(string $absolutePath): bool
207207
{
208-
[$width, $height] = getimagesize($absolutePath);
208+
[$width, $height] = getimagesizefromstring($this->getMediaDirectory()->readFile($absolutePath));
209209
return $width > $this->config->getWidth() || $height > $this->config->getHeight();
210210
}
211211

app/code/Magento/MediaGalleryRenditions/Test/Integration/Model/GenerateRenditionsTest.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ protected function setup(): void
6363
$this->mediaDirectory = $this->objectManager->get(Filesystem::class)
6464
->getDirectoryWrite(DirectoryList::MEDIA);
6565
$this->mediaDirectory->create(self::TEST_DIR);
66-
$this->driver = $this->objectManager->get(DriverInterface::class);
66+
$this->driver = $this->mediaDirectory->getDriver();
6767
$this->renditionSizeConfig = $this->objectManager->get(Config::class);
6868
$config = $this->objectManager->get(ScopeConfigInterface::class);
6969
$this->origConfigValue = $config->getValue(
@@ -114,10 +114,9 @@ public static function tearDownAfterClass(): void
114114
public function testExecute(string $path, string $renditionPath): void
115115
{
116116
$this->copyImage($path);
117-
$this->generateRenditions->execute([self::TEST_DIR . '/' . $path]);
118-
$expectedRenditionPath = $this->mediaDirectory->getAbsolutePath($renditionPath);
119-
list($imageWidth, $imageHeight) = getimagesize($expectedRenditionPath);
120-
$this->assertFileExists($expectedRenditionPath);
117+
$this->generateRenditions->execute([self::TEST_DIR . $path]);
118+
list($imageWidth, $imageHeight) = getimagesizefromstring($this->mediaDirectory->readFile($renditionPath));
119+
$this->assertTrue($this->mediaDirectory->isExist($renditionPath));
121120
$this->assertLessThanOrEqual(
122121
$this->renditionSizeConfig->getWidth(),
123122
$imageWidth,
@@ -136,11 +135,11 @@ public function testExecute(string $path, string $renditionPath): void
136135
*/
137136
private function copyImage(string $path): void
138137
{
139-
$imagePath = realpath(__DIR__ . '/../../_files' . $path);
140-
$modifiableFilePath = $this->mediaDirectory->getAbsolutePath(self::TEST_DIR . $path );
141-
$this->driver->copy(
142-
$imagePath,
143-
$modifiableFilePath
138+
$imagePath = realpath(__DIR__ . '/../../_files/' . $path);
139+
$modifiableFilePath = $this->mediaDirectory->getAbsolutePath(self::TEST_DIR . $path);
140+
$this->driver->filePutContents(
141+
$modifiableFilePath,
142+
file_get_contents($imagePath)
144143
);
145144
}
146145

app/code/Magento/MediaGalleryRenditions/Test/Integration/Model/GetRenditionPathTest.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ protected function setup(): void
3939
$this->getRenditionPath = Bootstrap::getObjectManager()->get(GetRenditionPathInterface::class);
4040
$this->mediaDirectory = Bootstrap::getObjectManager()->get(Filesystem::class)
4141
->getDirectoryWrite(DirectoryList::MEDIA);
42-
$this->driver = Bootstrap::getObjectManager()->get(DriverInterface::class);
42+
$this->driver = $this->mediaDirectory->getDriver();
4343
}
4444

4545
/**
@@ -51,9 +51,10 @@ public function testExecute(string $path, string $expectedRenditionPath): void
5151
{
5252
$imagePath = realpath(__DIR__ . '/../../_files' . $path);
5353
$modifiableFilePath = $this->mediaDirectory->getAbsolutePath($path);
54-
$this->driver->copy(
55-
$imagePath,
56-
$modifiableFilePath
54+
$this->mediaDirectory->create(dirname($path));
55+
$this->driver->filePutContents(
56+
$modifiableFilePath,
57+
file_get_contents($imagePath)
5758
);
5859
$this->assertEquals($expectedRenditionPath, $this->getRenditionPath->execute($path));
5960
}

0 commit comments

Comments
 (0)