mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-27 03:15:21 +00:00
ca1ff07fbe
* Fix Unintential Deprecated Calls in Tests - DATABASE I think it's best to install these before PR #3166. There are no changes to source code, only to test members which continue to inadvertently use calls to deprecated functions. * Fix deprecation Blocks Deprecated->deprecated, adjust see and comments * Fix Deliberate Deprecated Tests Add annotations. * Change Unit Tests to Run in Spreadsheet Context ... rather than as direct calls. The major difference is that specifying an invalid column should result in an Excel error, not null. Minor code changes were needed, including to Statistical/Conditional which sometimes calls Database. * Correct Some DocBlocks Null is no longer a possible output for most of these functions. * 2 Overlooked Tests Change to run in spreadsheet context. * T Function Should Return Null-String, not Null Fix it.
104 lines
2.9 KiB
PHP
104 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Database;
|
|
|
|
class DAverageTest extends AllSetupTeardown
|
|
{
|
|
/**
|
|
* @dataProvider providerDAverage
|
|
*
|
|
* @param mixed $expectedResult
|
|
* @param int|string $field
|
|
*/
|
|
public function testDAverage($expectedResult, array $database, $field, array $criteria): void
|
|
{
|
|
$this->runTestCase('DAVERAGE', $expectedResult, $database, $field, $criteria);
|
|
}
|
|
|
|
public function providerDAverage(): array
|
|
{
|
|
return [
|
|
[
|
|
12,
|
|
$this->database1(),
|
|
'Yield',
|
|
[
|
|
['Tree', 'Height'],
|
|
['=Apple', '>10'],
|
|
],
|
|
],
|
|
'numeric column, in this case referring to age' => [
|
|
13,
|
|
$this->database1(),
|
|
3,
|
|
$this->database1(),
|
|
],
|
|
[
|
|
268333.333333333333,
|
|
$this->database2(),
|
|
'Sales',
|
|
[
|
|
['Quarter', 'Sales Rep.'],
|
|
['>1', 'Tina'],
|
|
],
|
|
],
|
|
[
|
|
372500,
|
|
$this->database2(),
|
|
'Sales',
|
|
[
|
|
['Quarter', 'Area'],
|
|
['1', 'South'],
|
|
],
|
|
],
|
|
'null field' => [
|
|
'#VALUE!',
|
|
$this->database1(),
|
|
null,
|
|
$this->database1(),
|
|
],
|
|
'field unknown column' => [
|
|
'#VALUE!',
|
|
$this->database1(),
|
|
'xyz',
|
|
$this->database1(),
|
|
],
|
|
'multiple criteria, omit equal sign' => [
|
|
10.5,
|
|
$this->database1(),
|
|
'Yield',
|
|
[
|
|
['Tree', 'Height'],
|
|
['=Apple', '>10'],
|
|
['Pear'],
|
|
],
|
|
],
|
|
'multiple criteria for same field' => [
|
|
10,
|
|
$this->database1(),
|
|
'Yield',
|
|
[
|
|
['Tree', 'Height', 'Age', 'Height'],
|
|
['=Apple', '>10', null, '<16'],
|
|
],
|
|
],
|
|
/* Excel seems to return #NAME? when column number
|
|
is too high or too low. This makes so little sense
|
|
to me that I'm not going to bother coding that up,
|
|
content to return #VALUE! as an invalid name would */
|
|
'field column number too high' => [
|
|
'#VALUE!',
|
|
$this->database1(),
|
|
99,
|
|
$this->database1(),
|
|
],
|
|
'field column number too low' => [
|
|
'#VALUE!',
|
|
$this->database1(),
|
|
0,
|
|
$this->database1(),
|
|
],
|
|
];
|
|
}
|
|
}
|