CsvTest::testWrite()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 24
rs 9.7
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\Csv;
8
use ApplicationTest\Traits\TestWithTransaction;
9
10
class CsvTest extends AbstractWriter
11
{
12
    use TestWithTransaction;
13
14
    public function testWrite(): void
15
    {
16
        global $container;
17
18
        /** @var Csv $writer */
19
        $writer = $container->get(Csv::class);
20
        $tempFile = tempnam('data/tmp/', 'csv');
21
22
        $this->export($writer, $tempFile);
23
24
        $file = fopen($tempFile, 'rb');
25
        $line1 = fgetcsv($file, escape: '\\');
26
        $line2 = fgetcsv($file, escape: '\\');
27
        $line3 = fgetcsv($file, escape: '\\');
28
        fclose($file);
29
        unlink($tempFile);
30
31
        self::assertSame('Id', $line1[0]);
32
        self::assertSame('test with nothing', $line2[1]);
33
        self::assertSame('test with stuff', $line3[1]);
34
        self::assertSame('• period', $line3[4]);
35
        self::assertSame('country', $line3[7]);
36
        self::assertSame('document type', $line3[11]);
37
        self::assertSame('building', $line3[16]);
38
    }
39
}
40