1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical; |
6
|
|
|
|
7
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet; |
8
|
|
|
|
9
|
|
|
class CountATest extends AllSetupTeardown |
10
|
|
|
{ |
11
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providerCOUNTA')] |
12
|
|
|
public function testCOUNTA(mixed $expectedResult, mixed ...$args): void |
13
|
|
|
{ |
14
|
|
|
$this->runTestCases('COUNTA', $expectedResult, ...$args); |
15
|
|
|
} |
16
|
|
|
|
17
|
|
|
public static function providerCOUNTA(): array |
18
|
|
|
{ |
19
|
|
|
return require 'tests/data/Calculation/Statistical/COUNTA.php'; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function testNull(): void |
23
|
|
|
{ |
24
|
|
|
$spreadsheet = new Spreadsheet(); |
25
|
|
|
$sheet = $spreadsheet->getActiveSheet(); |
26
|
|
|
$sheet->setCellValue('A1', '=COUNTA(B1,B2,B3,B4)'); |
27
|
|
|
$sheet->setCellValue('A2', '=COUNTA(B1,,B3,B4)'); |
28
|
|
|
$sheet->setCellValue('A3', '=COUNTA(B1,B2,B3,B4)'); |
29
|
|
|
self::assertSame(0, $sheet->getCell('A1')->getCalculatedValue(), 'empty cells not counted'); |
30
|
|
|
self::assertSame(1, $sheet->getCell('A2')->getCalculatedValue(), 'null argument is counted'); |
31
|
|
|
self::assertSame(0, $sheet->getCell('A3')->getCalculatedValue(), 'empty cells still not counted'); |
32
|
|
|
$spreadsheet->disconnectWorksheets(); |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|