ZipTest::testWrite()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
c 0
b 0
f 0
dl 0
loc 25
rs 9.7666
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace ApplicationTest\Service\Exporter;
6
7
use Application\Service\Exporter\Zip;
8
use ApplicationTest\Traits\TestWithTransaction;
9
use ZipArchive;
10
11
class ZipTest extends AbstractWriter
12
{
13
    use TestWithTransaction;
14
15
    public function testWrite(): void
16
    {
17
        global $container;
18
19
        /** @var Zip $writer */
20
        $writer = $container->get(Zip::class);
21
        $tempFile = tempnam('data/tmp/', 'zip');
22
23
        $this->export($writer, $tempFile);
24
25
        // Assert that it is a valid ZIP file to prevent PhpSpreadsheet from hanging
26
        $zip = new ZipArchive();
27
        $res = $zip->open($tempFile, ZipArchive::CHECKCONS);
28
        self::assertTrue($res, 'exported file should be a valid ZIP file');
29
30
        self::assertNotFalse($zip->getFromName('111.html'), 'should contain an image');
31
        self::assertNotFalse($zip->getFromName('222.html'), 'should contain an image');
32
        self::assertNotFalse($zip->getFromName('222.jpg'), 'should contain an image');
33
34
        $actual = $zip->getFromName('222.html');
35
        self::assertStringContainsString('test with stuff', $actual);
36
        self::assertStringContainsString('expanded', $actual);
37
38
        $zip->close();
39
        unlink($tempFile);
40
    }
41
}
42