Passed
Pull Request — master (#3234)
by Mark
13:39
created

DCountATest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 3
eloc 29
c 0
b 0
f 0
dl 0
loc 78
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testDCountAAsWorksheetFormula() 0 6 1
A testDirectCallToDCountA() 0 4 1
A providerDCountA() 0 46 1
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database;
4
5
use PhpOffice\PhpSpreadsheet\Calculation\Database\DCountA;
6
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
7
8
class DCountATest extends AllSetupTeardown
9
{
10
    /**
11
     * @dataProvider providerDCountA
12
     *
13
     * @param mixed $expectedResult
14
     * @param mixed $database
15
     * @param mixed $field
16
     * @param mixed $criteria
17
     */
18
    public function testDirectCallToDCountA($expectedResult, $database, $field, $criteria): void
19
    {
20
        $result = DCountA::evaluate($database, $field, $criteria);
21
        self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
22
    }
23
24
    /**
25
     * @dataProvider providerDCountA
26
     *
27
     * @param mixed $expectedResult
28
     * @param mixed $database
29
     * @param mixed $field
30
     * @param mixed $criteria
31
     */
32
    public function testDCountAAsWorksheetFormula($expectedResult, $database, $field, $criteria): void
33
    {
34
        $this->prepareWorksheetWithFormula('DCOUNTA', $database, $field, $criteria);
35
36
        $result = $this->getSheet()->getCell(self::RESULT_CELL)->getCalculatedValue();
37
        self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
38
    }
39
40
    public function providerDCountA(): array
41
    {
42
        return [
43
            [
44
                1,
45
                $this->database1(),
46
                'Profit',
47
                [
48
                    ['Tree', 'Height', 'Height'],
49
                    ['=Apple', '>10', '<16'],
50
                ],
51
            ],
52
            [
53
                2,
54
                $this->database3(),
55
                'Score',
56
                [
57
                    ['Subject', 'Gender'],
58
                    ['Science', 'Male'],
59
                ],
60
            ],
61
            [
62
                1,
63
                $this->database3(),
64
                'Score',
65
                [
66
                    ['Subject', 'Gender'],
67
                    ['Math', 'Female'],
68
                ],
69
            ],
70
            [
71
                3,
72
                $this->database3(),
73
                'Score',
74
                [
75
                    ['Subject', 'Score'],
76
                    ['English', '>60%'],
77
                ],
78
            ],
79
            'invalid field name' => [
80
                ExcelError::VALUE(),
81
                $this->database3(),
82
                'Scorex',
83
                [
84
                    ['Subject', 'Score'],
85
                    ['English', '>60%'],
86
                ],
87
            ],
88
        ];
89
    }
90
}
91