Completed
Push — develop ( 148bee...a089a8 )
by Adrien
32:42
created

TypeAttributePreservationTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 43
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A providerFormulae() 0 13 3
A testFormulae() 0 18 2
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Functional;
4
5
use PhpOffice\PhpSpreadsheet\Spreadsheet;
6
7
class TypeAttributePreservationTest extends AbstractFunctional
8
{
9
    public function providerFormulae()
10
    {
11
        $formats = ['Xlsx'];
12
        $data = require 'data/Functional/TypeAttributePreservation/Formula.php';
13
14
        $result = [];
15
        foreach ($formats as $f) {
16
            foreach ($data as $d) {
17
                $result[] = [$f, $d];
18
            }
19
        }
20
21
        return $result;
22
    }
23
24
    /**
25
     * Ensure saved spreadsheets maintain the correct data type.
26
     *
27
     * @dataProvider providerFormulae
28
     *
29
     * @param string $format
30
     * @param array $values
31
     */
32
    public function testFormulae($format, array $values)
33
    {
34
        $spreadsheet = new Spreadsheet();
35
        $sheet = $spreadsheet->getActiveSheet();
36
        $sheet->fromArray($values);
37
38
        $reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $format);
39
        $reloadedSheet = $reloadedSpreadsheet->getActiveSheet();
40
41
        $expected = $sheet->getCell('A1')->getCalculatedValue();
42
43
        if ($sheet->getCell('A1')->getDataType() === 'f') {
44
            $actual = $reloadedSheet->getCell('A1')->getOldCalculatedValue();
45
        } else {
46
            $actual = $reloadedSheet->getCell('A1')->getValue();
47
        }
48
49
        self::assertSame($expected, $actual);
50
    }
51
}
52