Failed Conditions
Pull Request — master (#3962)
by Owen
11:35
created

HtmlArrayTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 33
c 1
b 0
f 0
dl 0
loc 41
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testArray() 0 19 1
A testInlineArrays() 0 18 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpOffice\PhpSpreadsheetTests\Writer\Html;
6
7
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
8
use PhpOffice\PhpSpreadsheet\Spreadsheet;
9
use PhpOffice\PhpSpreadsheetTests\Functional\AbstractFunctional;
10
11
class HtmlArrayTest extends AbstractFunctional
12
{
13
    public function testArray(): void
14
    {
15
        $spreadsheet = new Spreadsheet();
16
        Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY);
17
        $sheet = $spreadsheet->getActiveSheet();
18
        $sheet->getCell('A1')->setValue(1);
19
        $sheet->getCell('A2')->setValue(1);
20
        $sheet->getCell('A3')->setValue(3);
21
        $sheet->getCell('B1')->setValue('=UNIQUE(A1:A3)');
22
        $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Html');
23
        $sheet = $reloadedSpreadsheet->getActiveSheet();
24
        self::assertEquals('1', $sheet->getCell('A1')->getValue());
25
        self::assertEquals('1', $sheet->getCell('A2')->getValue());
26
        self::assertEquals('3', $sheet->getCell('A3')->getValue());
27
        self::assertEquals('1', $sheet->getCell('B1')->getValue());
28
        self::assertEquals('3', $sheet->getCell('B2')->getValue());
29
        self::assertNull($sheet->getCell('B3')->getValue());
30
        $spreadsheet->disconnectWorksheets();
31
        $reloadedSpreadsheet->disconnectWorksheets();
32
    }
33
34
    public function testInlineArrays(): void
35
    {
36
        $spreadsheet = new Spreadsheet();
37
        Calculation::getInstance($spreadsheet)->setInstanceArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY);
38
        $sheet = $spreadsheet->getActiveSheet();
39
        $sheet->getCell('A1')->setValue('=UNIQUE({1;1;2;1;3;2;4;4;4})');
40
        $sheet->getCell('D1')->setValue('=UNIQUE({1,1,2,1,3,2,4,4,4},true)');
41
        $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, 'Csv');
42
        $sheet = $reloadedSpreadsheet->getActiveSheet();
43
        $expected = [
44
            ['1', null, null, '1', '2', '3', '4'],
45
            ['2', null, null, null, null, null, null],
46
            ['3', null, null, null, null, null, null],
47
            ['4', null, null, null, null, null, null],
48
        ];
49
        self::assertSame($expected, $sheet->toArray());
50
        $spreadsheet->disconnectWorksheets();
51
        $reloadedSpreadsheet->disconnectWorksheets();
52
    }
53
}
54