BugHonorFileTimeTest.php 865 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. declare(strict_types=1);
  3. namespace BugHonorFileTimeTest;
  4. use DateTime;
  5. use PHPUnit\Framework\TestCase;
  6. use ZipStream\Option\{
  7. Archive,
  8. File
  9. };
  10. use ZipStream\ZipStream;
  11. use function fopen;
  12. /**
  13. * Asserts that specified last-modified timestamps are not overwritten when a
  14. * file is added
  15. */
  16. class BugHonorFileTimeTest extends TestCase
  17. {
  18. public function testHonorsFileTime(): void
  19. {
  20. $archiveOpt = new Archive();
  21. $fileOpt = new File();
  22. $expectedTime = new DateTime('2019-04-21T19:25:00-0800');
  23. $archiveOpt->setOutputStream(fopen('php://memory', 'wb'));
  24. $fileOpt->setTime(clone $expectedTime);
  25. $zip = new ZipStream(null, $archiveOpt);
  26. $zip->addFile('sample.txt', 'Sample', $fileOpt);
  27. $zip->finish();
  28. $this->assertEquals($expectedTime, $fileOpt->getTime());
  29. }
  30. }