Passed
Push — master ( c380b2...9239b3 )
by Adrien
10:06
created

SumIfTest::providerSUMIF()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
4
5
class SumIfTest extends AllSetupTeardown
6
{
7
    /**
8
     * @dataProvider providerSUMIF
9
     *
10
     * @param mixed $expectedResult
11
     * @param mixed $condition
12
     */
13
    public function testSUMIF2($expectedResult, array $array1, $condition, ?array $array2 = null): void
14
    {
15
        $this->mightHaveException($expectedResult);
16
        if ($expectedResult === 'incomplete') {
17
            self::markTestIncomplete('Raises formula error - researching solution');
18
        }
19
        $sheet = $this->sheet;
20
        $sheet->fromArray($array1, null, 'A1', true);
21
        $maxARow = count($array1);
22
        $firstArg = "A1:A$maxARow";
23
        //$secondArg = is_string($condition) ? "\"$condition\"" : $condition;
24
        $sheet->getCell('B1')->setValue($condition);
25
        $secondArg = 'B1';
26
        if (empty($array2)) {
27
            $sheet->getCell('D1')->setValue("=SUMIF($firstArg, $secondArg)");
28
        } else {
29
            $sheet->fromArray($array2, null, 'C1', true);
30
            $maxCRow = count($array2);
31
            $thirdArg = "C1:C$maxCRow";
32
            $sheet->getCell('D1')->setValue("=SUMIF($firstArg, $secondArg, $thirdArg)");
33
        }
34
        $result = $sheet->getCell('D1')->getCalculatedValue();
35
        self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
36
    }
37
38
    public function providerSUMIF()
39
    {
40
        return require 'tests/data/Calculation/MathTrig/SUMIF.php';
41
    }
42
}
43