-
Notifications
You must be signed in to change notification settings - Fork 58
/
AbstractZipAdapter.php
66 lines (53 loc) · 1.85 KB
/
AbstractZipAdapter.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
namespace PhpOffice\Common\Tests\Adapter\Zip;
use PhpOffice\Common\Adapter\Zip\ZipInterface;
use PhpOffice\Common\Tests\TestHelperZip;
abstract class AbstractZipAdapter extends \PHPUnit\Framework\TestCase
{
/**
* @var string
*/
protected $zipTest;
/**
* Returns a new instance of the adapter to test
*
* @return \PhpOffice\Common\Adapter\Zip\ZipInterface
*/
abstract protected function createAdapter(): ZipInterface;
public function setUp(): void
{
parent::setUp();
$pathResources = PHPOFFICE_COMMON_TESTS_BASE_DIR . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
$this->zipTest = tempnam(sys_get_temp_dir(), 'PhpOfficeCommon');
copy($pathResources . 'Sample_01_Simple.pptx', $this->zipTest);
}
public function tearDown(): void
{
parent::tearDown();
if (is_file($this->zipTest)) {
unlink($this->zipTest);
}
}
public function testOpen(): void
{
$adapter = $this->createAdapter();
$this->assertSame($adapter, $adapter->open($this->zipTest));
}
public function testClose(): void
{
$adapter = $this->createAdapter();
$adapter->open($this->zipTest);
$this->assertSame($adapter, $adapter->close());
}
public function testAddFromString(): void
{
$expectedPath = 'file.test';
$expectedContent = 'Content';
$adapter = $this->createAdapter();
$adapter->open($this->zipTest);
$this->assertSame($adapter, $adapter->addFromString($expectedPath, $expectedContent));
$adapter->close();
$this->assertTrue(TestHelperZip::assertFileExists($this->zipTest, $expectedPath));
$this->assertTrue(TestHelperZip::assertFileContent($this->zipTest, $expectedPath, $expectedContent));
}
}