Skip to content

Commit 4dff0e6

Browse files
committed
B2B-2048: [AWS S3] ImportExport can't unzip file from AWS S3
1 parent ad2c576 commit 4dff0e6

File tree

3 files changed

+84
-0
lines changed

3 files changed

+84
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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\Framework\Archive;
9+
10+
use Magento\Framework\App\Filesystem\DirectoryList;
11+
use Magento\Framework\Exception\FileSystemException;
12+
use Magento\Framework\Filesystem;
13+
use Magento\TestFramework\Helper\Bootstrap;
14+
use PHPUnit\Framework\TestCase;
15+
16+
/**
17+
* Tests for Zip packing and unpacking
18+
*/
19+
class ZipTest extends TestCase
20+
{
21+
/**
22+
* @var Zip
23+
*/
24+
private $zip;
25+
26+
/**
27+
* @var Filesystem\Directory\WriteInterface
28+
*/
29+
private $directory;
30+
31+
protected function setUp(): void
32+
{
33+
$this->zip = Bootstrap::getObjectManager()->get(Zip::class);
34+
$filesystem = Bootstrap::getObjectManager()->get(Filesystem::class);
35+
$this->directory = $filesystem->getDirectoryWrite(DirectoryList::VAR_IMPORT_EXPORT);
36+
}
37+
38+
protected function tearDown(): void
39+
{
40+
foreach (['test.txt', 'test.zip'] as $file) {
41+
$this->directory->delete($file);
42+
}
43+
}
44+
45+
/**
46+
* @throws FileSystemException
47+
*/
48+
public function testPack()
49+
{
50+
$driver = $this->directory->getDriver();
51+
$driver->filePutContents(
52+
$this->directory->getAbsolutePath('test.txt'),
53+
file_get_contents(__DIR__ . '/_files/test.txt')
54+
);
55+
56+
$this->zip->pack(
57+
$this->directory->getAbsolutePath('test.txt'),
58+
$this->directory->getAbsolutePath('test.zip')
59+
);
60+
61+
self::assertTrue($this->directory->isFile('test.zip'));
62+
}
63+
64+
/**
65+
* @throws FileSystemException
66+
*/
67+
public function testUnpack()
68+
{
69+
$driver = $this->directory->getDriver();
70+
$driver->filePutContents(
71+
$this->directory->getAbsolutePath('test.zip'),
72+
file_get_contents(__DIR__ . '/_files/test.zip')
73+
);
74+
75+
$this->zip->unpack(
76+
$this->directory->getAbsolutePath('test.zip'),
77+
$this->directory->getAbsolutePath('test.txt')
78+
);
79+
80+
self::assertTrue($this->directory->isFile('test.txt'));
81+
self::assertEquals("test file\n", $this->directory->readFile('test.txt'));
82+
}
83+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test file
Binary file not shown.

0 commit comments

Comments
 (0)