mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-24 17:28:15 +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.
48 lines
1.6 KiB
PHP
48 lines
1.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException;
|
|
|
|
class AverageIfTest extends AllSetupTeardown
|
|
{
|
|
/**
|
|
* @dataProvider providerAVERAGEIF
|
|
*/
|
|
public function testAVERAGEIF(mixed $expectedResult, mixed ...$args): void
|
|
{
|
|
$this->runTestCaseNoBracket('AVERAGEIF', $expectedResult, ...$args);
|
|
}
|
|
|
|
public static function providerAVERAGEIF(): array
|
|
{
|
|
return require 'tests/data/Calculation/Statistical/AVERAGEIF.php';
|
|
}
|
|
|
|
public function testOutliers(): void
|
|
{
|
|
$sheet = $this->getSheet();
|
|
$sheet->getCell('C1')->setValue(5);
|
|
$sheet->getCell('A1')->setValue('=AVERAGEIF(5,"<32")');
|
|
|
|
try {
|
|
$sheet->getCell('A1')->getCalculatedValue();
|
|
self::fail('Should receive exception for non-array arg');
|
|
} catch (CalcException $e) {
|
|
self::assertStringContainsString('Must specify range of cells', $e->getMessage());
|
|
}
|
|
$sheet->getCell('A2')->setValue('=AVERAGEIF({5},"<32")');
|
|
|
|
try {
|
|
$sheet->getCell('A2')->getCalculatedValue();
|
|
self::fail('Should receive exception for literal array arg');
|
|
} catch (CalcException $e) {
|
|
self::assertStringContainsString('Must specify range of cells', $e->getMessage());
|
|
}
|
|
$sheet->getCell('A3')->setValue('=AVERAGEIF(C1,"<32")');
|
|
self::assertSame(5, $sheet->getCell('A3')->getCalculatedValue(), 'first arg is single cell');
|
|
}
|
|
}
|