AbstractZipAdapterTest.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Common\Tests\Adapter\Zip;
  3. use PhpOffice\Common\Tests\TestHelperZip;
  4. abstract class AbstractZipAdapterTest extends \PHPUnit\Framework\TestCase
  5. {
  6. protected $zipTest;
  7. /**
  8. * Returns a new instance of the adapter to test
  9. * @return \PhpOffice\Common\Adapter\Zip\ZipInterface
  10. */
  11. abstract protected function createAdapter();
  12. public function setUp()
  13. {
  14. parent::setUp();
  15. $pathResources = PHPOFFICE_COMMON_TESTS_BASE_DIR.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'files'.DIRECTORY_SEPARATOR;
  16. $this->zipTest = tempnam(sys_get_temp_dir(), 'PhpOfficeCommon');
  17. copy($pathResources.'Sample_01_Simple.pptx', $this->zipTest);
  18. }
  19. public function tearDown()
  20. {
  21. parent::tearDown();
  22. if (is_file($this->zipTest)) {
  23. unlink($this->zipTest);
  24. }
  25. }
  26. public function testOpen()
  27. {
  28. $adapter = $this->createAdapter();
  29. $this->assertSame($adapter, $adapter->open($this->zipTest));
  30. }
  31. public function testClose()
  32. {
  33. $adapter = $this->createAdapter();
  34. $adapter->open($this->zipTest);
  35. $this->assertSame($adapter, $adapter->close());
  36. }
  37. public function testAddFromString()
  38. {
  39. $expectedPath = 'file.test';
  40. $expectedContent = 'Content';
  41. $adapter = $this->createAdapter();
  42. $adapter->open($this->zipTest);
  43. $this->assertSame($adapter, $adapter->addFromString($expectedPath, $expectedContent));
  44. $adapter->close();
  45. $this->assertTrue(TestHelperZip::assertFileExists($this->zipTest, $expectedPath));
  46. $this->assertTrue(TestHelperZip::assertFileContent($this->zipTest, $expectedPath, $expectedContent));
  47. }
  48. }