Files
MarkBaker 6fd24cad58 Refactor database tests to execute the test itself and check assertions in the main test function, not in the base class
Test both the function implementation (directly), and when the function is called in a formula from a spreadsheet
Replace error strings in expected result for providers with the value returned from the ExcelErrors class
2022-12-08 12:49:19 +01:00

80 lines
2.2 KiB
PHP

<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database;
use PhpOffice\PhpSpreadsheet\Calculation\Database\DVarP;
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
class DVarPTest extends AllSetupTeardown
{
/**
* @dataProvider providerDVarP
*
* @param mixed $expectedResult
* @param mixed $database
* @param mixed $field
* @param mixed $criteria
*/
public function testDirectCallToDVarP($expectedResult, $database, $field, $criteria): void
{
$result = DVarP::evaluate($database, $field, $criteria);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
}
/**
* @dataProvider providerDVarP
*
* @param mixed $expectedResult
* @param mixed $database
* @param mixed $field
* @param mixed $criteria
*/
public function testDVarPAsWorksheetFormula($expectedResult, $database, $field, $criteria): void
{
$this->prepareWorksheetWithFormula('DVARP', $database, $field, $criteria);
$result = $this->getSheet()->getCell(self::RESULT_CELL)->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
}
public function providerDVarP(): array
{
return [
[
7.04,
$this->database1(),
'Yield',
[
['Tree'],
['=Apple'],
['=Pear'],
],
],
[
0.025622222222,
$this->database3FilledIn(),
'Score',
[
['Subject', 'Gender'],
['Math', 'Male'],
],
],
[
0.011622222222,
$this->database3FilledIn(),
'Score',
[
['Subject', 'Age'],
['Science', '>8'],
],
],
'Omitted field name' => [
ExcelError::VALUE(),
$this->database1(),
null,
$this->database1(),
],
];
}
}