BugHonorFileTimeTest.php 877 B

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