summaryrefslogtreecommitdiffstats
path: root/vendor/maennchen/zipstream-php/test/bug/BugHonorFileTimeTest.php
blob: 05de4fe269f778d477efbc72b9a8aadbca905432 (plain) (blame)
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
<?php

declare(strict_types=1);

namespace BugHonorFileTimeTest;

use DateTime;

use function fopen;

use PHPUnit\Framework\TestCase;
use ZipStream\Option\Archive;
use ZipStream\Option\File;

use ZipStream\ZipStream;

/**
 * Asserts that specified last-modified timestamps are not overwritten when a
 * file is added
 */
class BugHonorFileTimeTest extends TestCase
{
    public function testHonorsFileTime(): void
    {
        $archiveOpt = new Archive();
        $fileOpt = new File();
        $expectedTime = new DateTime('2019-04-21T19:25:00-0800');

        $archiveOpt->setOutputStream(fopen('php://memory', 'wb'));
        $fileOpt->setTime(clone $expectedTime);

        $zip = new ZipStream(null, $archiveOpt);

        $zip->addFile('sample.txt', 'Sample', $fileOpt);

        $zip->finish();

        $this->assertEquals($expectedTime, $fileOpt->getTime());
    }
}