Skip to content

Commit cac4c37

Browse files
committed
B2B-2060: getimagesize() warning on tests when using remote storage AWS S3
1 parent b2cd0c1 commit cac4c37

File tree

2 files changed

+23
-11
lines changed
  • app/code/Magento/Catalog/Model/Webapi/Product/Option/Type/File
  • dev/tests/integration/testsuite/Magento/Catalog/Model/Webapi/Product/Option/Type/File

2 files changed

+23
-11
lines changed

app/code/Magento/Catalog/Model/Webapi/Product/Option/Type/File/Processor.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,19 @@ public function processFileContent(ImageContentInterface $imageContent)
5858
{
5959
$filePath = $this->saveFile($imageContent);
6060

61-
$fileAbsolutePath = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath($filePath);
62-
$fileHash = hash('sha256', $this->filesystem->getDirectoryRead(DirectoryList::MEDIA)->readFile($filePath));
63-
$imageSize = getimagesize($fileAbsolutePath);
61+
$directory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
62+
$fileAbsolutePath = $directory->getAbsolutePath($filePath);
63+
$fileContent = $directory->readFile($filePath);
64+
$fileHash = hash('sha256', $fileContent);
65+
$imageSize = getimagesizefromstring($fileContent);
66+
$stat = $directory->stat($fileAbsolutePath);
6467
$result = [
6568
'type' => $imageContent->getType(),
6669
'title' => $imageContent->getName(),
6770
'fullpath' => $fileAbsolutePath,
6871
'quote_path' => $filePath,
6972
'order_path' => $filePath,
70-
'size' => filesize($fileAbsolutePath),
73+
'size' => $stat['size'],
7174
'width' => $imageSize ? $imageSize[0] : 0,
7275
'height' => $imageSize ? $imageSize[1] : 0,
7376
'secret_key' => substr($fileHash, 0, 20),

dev/tests/integration/testsuite/Magento/Catalog/Model/Webapi/Product/Option/Type/File/ProcessorTest.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,32 @@ public function testProcessFileContent($pathConfig)
2929
$imageContent = $this->objectManager->create(
3030
\Magento\Framework\Api\Data\ImageContentInterface::class
3131
);
32+
$fileExpectedParams = [
33+
'type' => 'image/png',
34+
'title' => 'my_file',
35+
'size' => 212,
36+
'width' => 10,
37+
'height' => 10,
38+
];
3239
$imageContent->setName('my_file');
3340
$imageContent->setType('image/png');
3441
$imageContent->setBase64EncodedData($this->getImageContent());
3542
$result = $model->processFileContent($imageContent);
3643

37-
$this->assertArrayHasKey('fullpath', $result);
38-
$this->assertFileExists($result['fullpath']);
39-
4044
/** @var $filesystem \Magento\Framework\Filesystem */
4145
$filesystem = $this->objectManager->get(\Magento\Framework\Filesystem::class);
46+
$directory = $filesystem->getDirectoryRead(DirectoryList::MEDIA);
47+
$this->assertArrayHasKey('fullpath', $result);
48+
$this->assertEmpty(array_diff_assoc($fileExpectedParams, $result), 'Some file parameters are not correct');
49+
$this->assertTrue($directory->isExist($result['fullpath']));
50+
4251
$this->assertArrayHasKey('quote_path', $result);
43-
$filePath = $filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath($result['quote_path']);
44-
$this->assertFileExists($filePath);
52+
$filePath = $directory->getAbsolutePath($result['quote_path']);
53+
$this->assertTrue($directory->isExist($filePath));
4554

4655
$this->assertArrayHasKey('order_path', $result);
47-
$filePath = $filesystem->getDirectoryRead(DirectoryList::MEDIA)->getAbsolutePath($result['order_path']);
48-
$this->assertFileExists($filePath);
56+
$filePath = $directory->getAbsolutePath($result['order_path']);
57+
$this->assertTrue($directory->isExist($filePath));
4958
}
5059

5160
public function pathConfigDataProvider()

0 commit comments

Comments
 (0)