ZipTest   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 17
c 0
b 0
f 0
dl 0
loc 29
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A testWrite() 0 25 1
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