Files
PhpSpreadsheet/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/ModeTest.php
T
Adrien Crivelli 1b05dfab8b Rector AddParamTypeBasedOnPHPUnitDataProviderRector
And quite a bit more manual changes. The idea is that typing of our
tests can be a bit more loose, so we assume PHPDoc is mostly correct. If
that happens to be wrong, it should be caught by the tests themselves.
2023-09-07 17:00:24 +08:00

41 lines
1.2 KiB
PHP

<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;
class ModeTest extends TestCase
{
/**
* @dataProvider providerMODE
*/
public function testMODE(mixed $expectedResult, string $str): void
{
$workbook = new Spreadsheet();
$sheet = $workbook->getActiveSheet();
$row = 1;
$sheet->setCellValue("B$row", "=MODE($str)");
$sheet->setCellValue("C$row", "=MODE.SNGL($str)");
self::assertEquals($expectedResult, $sheet->getCell("B$row")->getCalculatedValue());
self::assertEquals($expectedResult, $sheet->getCell("C$row")->getCalculatedValue());
}
public static function providerMODE(): array
{
return require 'tests/data/Calculation/Statistical/MODE.php';
}
public function testMODENoArgs(): void
{
$this->expectException(\PhpOffice\PhpSpreadsheet\Calculation\Exception::class);
$workbook = new Spreadsheet();
$sheet = $workbook->getActiveSheet();
$sheet->setCellValue('B1', '=MODE()');
self::assertEquals('#N/A', $sheet->getCell('B1')->getCalculatedValue());
}
}