mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-27 07:58:33 +00:00
ec4098c8fd
While we might never be able to have 100% of our code strict, we can at the very least do it for all of our tests. This ensures that our tests are using our API with the types as intended by the test author, and not silently be cast to what our API requires.
72 lines
2.0 KiB
PHP
72 lines
2.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Database\DVarP;
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
|
|
|
|
class DVarPTest extends SetupTeardownDatabases
|
|
{
|
|
/**
|
|
* @dataProvider providerDVarP
|
|
*/
|
|
public function testDirectCallToDVarP(float|string $expectedResult, array $database, ?string $field, array $criteria): void
|
|
{
|
|
$result = DVarP::evaluate($database, $field, $criteria);
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerDVarP
|
|
*/
|
|
public function testDVarPAsWorksheetFormula(float|string $expectedResult, array $database, ?string $field, array $criteria): void
|
|
{
|
|
$this->prepareWorksheetWithFormula('DVARP', $database, $field, $criteria);
|
|
|
|
$result = $this->getSheet()->getCell(self::RESULT_CELL)->getCalculatedValue();
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
|
|
}
|
|
|
|
public static function providerDVarP(): array
|
|
{
|
|
return [
|
|
[
|
|
7.04,
|
|
self::database1(),
|
|
'Yield',
|
|
[
|
|
['Tree'],
|
|
['=Apple'],
|
|
['=Pear'],
|
|
],
|
|
],
|
|
[
|
|
0.025622222222,
|
|
self::database3FilledIn(),
|
|
'Score',
|
|
[
|
|
['Subject', 'Gender'],
|
|
['Math', 'Male'],
|
|
],
|
|
],
|
|
[
|
|
0.011622222222,
|
|
self::database3FilledIn(),
|
|
'Score',
|
|
[
|
|
['Subject', 'Age'],
|
|
['Science', '>8'],
|
|
],
|
|
],
|
|
'Omitted field name' => [
|
|
ExcelError::VALUE(),
|
|
self::database1(),
|
|
null,
|
|
self::database1(),
|
|
],
|
|
];
|
|
}
|
|
}
|