repo stringlengths 7 63 | file_url stringlengths 81 284 | file_path stringlengths 5 200 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 15:02:33 2026-01-05 05:24:06 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/NetworkDaysTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/NetworkDaysTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\NetworkDays;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class NetworkDaysTest extends TestCase
{
#[DataProvider('providerNETWORKDAYS')]
public function testDirectCallToNETWORKDAYS(mixed $expectedResult, mixed ...$args): void
{
$result = NetworkDays::count(...$args);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerNETWORKDAYS')]
public function testNETWORKDAYSAsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=NETWORKDAYS({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerNETWORKDAYS')]
public function testNETWORKDAYSInWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=NETWORKDAYS({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public static function providerNETWORKDAYS(): array
{
return require 'tests/data/Calculation/DateTime/NETWORKDAYS.php';
}
#[DataProvider('providerUnhappyNETWORKDAYS')]
public function testNETWORKDAYSUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=NETWORKDAYS({$argumentCells})";
$this->expectException(\PhpOffice\PhpSpreadsheet\Calculation\Exception::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyNETWORKDAYS(): array
{
return [
['Formula Error: Wrong number of arguments for NETWORKDAYS() function'],
['Formula Error: Wrong number of arguments for NETWORKDAYS() function', '2001-01-01'],
];
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerNetWorkDaysArray')]
public function testNetWorkDaysArray(array $expectedResult, string $startDate, string $endDays, ?string $holidays): void
{
$calculation = Calculation::getInstance();
if ($holidays === null) {
$formula = "=NETWORKDAYS({$startDate}, {$endDays})";
} else {
$formula = "=NETWORKDAYS({$startDate}, {$endDays}, {$holidays})";
}
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerNetWorkDaysArray(): array
{
return [
'row vector #1' => [[[234, 233, 232]], '{"2022-02-01", "2022-02-02", "2022-02-03"}', '"2022-12-25"', null],
'column vector #1' => [[[234], [233], [232]], '{"2022-02-01"; "2022-02-02"; "2022-02-03"}', '"2022-12-25"', null],
'matrix #1' => [[[234, 233], [232, 231]], '{"2022-02-01", "2022-02-02"; "2022-02-03", "2022-02-04"}', '"2022-12-25"', null],
'row vector #2' => [[[234, -27]], '"2022-02-01"', '{"2022-12-25", "2021-12-25"}', null],
'column vector #2' => [[[234], [-27]], '"2022-02-01"', '{"2022-12-25"; "2021-12-25"}', null],
'row vector with Holiday' => [[[233, -27]], '"2022-02-01"', '{"2022-12-25", "2021-12-25"}', '{"2022-02-02"}'],
'row vector with Holidays' => [[[232, -27]], '"2022-02-01"', '{"2022-12-25", "2021-12-25"}', '{"2022-02-02", "2022-02-03"}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateDifTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateDifTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use DateTime;
use DateTimeImmutable;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Days;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Difference;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class DateDifTest extends TestCase
{
/** @param array<mixed>|int|string $expectedResult */
#[DataProvider('providerDATEDIF')]
public function testDirectCallToDATEDIF(array|int|string $expectedResult, string ...$args): void
{
$result = Difference::interval(...$args);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerDATEDIF')]
public function testDATEDIFAsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=DATEDIF({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerDATEDIF')]
public function testDATEDIFInWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=DATEDIF({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public static function providerDATEDIF(): array
{
return require 'tests/data/Calculation/DateTime/DATEDIF.php';
}
#[DataProvider('providerUnhappyDATEDIF')]
public function testDATEDIFUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=DATEDIF({$argumentCells})";
$this->expectException(CalculationException::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyDATEDIF(): array
{
return [
['Formula Error: Wrong number of arguments for DATEDIF() function', '2023-03-1'],
];
}
public function testDateObject(): void
{
$obj1 = new DateTime('2000-3-31');
$obj2 = new DateTimeImmutable('2000-2-29');
self::assertSame(31, Days::between($obj1, $obj2));
}
/** @param array<mixed> $expectedResult */
#[DataProvider('providerDateDifArray')]
public function testDateDifArray(array $expectedResult, string $startDate, string $endDate, ?string $methods): void
{
$calculation = Calculation::getInstance();
if ($methods === null) {
$formula = "=DATEDIF({$startDate}, {$endDate})";
} else {
$formula = "=DATEDIF({$startDate}, {$endDate}, {$methods})";
}
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
public static function providerDateDifArray(): array
{
return [
'row vector #1' => [[[364, 202, '#NUM!']], '{"2022-01-01", "2022-06-12", "2023-07-22"}', '"2022-12-31"', null],
'row vector #2' => [[['#NUM!', '#NUM!', 203]], '"2022-12-31"', '{"2022-01-01", "2022-06-12", "2023-07-22"}', null],
'column vector #1' => [[[364], [362], [359]], '{"2022-01-01"; "2022-01-03"; "2022-01-06"}', '"2022-12-31"', null],
'matrix #1' => [[[365, 266], [139, 1]], '{"2022-01-01", "2022-04-10"; "2022-08-15", "2022-12-31"}', '"2023-01-01"', null],
'column vector with methods' => [[[364, 11], [242, 7], [173, 5]], '{"2022-01-01"; "2022-05-03"; "2022-07-11"}', '"2022-12-31"', '{"D", "M"}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MonthTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MonthTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\DateParts;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class MonthTest extends TestCase
{
#[DataProvider('providerMONTH')]
public function testDirectCallToMONTH(mixed $expectedResultExcel, mixed ...$args): void
{
$result = DateParts::month(...$args);
self::assertSame($expectedResultExcel, $result);
}
#[DataProvider('providerMONTH')]
public function testMONTHAsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=MONTH({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerMONTH')]
public function testMONTHInWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=MONTH({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public static function providerMONTH(): array
{
return require 'tests/data/Calculation/DateTime/MONTH.php';
}
#[DataProvider('providerUnhappyMONTH')]
public function testMONTHUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=MONTH({$argumentCells})";
$this->expectException(CalculationException::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyMONTH(): array
{
return [
['Formula Error: Wrong number of arguments for MONTH() function'],
];
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerMonthArray')]
public function testMonthArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=MONTH({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerMonthArray(): array
{
return [
'row vector' => [[[1, 6, 1]], '{"2022-01-01", "2022-06-01", "2023-01-01"}'],
'column vector' => [[[1], [3], [6]], '{"2022-01-01"; "2022-03-01"; "2022-06-01"}'],
'matrix' => [[[1, 4], [8, 12]], '{"2022-01-01", "2022-04-01"; "2022-08-01", "2022-12-01"}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/IsoWeekNumTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/IsoWeekNumTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Week;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException;
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDate;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class IsoWeekNumTest extends TestCase
{
private int $excelCalendar;
protected function setUp(): void
{
parent::setUp();
$this->excelCalendar = SharedDate::getExcelCalendar();
}
protected function tearDown(): void
{
parent::tearDown();
SharedDate::setExcelCalendar($this->excelCalendar);
}
#[DataProvider('providerISOWEEKNUM')]
public function testDirectCallToISOWEEKNUM(mixed $expectedResult, mixed ...$args): void
{
$result = Week::isoWeekNumber(...$args);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerISOWEEKNUM')]
public function testISOWEEKNUMAsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=ISOWEEKNUM({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerISOWEEKNUM')]
public function testISOWEEKNUMInWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=ISOWEEKNUM({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public static function providerISOWEEKNUM(): array
{
return require 'tests/data/Calculation/DateTime/ISOWEEKNUM.php';
}
#[DataProvider('providerUnhappyISOWEEKNUM')]
public function testISOWEEKNUMUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=ISOWEEKNUM({$argumentCells})";
$this->expectException(CalculationException::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyISOWEEKNUM(): array
{
return [
['Formula Error: Wrong number of arguments for ISOWEEKNUM() function', 2023, 3],
];
}
#[DataProvider('providerISOWEEKNUM1904')]
public function testISOWEEKNUMWith1904Calendar(mixed $expectedResult, mixed ...$args): void
{
SharedDate::setExcelCalendar(SharedDate::CALENDAR_MAC_1904);
$result = Week::isoWeekNumber(...$args);
self::assertSame($expectedResult, $result);
}
public static function providerISOWEEKNUM1904(): array
{
return require 'tests/data/Calculation/DateTime/ISOWEEKNUM1904.php';
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerIsoWeekNumArray')]
public function testIsoWeekNumArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=ISOWEEKNUM({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerIsoWeekNumArray(): array
{
return [
'row vector' => [[[52, 23, 29]], '{"2022-01-01", "2022-06-12", "2023-07-22"}'],
'column vector' => [[[52], [13], [26]], '{"2023-01-01"; "2023-04-01"; "2023-07-01"}'],
'matrix' => [[[53, 52], [52, 52]], '{"2021-01-01", "2021-12-31"; "2023-01-01", "2023-12-31"}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EoMonthTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EoMonthTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use DateTimeInterface;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Month;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class EoMonthTest extends TestCase
{
private string $returnDateType;
protected function setUp(): void
{
parent::setUp();
$this->returnDateType = Functions::getReturnDateType();
}
protected function tearDown(): void
{
parent::tearDown();
Functions::setReturnDateType($this->returnDateType);
}
#[DataProvider('providerEOMONTH')]
public function testDirectCallToEOMONTH(mixed $expectedResult, mixed ...$args): void
{
$result = Month::lastDay(...$args);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerEOMONTH')]
public function testEOMONTHAsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=EOMONTH({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerEOMONTH')]
public function testEOMONTHInWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=EOMONTH({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public static function providerEOMONTH(): array
{
return require 'tests/data/Calculation/DateTime/EOMONTH.php';
}
#[DataProvider('providerUnhappyEOMONTH')]
public function testEOMONTHUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=EOMONTH({$argumentCells})";
$this->expectException(CalculationException::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyEOMONTH(): array
{
return [
['Formula Error: Wrong number of arguments for EOMONTH() function'],
['Formula Error: Wrong number of arguments for EOMONTH() function', 22669],
];
}
public function testEOMONTHtoUnixTimestamp(): void
{
Functions::setReturnDateType(Functions::RETURNDATE_UNIX_TIMESTAMP);
$result = Month::lastDay('2012-1-26', -1);
self::assertEquals(1325289600, $result);
}
public function testEOMONTHtoDateTimeObject(): void
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_DATETIME_OBJECT);
$result = Month::lastDay('2012-1-26', -1);
// Must return an object...
// ... of the correct type
self::assertInstanceOf(DateTimeInterface::class, $result);
// ... with the correct value
self::assertSame($result->format('d-M-Y'), '31-Dec-2011');
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerEoMonthArray')]
public function testEoMonthArray(array $expectedResult, string $dateValues, string $methods): void
{
$calculation = Calculation::getInstance();
$formula = "=EOMONTH({$dateValues}, {$methods})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerEoMonthArray(): array
{
return [
'row vector #1' => [[[44620, 44651, 45351]], '{"2022-01-01", "2022-02-12", "2024-01-15"}', '1'],
'column vector #1' => [[[44620], [44651], [45351]], '{"2022-01-01"; "2022-02-12"; "2024-01-15"}', '1'],
'matrix #1' => [[[44620, 44651], [44681, 45351]], '{"2022-01-01", "2022-02-12"; "2022-03-01", "2024-01-21"}', '1'],
'row vector #2' => [[[44592, 44620, 44651]], '"2022-02-12"', '{-1, 0, 1}'],
'column vector #2' => [[[44592], [44620], [44651]], '"2022-02-12"', '{-1; 0; 1}'],
'matrix #2' => [[[44592, 44620], [44651, 45351]], '"2022-02-12"', '{-1, 0; 1, 24}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TodayTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TodayTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use DateTimeImmutable;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Current;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\DateParts;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\TimeParts;
use PHPUnit\Framework\TestCase;
class TodayTest extends TestCase
{
private function assertions(DateTimeImmutable $dtStart, mixed $result): void
{
self::assertEquals($dtStart->format('Y'), DateParts::year($result));
self::assertEquals($dtStart->format('m'), DateParts::month($result));
self::assertEquals($dtStart->format('d'), DateParts::day($result));
self::assertEquals(0, TimeParts::hour($result));
self::assertEquals(0, TimeParts::minute($result));
self::assertEquals(0, TimeParts::second($result));
}
public function testDirectCallToToday(): void
{
// Loop to avoid rare edge case where first calculation
// and second do not take place in same second.
do {
$dtStart = new DateTimeImmutable();
$startSecond = $dtStart->format('s');
$result = Current::today();
$endSecond = (new DateTimeImmutable('now'))->format('s');
} while ($startSecond !== $endSecond);
$this->assertions($dtStart, $result);
}
public function testTodayAsFormula(): void
{
$calculation = Calculation::getInstance();
$formula = '=TODAY()';
// Loop to avoid rare edge case where first calculation
// and second do not take place in same second.
do {
$dtStart = new DateTimeImmutable();
$startSecond = $dtStart->format('s');
$result = $calculation->calculateFormula($formula);
$endSecond = (new DateTimeImmutable('now'))->format('s');
} while ($startSecond !== $endSecond);
$this->assertions($dtStart, $result);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use DateTimeInterface;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Date;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDate;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class DateTest extends TestCase
{
private int $excelCalendar;
private string $returnDateType;
protected function setUp(): void
{
parent::setUp();
$this->excelCalendar = SharedDate::getExcelCalendar();
$this->returnDateType = Functions::getReturnDateType();
}
protected function tearDown(): void
{
parent::tearDown();
SharedDate::setExcelCalendar($this->excelCalendar);
Functions::setReturnDateType($this->returnDateType);
}
#[DataProvider('providerDATE')]
public function testDirectCallToDATE(float|string $expectedResult, int|string $year, null|bool|float|int|string $month, float|int|string $day): void
{
$result = Date::fromYMD($year, $month, $day);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerDATE')]
public function testDATEAsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=DATE({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerDATE')]
public function testDATEInWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=DATE({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public static function providerDATE(): array
{
return require 'tests/data/Calculation/DateTime/DATE.php';
}
#[DataProvider('providerUnhappyDATE')]
public function testDATEUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=DATE({$argumentCells})";
$this->expectException(CalculationException::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyDATE(): array
{
return [
['Formula Error: Wrong number of arguments for DATE() function', 2023, 3],
];
}
public function testDATEtoUnixTimestamp(): void
{
Functions::setReturnDateType(Functions::RETURNDATE_UNIX_TIMESTAMP);
$result = Date::fromYMD(2012, 1, 31); // 32-bit safe
self::assertEquals(1327968000, $result);
}
public function testDATEtoDateTimeObject(): void
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_OBJECT);
$result = Date::fromYMD(2012, 1, 31);
// Must return an object...
// ... of the correct type
self::assertInstanceOf(DateTimeInterface::class, $result);
// ... with the correct value
self::assertEquals($result->format('d-M-Y'), '31-Jan-2012');
}
public function testDATEWith1904Calendar(): void
{
SharedDate::setExcelCalendar(SharedDate::CALENDAR_MAC_1904);
$result = Date::fromYMD(1918, 11, 11);
self::assertEquals($result, 5428);
$result = Date::fromYMD(1901, 1, 31);
self::assertEquals($result, ExcelError::NAN());
}
/** @param array<mixed> $expectedResult */
#[DataProvider('providerDateArray')]
public function testDateArray(array $expectedResult, string $year, string $month, string $day): void
{
$calculation = Calculation::getInstance();
$formula = "=DATE({$year}, {$month}, {$day})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerDateArray(): array
{
return [
'row vector year' => [[[44197, 44562, 44927]], '{2021,2022,2023}', '1', '1'],
'column vector year' => [[[44197], [44562], [44927]], '{2021;2022;2023}', '1', '1'],
'matrix year' => [[[43831.00, 44197], [44562, 44927]], '{2020,2021;2022,2023}', '1', '1'],
'row vector month' => [[[44562, 44652, 44743, 44835]], '2022', '{1, 4, 7, 10}', '1'],
'column vector month' => [[[44562], [44652], [44743], [44835]], '2022', '{1; 4; 7; 10}', '1'],
'matrix month' => [[[44562, 44652], [44743, 44835]], '2022', '{1, 4; 7, 10}', '1'],
'row vector day' => [[[44561, 44562]], '2022', '1', '{0,1}'],
'column vector day' => [[[44561], [44562]], '2022', '1', '{0;1}'],
'vectors year and month' => [
[
[44197, 44287, 44378, 44470],
[44562, 44652, 44743, 44835],
[44927, 45017, 45108, 45200],
],
'{2021;2022;2023}',
'{1, 4, 7, 10}',
'1',
],
'vectors year and day' => [
[
[44196, 44197],
[44561, 44562],
[44926, 44927],
],
'{2021;2022;2023}',
'1',
'{0,1}',
],
'vectors month and day' => [
[
[44561, 44562],
[44651, 44652],
[44742, 44743],
[44834, 44835],
],
'2022',
'{1; 4; 7; 10}',
'{0,1}',
],
'matrices year and month' => [
[
[43831, 44287],
[44743, 45200],
],
'{2020, 2021; 2022, 2023}',
'{1, 4; 7, 10}',
'1',
],
];
}
#[DataProvider('providerDateArrayException')]
public function testDateArrayException(string $year, string $month, string $day): void
{
$calculation = Calculation::getInstance();
$this->expectException(CalculationException::class);
$this->expectExceptionMessage('Formulae with more than two array arguments are not supported');
$formula = "=DATE({$year}, {$month}, {$day})";
$calculation->calculateFormula($formula);
}
public static function providerDateArrayException(): array
{
return [
'matrix arguments with 3 array values' => [
'{2020, 2021; 2022, 2023}',
'{1, 4; 7, 10}',
'{0,1}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/HelpersTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/HelpersTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Helpers;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PHPUnit\Framework\TestCase;
class HelpersTest extends TestCase
{
public function testGetDateValueBadObject(): void
{
$this->expectException(CalcExp::class);
$this->expectExceptionMessage('#VALUE!');
Helpers::getDateValue($this);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EDateTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EDateTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use DateTimeInterface;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Month;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class EDateTest extends TestCase
{
private string $returnDateType;
protected function setUp(): void
{
parent::setUp();
$this->returnDateType = Functions::getReturnDateType();
}
protected function tearDown(): void
{
parent::tearDown();
Functions::setReturnDateType($this->returnDateType);
}
#[DataProvider('providerEDATE')]
public function testDirectCallToEDATE(mixed $expectedResult, mixed ...$args): void
{
$result = Month::adjust(...$args);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerEDATE')]
public function testEDATEAsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=EDATE({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerEDATE')]
public function testEDATEInWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=EDATE({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public static function providerEDATE(): array
{
return require 'tests/data/Calculation/DateTime/EDATE.php';
}
#[DataProvider('providerUnhappyEDATE')]
public function testEDATEUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=EDATE({$argumentCells})";
$this->expectException(CalculationException::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyEDATE(): array
{
return [
['Formula Error: Wrong number of arguments for EDATE() function', null],
['Formula Error: Wrong number of arguments for EDATE() function', 22669],
];
}
public function testEDATEtoUnixTimestamp(): void
{
Functions::setReturnDateType(Functions::RETURNDATE_UNIX_TIMESTAMP);
$result = Month::adjust('2012-1-26', -1);
self::assertEquals(1324857600, $result);
self::assertEqualsWithDelta(1324857600, $result, 1E-8);
}
public function testEDATEtoDateTimeObject(): void
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_DATETIME_OBJECT);
$result = Month::adjust('2012-1-26', -1);
// Must return an object...
// ... of the correct type
self::assertInstanceOf(DateTimeInterface::class, $result);
// ... with the correct value
self::assertEquals($result->format('d-M-Y'), '26-Dec-2011');
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerEDateArray')]
public function testEDateArray(array $expectedResult, string $dateValues, string $methods): void
{
$calculation = Calculation::getInstance();
$formula = "=EDATE({$dateValues}, {$methods})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerEDateArray(): array
{
return [
'row vector #1' => [[[44593, 44632, 45337]], '{"2022-01-01", "2022-02-12", "2024-01-15"}', '1'],
'column vector #1' => [[[44593], [44632], [45337]], '{"2022-01-01"; "2022-02-12"; "2024-01-15"}', '1'],
'matrix #1' => [[[44593, 44632], [44652, 45343]], '{"2022-01-01", "2022-02-12"; "2022-03-01", "2024-01-21"}', '1'],
'row vector #2' => [[[44573, 44604, 44632]], '"2022-02-12"', '{-1, 0, 1}'],
'column vector #2' => [[[44573], [44604], [44632]], '"2022-02-12"', '{-1; 0; 1}'],
'matrix #2' => [[[44573, 44604], [44632, 45334]], '"2022-02-12"', '{-1, 0; 1, 24}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/YearFracTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/YearFracTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\YearFrac;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class YearFracTest extends TestCase
{
#[DataProvider('providerYEARFRAC')]
public function testDirectCallToYEARFRAC(mixed $expectedResult, mixed ...$args): void
{
$result = YearFrac::fraction(...$args);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-6);
}
#[DataProvider('providerYEARFRAC')]
public function testYEARFRACAsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=YEARFRAC({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-6);
}
#[DataProvider('providerYEARFRAC')]
public function testYEARFRACInWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=YEARFRAC({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-6);
$spreadsheet->disconnectWorksheets();
}
public static function providerYEARFRAC(): array
{
return require 'tests/data/Calculation/DateTime/YEARFRAC.php';
}
#[DataProvider('providerUnhappyYEARFRAC')]
public function testYEARFRACUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=YEARFRAC({$argumentCells})";
$this->expectException(CalculationException::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyYEARFRAC(): array
{
return [
['Formula Error: Wrong number of arguments for YEARFRAC() function'],
['Formula Error: Wrong number of arguments for YEARFRAC() function', '2023-03-09'],
];
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerYearFracArray')]
public function testYearFracArray(array $expectedResult, string $startDate, string $endDate, ?string $methods): void
{
$calculation = Calculation::getInstance();
if ($methods === null) {
$formula = "=YEARFRAC({$startDate}, {$endDate})";
} else {
$formula = "=YEARFRAC({$startDate}, {$endDate}, {$methods})";
}
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerYearFracArray(): array
{
return [
'row vector #1' => [[[1.0, 0.55277777777778, 0.56111111111111]], '{"2022-01-01", "2022-06-12", "2023-07-22"}', '"2022-12-31"', null],
'column vector #1' => [[[1.0], [0.99444444444445], [0.98611111111111]], '{"2022-01-01"; "2022-01-03"; "2022-01-06"}', '"2022-12-31"', null],
'matrix #1' => [[[0.002777777777778, 0.027777777777778], [0.625, 1.0]], '{"2022-01-01", "2022-01-10"; "2022-08-15", "2022-12-31"}', '"2021-12-31"', null],
'column vector with methods' => [[[0.99726027397260, 0.99722222222222], [0.99178082191781, 0.99166666666667], [0.98356164383562, 0.98333333333333]], '{"2022-01-01"; "2022-01-03"; "2022-01-06"}', '"2022-12-31"', '{1, 4}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/NowTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/NowTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use DateTimeImmutable;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Current;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\DateParts;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\TimeParts;
use PHPUnit\Framework\TestCase;
class NowTest extends TestCase
{
private function assertions(DateTimeImmutable $dtStart, mixed $result): void
{
self::assertEquals($dtStart->format('Y'), DateParts::year($result));
self::assertEquals($dtStart->format('m'), DateParts::month($result));
self::assertEquals($dtStart->format('d'), DateParts::day($result));
self::assertEquals($dtStart->format('H'), TimeParts::hour($result));
self::assertEquals($dtStart->format('i'), TimeParts::minute($result));
self::assertEquals($dtStart->format('s'), TimeParts::second($result));
}
public function testDirectCallToNow(): void
{
// Loop to avoid rare edge case where first calculation
// and second do not take place in same second.
do {
$dtStart = new DateTimeImmutable();
$startSecond = $dtStart->format('s');
$result = Current::now();
$endSecond = (new DateTimeImmutable('now'))->format('s');
} while ($startSecond !== $endSecond);
$this->assertions($dtStart, $result);
}
public function testNowAsFormula(): void
{
$calculation = Calculation::getInstance();
$formula = '=NOW()';
// Loop to avoid rare edge case where first calculation
// and second do not take place in same second.
do {
$dtStart = new DateTimeImmutable();
$startSecond = $dtStart->format('s');
$result = $calculation->calculateFormula($formula);
$endSecond = (new DateTimeImmutable('now'))->format('s');
} while ($startSecond !== $endSecond);
$this->assertions($dtStart, $result);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/SecondTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/SecondTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\TimeParts;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class SecondTest extends TestCase
{
#[DataProvider('providerSECOND')]
public function testDirectCallToSECOND(mixed $expectedResult, mixed ...$args): void
{
$result = TimeParts::second(...$args);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerSECOND')]
public function testSECONDAsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=SECOND({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerSECOND')]
public function testSECONDInWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=SECOND({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public static function providerSECOND(): array
{
return require 'tests/data/Calculation/DateTime/SECOND.php';
}
#[DataProvider('providerUnhappySECOND')]
public function testSECONDUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=SECOND({$argumentCells})";
$this->expectException(\PhpOffice\PhpSpreadsheet\Calculation\Exception::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappySECOND(): array
{
return [
['Formula Error: Wrong number of arguments for SECOND() function'],
];
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerSecondArray')]
public function testSecondArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=SECOND({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerSecondArray(): array
{
return [
'row vector' => [[[3, 15, 21]], '{"2022-02-09 01:02:03", "2022-02-09 13:14:15", "2022-02-09 19:20:21"}'],
'column vector' => [[[3], [15], [21]], '{"2022-02-09 01:02:03"; "2022-02-09 13:14:15"; "2022-02-09 19:20:21"}'],
'matrix' => [[[3, 15], [21, 59]], '{"2022-02-09 01:02:03", "2022-02-09 13:14:15"; "2022-02-09 19:20:21", "1999-12-31 23:59:59"}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/Days360Test.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/Days360Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use DateTime;
use DateTimeImmutable;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Days;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Days360;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class Days360Test extends TestCase
{
#[DataProvider('providerDAYS360')]
public function testDirectCallToDAYS360(mixed $expectedResult, mixed ...$args): void
{
$result = Days360::between(...$args);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerDAYS360')]
public function testDAYS360AsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=DAYS360({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerDAYS360')]
public function testDAYS360InWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=DAYS360({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public static function providerDAYS360(): array
{
return require 'tests/data/Calculation/DateTime/DAYS360.php';
}
#[DataProvider('providerUnhappyDAYS360')]
public function testDAYS360UnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=DAYS360({$argumentCells})";
$this->expectException(CalculationException::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyDAYS360(): array
{
return [
['Formula Error: Wrong number of arguments for DAYS360() function'],
];
}
public function testDateObject(): void
{
$obj1 = new DateTime('2000-3-31');
$obj2 = new DateTimeImmutable('2000-2-29');
self::assertSame(31, Days::between($obj1, $obj2));
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerDays360Array')]
public function testDays360Array(array $expectedResult, string $startDate, string $endDate, ?string $methods): void
{
$calculation = Calculation::getInstance();
if ($methods === null) {
$formula = "=DAYS360({$startDate}, {$endDate})";
} else {
$formula = "=DAYS360({$startDate}, {$endDate}, {$methods})";
}
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerDays360Array(): array
{
return [
'row vector #1' => [[[360, 199, -201]], '{"2022-01-01", "2022-06-12", "2023-07-22"}', '"2022-12-31"', null],
'column vector #1' => [[[360], [358], [355]], '{"2022-01-01"; "2022-01-03"; "2022-01-06"}', '"2022-12-31"', null],
'matrix #1' => [[[0, -9], [-224, -360]], '{"2022-01-01", "2022-01-10"; "2022-08-15", "2022-12-31"}', '"2021-12-31"', null],
'column vector with methods' => [[[360, 359], [358, 357], [355, 354]], '{"2022-01-01"; "2022-01-03"; "2022-01-06"}', '"2022-12-31"', '{FALSE, TRUE}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WorkDayTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WorkDayTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\WorkDay;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class WorkDayTest extends TestCase
{
#[DataProvider('providerWORKDAY')]
public function testDirectCallToWORKDAY(mixed $expectedResult, mixed ...$args): void
{
$result = WorkDay::date(...$args);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerWORKDAY')]
public function testWORKDAYAsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=WORKDAY({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerWORKDAY')]
public function testWORKDAYInWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=WORKDAY({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public static function providerWORKDAY(): array
{
return require 'tests/data/Calculation/DateTime/WORKDAY.php';
}
#[DataProvider('providerUnhappyWORKDAY')]
public function testWORKDAYUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=WORKDAY({$argumentCells})";
$this->expectException(\PhpOffice\PhpSpreadsheet\Calculation\Exception::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyWORKDAY(): array
{
return [
['Formula Error: Wrong number of arguments for WORKDAY() function'],
];
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerWorkDayArray')]
public function testWorkDayArray(array $expectedResult, string $startDate, string $endDays, ?string $holidays): void
{
$calculation = Calculation::getInstance();
if ($holidays === null) {
$formula = "=WORKDAY({$startDate}, {$endDays})";
} else {
$formula = "=WORKDAY({$startDate}, {$endDays}, {$holidays})";
}
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerWorkDayArray(): array
{
return [
'row vector #1' => [[[44595, 44596, 44599]], '{"2022-02-01", "2022-02-02", "2022-02-03"}', '2', null],
'column vector #1' => [[[44595], [44596], [44599]], '{"2022-02-01"; "2022-02-02"; "2022-02-03"}', '2', null],
'matrix #1' => [[[44595, 44596], [44599, 44600]], '{"2022-02-01", "2022-02-02"; "2022-02-03", "2022-02-04"}', '2', null],
'row vector #2' => [[[44595, 44596]], '"2022-02-01"', '{2, 3}', null],
'column vector #2' => [[[44595], [44596]], '"2022-02-01"', '{2; 3}', null],
'row vector with Holiday' => [[[44596, 44599]], '"2022-02-01"', '{2, 3}', '{"2022-02-02"}'],
'row vector with Holidays' => [[[44599, 44600]], '"2022-02-01"', '{2, 3}', '{"2022-02-02", "2022-02-03"}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DaysTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DaysTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use DateTime;
use DateTimeImmutable;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Days;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class DaysTest extends TestCase
{
#[DataProvider('providerDAYS')]
public function testDirectCallToDAYS(int|string $expectedResult, int|string $date1, int|string $date2): void
{
$result = Days::between($date1, $date2);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerDAYS')]
public function testDAYSAsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=DAYS({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerDAYS')]
public function testDAYSInWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=DAYS({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public static function providerDAYS(): array
{
return require 'tests/data/Calculation/DateTime/DAYS.php';
}
#[DataProvider('providerUnhappyDAYS')]
public function testDAYSUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=DAYS({$argumentCells})";
$this->expectException(CalculationException::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyDAYS(): array
{
return [
['Formula Error: Wrong number of arguments for DAYS() function', '2023-04-01'],
];
}
public function testDateObject(): void
{
$obj1 = new DateTime('2000-3-31');
$obj2 = new DateTimeImmutable('2000-2-29');
self::assertSame(31, Days::between($obj1, $obj2));
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerDaysArray')]
public function testDaysArray(array $expectedResult, string $startDate, string $endDate): void
{
$calculation = Calculation::getInstance();
$formula = "=DAYS({$startDate}, {$endDate})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerDaysArray(): array
{
return [
'row vector #1' => [[[-364, -202, 203]], '{"2022-01-01", "2022-06-12", "2023-07-22"}', '"2022-12-31"'],
'column vector #1' => [[[-364], [-362], [-359]], '{"2022-01-01"; "2022-01-03"; "2022-01-06"}', '"2022-12-31"'],
'matrix #1' => [[[1, 10], [227, 365]], '{"2022-01-01", "2022-01-10"; "2022-08-15", "2022-12-31"}', '"2021-12-31"'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/HourTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/HourTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\TimeParts;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class HourTest extends TestCase
{
#[DataProvider('providerHOUR')]
public function testDirectCallToHOUR(mixed $expectedResult, mixed ...$args): void
{
$result = TimeParts::hour(...$args);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerHOUR')]
public function testHOURAsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=HOUR({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerHOUR')]
public function testHOURInWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=HOUR({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public static function providerHOUR(): array
{
return require 'tests/data/Calculation/DateTime/HOUR.php';
}
#[DataProvider('providerUnhappyHOUR')]
public function testHOURUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=HOUR({$argumentCells})";
$this->expectException(CalculationException::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyHOUR(): array
{
return [
['Formula Error: Wrong number of arguments for HOUR() function'],
];
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerHourArray')]
public function testHourArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=HOUR({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerHourArray(): array
{
return [
'row vector' => [[[1, 13, 19]], '{"2022-02-09 01:02:03", "2022-02-09 13:14:15", "2022-02-09 19:20:21"}'],
'column vector' => [[[1], [13], [19]], '{"2022-02-09 01:02:03"; "2022-02-09 13:14:15"; "2022-02-09 19:20:21"}'],
'matrix' => [[[1, 13], [19, 23]], '{"2022-02-09 01:02:03", "2022-02-09 13:14:15"; "2022-02-09 19:20:21", "1999-12-31 23:59:59"}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateValueTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateValueTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use DateTimeImmutable;
use DateTimeInterface;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\DateValue;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDate;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class DateValueTest extends TestCase
{
private int $excelCalendar;
private string $returnDateType;
protected function setUp(): void
{
parent::setUp();
$this->excelCalendar = SharedDate::getExcelCalendar();
$this->returnDateType = Functions::getReturnDateType();
}
protected function tearDown(): void
{
parent::tearDown();
SharedDate::setExcelCalendar($this->excelCalendar);
Functions::setReturnDateType($this->returnDateType);
}
private function expectationIsTemplate(mixed $expectedResult): bool
{
return is_string($expectedResult) && str_starts_with($expectedResult, 'Y-');
}
private function parseTemplatedExpectation(float|int|string $expectedResult): string
{
/** @var float */
$x = DateValue::fromString(
(new DateTimeImmutable(
str_replace('Y', (new DateTimeImmutable('now'))->format('Y'), (string) $expectedResult)
))->format('Y-m-d')
);
return (string) $x;
}
#[DataProvider('providerDATEVALUE')]
public function testDirectCallToDATEVALUE(int|string $expectedResult, bool|int|string $value): void
{
if ($this->expectationIsTemplate($expectedResult)) {
$expectedResult = $this->parseTemplatedExpectation((string) $expectedResult);
}
$result = DateValue::fromString($value);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-8);
}
#[DataProvider('providerDATEVALUE')]
public function testDATEVALUEAsFormula(float|int|string $expectedResult, mixed ...$args): void
{
if ($this->expectationIsTemplate($expectedResult)) {
$expectedResult = $this->parseTemplatedExpectation($expectedResult);
}
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=DATEVALUE({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-8);
}
#[DataProvider('providerDATEVALUE')]
public function testDATEVALUEInWorksheet(float|int|string $expectedResult, mixed ...$args): void
{
if ($this->expectationIsTemplate($expectedResult)) {
$expectedResult = $this->parseTemplatedExpectation($expectedResult);
}
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=DATEVALUE({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-8);
$spreadsheet->disconnectWorksheets();
}
public static function providerDATEVALUE(): array
{
return require 'tests/data/Calculation/DateTime/DATEVALUE.php';
}
public function testRefArgNull(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue('=DATEVALUE(B1)');
self::assertSame('#VALUE!', $sheet->getCell('A1')->getCalculatedValue());
$spreadsheet->disconnectWorksheets();
}
#[DataProvider('providerUnhappyDATEVALUE')]
public function testDATEVALUEUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=DATEVALUE({$argumentCells})";
$this->expectException(CalculationException::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyDATEVALUE(): array
{
return [
['Formula Error: Wrong number of arguments for DATEVALUE() function'],
];
}
public function testDATEVALUEtoUnixTimestamp(): void
{
Functions::setReturnDateType(Functions::RETURNDATE_UNIX_TIMESTAMP);
$result = DateValue::fromString('2012-1-31');
self::assertEquals(1327968000, $result);
self::assertEqualsWithDelta(1327968000, $result, 1E-8);
}
public function testDATEVALUEtoDateTimeObject(): void
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_DATETIME_OBJECT);
$result = DateValue::fromString('2012-1-31');
// Must return an object...
// ... of the correct type
self::assertInstanceOf(DateTimeInterface::class, $result);
// ... with the correct value
self::assertEquals($result->format('d-M-Y'), '31-Jan-2012');
}
public function testDATEVALUEWith1904Calendar(): void
{
SharedDate::setExcelCalendar(SharedDate::CALENDAR_MAC_1904);
self::assertEquals(5428, DateValue::fromString('1918-11-11'));
self::assertEquals(0, DateValue::fromString('1904-01-01'));
self::assertEquals('#VALUE!', DateValue::fromString('1903-12-31'));
self::assertEquals('#VALUE!', DateValue::fromString('1900-02-29'));
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerDateValueArray')]
public function testDateValueArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=DATEVALUE({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerDateValueArray(): array
{
return [
'row vector' => [[[44562, 44724, 45129]], '{"2022-01-01", "2022-06-12", "2023-07-22"}'],
'column vector' => [[[44562], [44564], [44567]], '{"2022-01-01"; "2022-01-03"; "2022-01-06"}'],
'matrix' => [[[44562, 44571], [44788, 44926]], '{"2022-01-01", "2022-01-10"; "2022-08-15", "2022-12-31"}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use DateTimeInterface;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Time;
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDate;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class TimeTest extends TestCase
{
private int $excelCalendar;
private string $returnDateType;
protected function setUp(): void
{
parent::setUp();
$this->excelCalendar = SharedDate::getExcelCalendar();
$this->returnDateType = Functions::getReturnDateType();
}
protected function tearDown(): void
{
parent::tearDown();
SharedDate::setExcelCalendar($this->excelCalendar);
Functions::setReturnDateType($this->returnDateType);
}
#[DataProvider('providerTIME')]
public function testDirectCallToTIME(float|string $expectedResult, int|string $hour, bool|int $minute, int $second): void
{
$result = Time::fromHMS($hour, $minute, $second);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
}
#[DataProvider('providerTIME')]
public function testTIMEAsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=TIME({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
}
public static function providerTIME(): array
{
return require 'tests/data/Calculation/DateTime/TIME.php';
}
#[DataProvider('providerUnhappyTIME')]
public function testTIMEUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=TIME({$argumentCells})";
$this->expectException(CalculationException::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyTIME(): array
{
return [
['Formula Error: Wrong number of arguments for TIME() function', 2023, 3],
];
}
public function testTIMEtoUnixTimestamp(): void
{
Functions::setReturnDateType(Functions::RETURNDATE_UNIX_TIMESTAMP);
$result = Time::fromHMS(7, 30, 20);
self::assertEqualsWithDelta(27020, $result, 1E-12);
}
public function testTIMEtoDateTimeObject(): void
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_DATETIME_OBJECT);
$result = Time::fromHMS(7, 30, 20);
// Must return an object...
// ... of the correct type
self::assertInstanceOf(DateTimeInterface::class, $result);
// ... with the correct value
self::assertEquals($result->format('H:i:s'), '07:30:20');
}
public function testTIMEWith1904Calendar(): void
{
SharedDate::setExcelCalendar(SharedDate::CALENDAR_MAC_1904);
$result = Time::fromHMS(0, 0, 0);
self::assertEquals(0, $result);
}
public function testTIME1900(): void
{
$result = Time::fromHMS(0, 0, 0);
self::assertEquals(0, $result);
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerTimeArray')]
public function testTimeArray(array $expectedResult, string $hour, string $minute, string $second): void
{
$calculation = Calculation::getInstance();
$formula = "=TIME({$hour}, {$minute}, {$second})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerTimeArray(): array
{
return [
'row vector hour' => [[[0.250706018518519, 0.50070601851852, 0.75070601851852]], '{6,12,18}', '1', '1'],
'column vector hour' => [[[0.250706018518519], [0.50070601851852], [0.75070601851852]], '{6;12;18}', '1', '1'],
'matrix hour' => [[[0.250706018518519, 0.50070601851852], [0.75070601851852, 0.95903935185185]], '{6,12;18,23}', '1', '1'],
'row vector minute' => [[[0.96667824074074, 0.97501157407407, 0.98334490740741, 0.99931712962963]], '23', '{12, 24, 36, 59}', '1'],
'column vector minute' => [[[0.96734953703704], [0.97568287037037], [0.98401620370370], [0.99998842592593]], '23', '{12; 24; 36; 59}', '59'],
'matrix minute' => [[[0.50833333333333, 0.51666666666667], [0.52083333333333, 0.5]], '12', '{12, 24; 30, 0}', '0'],
'row vector second' => [[[0.50069444444444, 0.50137731481481]], '12', '1', '{0,59}'],
'column vector second' => [[[0.99930555555556], [0.99998842592593]], '23', '59', '{0;59}'],
'vectors hour and minute' => [
[
[0.87570601851852, 0.88473379629630, 0.89376157407407, 0.90626157407407],
[0.91737268518519, 0.92640046296296, 0.93542824074074, 0.94792824074074],
[0.95903935185185, 0.96806712962963, 0.97709490740741, 0.98959490740741],
],
'{21;22;23}',
'{1, 14, 27, 45}',
'1',
],
'vectors hour and second' => [
[
[0.126041666666667, 0.126215277777778],
[0.334375, 0.33454861111111],
[0.584375, 0.58454861111111],
],
'{3;8;14}',
'1',
'{30,45}',
],
'vectors minute and second' => [
[
[0.75833333333333, 0.75834490740741],
[0.76041666666667, 0.76042824074074],
[0.77083333333333, 0.77084490740741],
[0.75, 0.750011574074074],
],
'18',
'{12; 15; 30; 0}',
'{0,1}',
],
'matrices hour and minute' => [
[
[0.25070601851852, 0.50278935185185],
[0.75487268518519, 0.96528935185185],
],
'{6, 12; 18, 23}',
'{1, 4; 7, 10}',
'1',
],
];
}
#[DataProvider('providerTimeArrayException')]
public function testTimeArrayException(string $hour, string $minute, string $second): void
{
$calculation = Calculation::getInstance();
$this->expectException(Exception::class);
$this->expectExceptionMessage('Formulae with more than two array arguments are not supported');
$formula = "=TIME({$hour}, {$minute}, {$second})";
$calculation->calculateFormula($formula);
}
public static function providerTimeArrayException(): array
{
return [
'matrix arguments with 3 array values' => [
'{6, 12; 16, 23}',
'{1, 4; 7, 10}',
'{0,1}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekNumTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekNumTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\Week;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException;
use PhpOffice\PhpSpreadsheet\Shared\Date as SharedDate;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class WeekNumTest extends TestCase
{
private int $excelCalendar;
protected function setUp(): void
{
parent::setUp();
$this->excelCalendar = SharedDate::getExcelCalendar();
}
protected function tearDown(): void
{
parent::tearDown();
SharedDate::setExcelCalendar($this->excelCalendar);
}
#[DataProvider('providerWEEKNUM')]
public function testDirectCallToWEEKNUM(mixed $expectedResult, mixed ...$args): void
{
$result = Week::number(...$args);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerWEEKNUM')]
public function testWEEKNUMAsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=WEEKNUM({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerWEEKNUM')]
public function testWEEKNUMInWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=WEEKNUM({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public static function providerWEEKNUM(): array
{
return require 'tests/data/Calculation/DateTime/WEEKNUM.php';
}
#[DataProvider('providerUnhappyWEEKNUM')]
public function testWEEKNUMUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=WEEKNUM({$argumentCells})";
$this->expectException(CalculationException::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyWEEKNUM(): array
{
return [
['Formula Error: Wrong number of arguments for WEEKNUM() function'],
];
}
#[DataProvider('providerWEEKNUM1904')]
public function testWEEKNUMWith1904Calendar(mixed $expectedResult, mixed ...$args): void
{
SharedDate::setExcelCalendar(SharedDate::CALENDAR_MAC_1904);
$result = Week::number(...$args);
self::assertSame($expectedResult, $result);
}
public static function providerWEEKNUM1904(): array
{
return require 'tests/data/Calculation/DateTime/WEEKNUM1904.php';
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerWeekNumArray')]
public function testWeekNumArray(array $expectedResult, string $dateValues, string $methods): void
{
$calculation = Calculation::getInstance();
$formula = "=WEEKNUM({$dateValues}, {$methods})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerWeekNumArray(): array
{
return [
'row vector #1' => [[[1, 25, 29]], '{"2022-01-01", "2022-06-12", "2023-07-22"}', '1'],
'column vector #1' => [[[1], [13], [26]], '{"2023-01-01"; "2023-04-01"; "2023-07-01"}', '1'],
'matrix #1' => [[[1, 53], [1, 53]], '{"2021-01-01", "2021-12-31"; "2023-01-01", "2023-12-31"}', '1'],
'row vector #2' => [[[25, 24]], '"2022-06-12"', '{1, 2}'],
'column vector #2' => [[[13], [14]], '"2023-04-01"', '{1; 2}'],
'matrix #2' => [[[53, 53], [53, 52]], '"2021-12-31"', '{1, 2; 16, 21}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SechTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SechTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class SechTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerSECH')]
public function testSECH(float|int|string $expectedResult, float|int|string $angle): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=SECH($angle)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
}
public static function providerSECH(): array
{
return require 'tests/data/Calculation/MathTrig/SECH.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerSechArray')]
public function testSechArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=SECH({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerSechArray(): array
{
return [
'row vector' => [[[0.64805427366389, 0.88681888397007, 0.64805427366389]], '{1, 0.5, -1}'],
'column vector' => [[[0.64805427366389], [0.88681888397007], [0.64805427366389]], '{1; 0.5; -1}'],
'matrix' => [[[0.64805427366389, 0.88681888397007], [1.0, 0.64805427366389]], '{1, 0.5; 0, -1}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class TanTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerTan')]
public function testTan(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1);
$sheet->getCell('A1')->setValue("=TAN($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
}
public static function providerTan(): array
{
return require 'tests/data/Calculation/MathTrig/TAN.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerTanArray')]
public function testTanArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=TAN({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerTanArray(): array
{
return [
'row vector' => [[[1.55740772465490, 0.54630248984379, -1.55740772465490]], '{1, 0.5, -1}'],
'column vector' => [[[1.55740772465490], [0.54630248984379], [-1.55740772465490]], '{1; 0.5; -1}'],
'matrix' => [[[1.55740772465490, 0.54630248984379], [0.0, -1.55740772465490]], '{1, 0.5; 0, -1}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FloorPreciseTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FloorPreciseTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class FloorPreciseTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerFLOORPRECISE')]
public function testFLOORPRECISE(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=FLOOR.PRECISE($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerFLOORPRECISE(): array
{
return require 'tests/data/Calculation/MathTrig/FLOORPRECISE.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerFloorArray')]
public function testFloorArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=FLOOR.PRECISE({$argument1}, {$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerFloorArray(): array
{
return [
'matrix' => [[[3.14, 3.14], [3.14155, 3.141592]], '3.1415926536', '{0.01, 0.002; 0.00005, 0.000002}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AllSetupTeardown.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AllSetupTeardown.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Cell\DataType;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PHPUnit\Framework\TestCase;
class AllSetupTeardown extends TestCase
{
private string $compatibilityMode;
protected ?Spreadsheet $spreadsheet = null;
private ?Worksheet $sheet = null;
protected function setUp(): void
{
$this->compatibilityMode = Functions::getCompatibilityMode();
}
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
$this->sheet = null;
if ($this->spreadsheet !== null) {
$this->spreadsheet->disconnectWorksheets();
$this->spreadsheet = null;
}
}
protected static function setOpenOffice(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
}
protected static function setGnumeric(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
}
protected function mightHaveException(mixed $expectedResult): void
{
if ($expectedResult === 'exception') {
$this->expectException(CalcException::class);
}
}
protected function setCell(string $cell, mixed $value): void
{
if ($value !== null) {
if (is_string($value) && is_numeric($value)) {
$this->getSheet()->getCell($cell)->setValueExplicit($value, DataType::TYPE_STRING);
} else {
$this->getSheet()->getCell($cell)->setValue($value);
}
}
}
protected function getSpreadsheet(): Spreadsheet
{
if ($this->spreadsheet !== null) {
return $this->spreadsheet;
}
$this->spreadsheet = new Spreadsheet();
return $this->spreadsheet;
}
protected function getSheet(): Worksheet
{
if ($this->sheet !== null) {
return $this->sheet;
}
$this->sheet = $this->getSpreadsheet()->getActiveSheet();
return $this->sheet;
}
protected function setArrayAsValue(): void
{
$spreadsheet = $this->getSpreadsheet();
$calculation = Calculation::getInstance($spreadsheet);
$calculation->setInstanceArrayReturnType(
Calculation::RETURN_ARRAY_AS_VALUE
);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RoundUpTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RoundUpTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class RoundUpTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerRoundUp')]
public function testRoundUp(float|int|string $expectedResult, float|int|string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=ROUNDUP($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerRoundUp(): array
{
return require 'tests/data/Calculation/MathTrig/ROUNDUP.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerRoundUpArray')]
public function testRoundUpArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=ROUNDUP({$argument1},{$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerRoundUpArray(): array
{
return [
'first argument row vector' => [
[[0.146, 1.373, -931.683, 3.142]],
'{0.14527, 1.3725, -931.6829, 3.14159265}',
'3',
],
'first argument column vector' => [
[[0.146], [1.373], [-931.683], [3.142]],
'{0.14527; 1.3725; -931.6829; 3.14159265}',
'3',
],
'first argument matrix' => [
[[0.146, 1.373], [-931.683, 3.142]],
'{0.14527, 1.3725; -931.6829, 3.14159265}',
'3',
],
'second argument row vector' => [
[[0.2, 0.15, 0.146, 0.1453, 0.14527]],
'0.14527',
'{1, 2, 3, 4, 5}',
],
'second argument column vector' => [
[[0.2], [0.15], [0.146], [0.1453], [0.14527]],
'0.14527',
'{1; 2; 3; 4; 5}',
],
'second argument matrix' => [
[[0.2, 0.15], [0.146, 0.1453]],
'0.14527',
'{1, 2; 3, 4}',
],
'A row and a column vector' => [
[
[0.2, 0.15, 0.146, 0.1453],
[1.4, 1.38, 1.373, 1.3725],
[-931.7, -931.69, -931.683, -931.6829],
[3.2, 3.15, 3.142, 3.1416],
],
'{0.14527; 1.37250; -931.68290; 3.14159265}',
'{1, 2, 3, 4}',
],
'Two row vectors' => [
[[0.2, 1.38, -931.683, 3.1416]],
'{0.14527, 1.37250, -931.68290, 3.14159265}',
'{1, 2, 3, 4}',
],
'Two column vectors' => [
[[0.2], [1.38], [-931.683], [3.1416]],
'{0.14527; 1.37250; -931.68290; 3.14159265}',
'{1; 2; 3; 4}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FactDoubleTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FactDoubleTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class FactDoubleTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerFACTDOUBLE')]
public function testFACTDOUBLE(mixed $expectedResult, mixed $value): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue($value);
$sheet->getCell('B1')->setValue('=FACTDOUBLE(A1)');
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public static function providerFACTDOUBLE(): array
{
return require 'tests/data/Calculation/MathTrig/FACTDOUBLE.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerFactDoubleArray')]
public function testFactDoubleArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=FACTDOUBLE({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerFactDoubleArray(): array
{
return [
'row vector' => [[['#NUM!', 48, 945]], '{-2, 6, 9}'],
'column vector' => [[['#NUM!'], [48], [945]], '{-2; 6; 9}'],
'matrix' => [[['#NUM!', 48], [945, 3]], '{-2, 6; 9, 3.5}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CotTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CotTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class CotTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCOT')]
public function testCOT(float|int|string $expectedResult, float|int|string $angle): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=COT($angle)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
}
public static function providerCOT(): array
{
return require 'tests/data/Calculation/MathTrig/COT.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerCotArray')]
public function testCotArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=COT({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerCotArray(): array
{
return [
'row vector' => [[[0.64209261593433, 1.83048772171245, -0.64209261593433]], '{1, 0.5, -1}'],
'column vector' => [[[0.64209261593433], [1.83048772171245], [-0.64209261593433]], '{1; 0.5; -1}'],
'matrix' => [[[0.64209261593433, 1.83048772171245], ['#DIV/0!', -0.64209261593433]], '{1, 0.5; 0, -1}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/LnTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/LnTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class LnTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerLN')]
public function testLN(mixed $expectedResult, mixed $number = 'omitted'): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
if ($number !== null) {
$sheet->getCell('A1')->setValue($number);
}
if ($number === 'omitted') {
$sheet->getCell('B1')->setValue('=LN()');
} else {
$sheet->getCell('B1')->setValue('=LN(A1)');
}
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
}
public static function providerLN(): array
{
return require 'tests/data/Calculation/MathTrig/LN.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerLnArray')]
public function testLnArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=LN({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerLnArray(): array
{
return [
'row vector' => [[[-2.07944154167984, 0.85228540189824, 2.525728644308256]], '{0.125, 2.345, 12.5}'],
'column vector' => [[[-2.07944154167984], [0.85228540189824], [2.525728644308256]], '{0.125; 2.345; 12.5}'],
'matrix' => [[[-2.07944154167984, 0.85228540189824], [0.0, 2.525728644308256]], '{0.125, 2.345; 1.0, 12.5}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/DegreesTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/DegreesTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class DegreesTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerDEGREES')]
public function testDegrees(mixed $expectedResult, mixed $number = 'omitted'): void
{
$sheet = $this->getSheet();
$this->mightHaveException($expectedResult);
$this->setCell('A1', $number);
if ($number === 'omitted') {
$sheet->getCell('B1')->setValue('=DEGREES()');
} else {
$sheet->getCell('B1')->setValue('=DEGREES(A1)');
}
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
}
public static function providerDegrees(): array
{
return require 'tests/data/Calculation/MathTrig/DEGREES.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerDegreesArray')]
public function testDegreesArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=DEGREES({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
}
public static function providerDegreesArray(): array
{
return [
'row vector' => [[[143.23944878270600, 7.16197243913529, -183.34649444186300]], '{2.5, 0.125, -3.2}'],
'column vector' => [[[143.23944878270600], [7.16197243913529], [-183.34649444186300]], '{2.5; 0.125; -3.2}'],
'matrix' => [[[143.23944878270600, 7.16197243913529], [429.71834634811700, -183.34649444186300]], '{2.5, 0.125; 7.5, -3.2}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CeilingPreciseTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CeilingPreciseTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class CeilingPreciseTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerFLOORPRECISE')]
public function testCEILINGPRECISE(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=CEILING.PRECISE($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerFLOORPRECISE(): array
{
return require 'tests/data/Calculation/MathTrig/CEILINGPRECISE.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerCeilingArray')]
public function testCeilingArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=CEILING.PRECISE({$argument1}, {$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerCeilingArray(): array
{
return [
'matrix' => [[[3.15, 3.142], [3.1416, 3.141594]], '3.1415926536', '{0.01, 0.002; 0.00005, 0.000002}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RandTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RandTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
class RandTest extends AllSetupTeardown
{
public function testRand(): void
{
$sheet = $this->getSheet();
$sheet->getCell('B1')->setValue('=RAND()');
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertGreaterThanOrEqual(0, $result);
self::assertLessThanOrEqual(1, $result);
}
public function testRandException(): void
{
$this->mightHaveException('exception');
$sheet = $this->getSheet();
$sheet->getCell('B1')->setValue('=RAND(A1)');
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEquals(0, $result);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CombinATest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CombinATest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class CombinATest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCOMBINA')]
public function testCOMBINA(mixed $expectedResult, mixed $numObjs, mixed $numInSet): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
if ($numObjs !== null) {
$sheet->getCell('A1')->setValue($numObjs);
}
if ($numInSet !== null) {
$sheet->getCell('A2')->setValue($numInSet);
}
$sheet->getCell('B1')->setValue('=COMBINA(A1,A2)');
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public static function providerCOMBINA(): array
{
return require 'tests/data/Calculation/MathTrig/COMBINA.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerCombinAArray')]
public function testCombinAArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=COMBINA({$argument1},{$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerCombinAArray(): array
{
return [
'first argument row vector' => [
[[120, 35]],
'{8, 5}',
'3',
],
'first argument column vector' => [
[[120], [35]],
'{8; 5}',
'3',
],
'first argument matrix' => [
[[120, 35], [10, 84]],
'{8, 5; 3, 7}',
'3',
],
'second argument row vector' => [
[[455, 18564]],
'13',
'{3, 6}',
],
'second argument column vector' => [
[[455], [18564]],
'13',
'{3; 6}',
],
'second argument matrix' => [
[[455, 18564], [1820, 125970]],
'13',
'{3, 6; 4, 8}',
],
'A row and a column vector' => [
[
[4368, 1365, 364, 78],
[2002, 715, 220, 55],
[792, 330, 120, 36],
[252, 126, 56, 21],
],
'{12; 10; 8; 6}',
'{5, 4, 3, 2}',
],
'Two row vectors' => [
[[4368, 715, 120, 21]],
'{12, 10, 8, 6}',
'{5, 4, 3, 2}',
],
'Two column vectors' => [
[[4368], [715], [120], [21]],
'{12; 10; 8; 6}',
'{5; 4; 3; 2}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CscTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CscTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class CscTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCSC')]
public function testCSC(float|int|string $expectedResult, float|int|string $angle): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=CSC($angle)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
}
public static function providerCSC(): array
{
return require 'tests/data/Calculation/MathTrig/CSC.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerCscArray')]
public function testCscArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=CSC({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerCscArray(): array
{
return [
'row vector' => [[[1.18839510577812, 2.08582964293349, -1.18839510577812]], '{1, 0.5, -1}'],
'column vector' => [[[1.18839510577812], [2.08582964293349], [-1.18839510577812]], '{1; 0.5; -1}'],
'matrix' => [[[1.18839510577812, 2.08582964293349], ['#DIV/0!', -1.18839510577812]], '{1, 0.5; 0, -1}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/QuotientTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/QuotientTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class QuotientTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerQUOTIENT')]
public function testQUOTIENT(mixed $expectedResult, mixed $arg1 = 'omitted', mixed $arg2 = 'omitted'): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
if ($arg1 !== null) {
$sheet->getCell('A1')->setValue($arg1);
}
if ($arg2 !== null) {
$sheet->getCell('A2')->setValue($arg2);
}
if ($arg1 === 'omitted') {
$sheet->getCell('B1')->setValue('=QUOTIENT()');
} elseif ($arg2 === 'omitted') {
$sheet->getCell('B1')->setValue('=QUOTIENT(A1)');
} else {
$sheet->getCell('B1')->setValue('=QUOTIENT(A1, A2)');
}
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
public static function providerQUOTIENT(): array
{
return require 'tests/data/Calculation/MathTrig/QUOTIENT.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerQuotientArray')]
public function testQuotientArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=QUOTIENT({$argument1}, {$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerQuotientArray(): array
{
return [
'matrix' => [[[3, 3, 2], [2, 2, 1], [1, 0, 0]], '{9, 8, 7; 6, 5, 4; 3, 2, 1}', '2.5'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FloorMathTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FloorMathTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class FloorMathTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerFLOORMATH')]
public function testFLOORMATH(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=FLOOR.MATH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerFLOORMATH(): array
{
return require 'tests/data/Calculation/MathTrig/FLOORMATH.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerFloorArray')]
public function testFloorArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=FLOOR.MATH({$argument1}, {$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerFloorArray(): array
{
return [
'matrix' => [[[3.14, 3.14], [3.14155, 3.141592]], '3.1415926536', '{0.01, 0.002; 0.00005, 0.000002}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumX2MY2Test.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumX2MY2Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\Attributes\DataProvider;
class SumX2MY2Test extends AllSetupTeardown
{
/**
* @param mixed[] $matrixData1
* @param mixed[] $matrixData2
*/
#[DataProvider('providerSUMX2MY2')]
public function testSUMX2MY2(mixed $expectedResult, array $matrixData1, array $matrixData2): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$maxRow = 0;
$funcArg1 = '';
foreach (Functions::flattenArray($matrixData1) as $arg) {
++$maxRow;
$funcArg1 = "A1:A$maxRow";
$this->setCell("A$maxRow", $arg);
}
$maxRow = 0;
$funcArg2 = '';
foreach (Functions::flattenArray($matrixData2) as $arg) {
++$maxRow;
$funcArg2 = "C1:C$maxRow";
$this->setCell("C$maxRow", $arg);
}
$sheet->getCell('B1')->setValue("=SUMX2MY2($funcArg1, $funcArg2)");
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerSUMX2MY2(): array
{
return require 'tests/data/Calculation/MathTrig/SUMX2MY2.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcotTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcotTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class AcotTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerACOT')]
public function testACOT(float|int|string $expectedResult, float|int|string $number): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5);
$sheet->getCell('A1')->setValue("=ACOT($number)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
}
public static function providerACOT(): array
{
return require 'tests/data/Calculation/MathTrig/ACOT.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerAcotArray')]
public function testAcotArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=ACOT({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerAcotArray(): array
{
return [
'row vector' => [[[0.78539816339745, 1.10714871779409, 2.35619449019234]], '{1, 0.5, -1}'],
'column vector' => [[[0.78539816339745], [1.10714871779409], [2.35619449019234]], '{1; 0.5; -1}'],
'matrix' => [[[0.78539816339745, 1.10714871779409], [1.57079632679490, 2.35619449019234]], '{1, 0.5; 0, -1}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MUnitTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MUnitTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\MatrixFunctions;
class MUnitTest extends AllSetupTeardown
{
const MU_PRECISION = 1.0E-12;
public function testMUNIT(): void
{
$identity = MatrixFunctions::identity(3);
self::assertEquals([[1, 0, 0], [0, 1, 0], [0, 0, 1]], $identity);
$startArray = [[1, 2, 2], [4, 5, 6], [7, 8, 9]];
$resultArray = MatrixFunctions::multiply($startArray, $identity);
self::assertEquals($startArray, $resultArray);
$inverseArray = MatrixFunctions::inverse($startArray);
$resultArray = MatrixFunctions::multiply($startArray, $inverseArray);
self::assertEqualsWithDelta($identity, $resultArray, self::MU_PRECISION);
self::assertEquals('#VALUE!', MatrixFunctions::identity(0));
self::assertEquals('#VALUE!', MatrixFunctions::identity(-1));
self::assertEquals('#VALUE!', MatrixFunctions::identity('X'));
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/LcmTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/LcmTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
class LcmTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerLCM')]
public function testLCM(mixed $expectedResult, mixed ...$args): void
{
$sheet = $this->getSheet();
$row = 0;
foreach ($args as $arg) {
++$row;
$sheet->getCell("A$row")->setValue($arg);
}
$sheet->getCell('B1')->setValue("=LCM(A1:A$row)");
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerLCM(): array
{
return require 'tests/data/Calculation/MathTrig/LCM.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumProductTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumProductTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class SumProductTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerSUMPRODUCT')]
public function testSUMPRODUCT(mixed $expectedResult, mixed ...$args): void
{
$sheet = $this->getSheet();
$row = 0;
$arrayArg = '';
foreach ($args as $arr) {
$arr2 = Functions::flattenArray($arr);
$startRow = 0;
foreach ($arr2 as $arr3) {
++$row;
if (!$startRow) {
$startRow = $row;
}
$sheet->getCell("A$row")->setValue($arr3);
}
$arrayArg .= "A$startRow:A$row,";
}
$arrayArg = substr($arrayArg, 0, -1); // strip trailing comma
$sheet->getCell('B1')->setValue("=SUMPRODUCT($arrayArg)");
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerSUMPRODUCT(): array
{
return require 'tests/data/Calculation/MathTrig/SUMPRODUCT.php';
}
public function testBoolsAsInt(): void
{
// issue 3389 not handling unary minus with boolean value
$sheet = $this->getSheet();
$sheet->fromArray(
[
['Range 1', 'Range 2', null, 'Blue matches', 'Red matches'],
[0, 'Red', null, '=SUMPRODUCT(--(B3:B10=1), --(C3:C10="BLUE"))', '=SUMPRODUCT(--(B3:B10=1), --(C3:C10="RED"))'],
[1, 'Blue'],
[0, 'Blue'],
[1, 'Red'],
[1, 'Blue'],
[0, 'Blue'],
[1, 'Red'],
[1, 'Blue'],
],
null, // null value
'B2', // start cell
true // strict null comparison
);
self::assertSame(3, $sheet->getCell('E3')->getCalculatedValue());
self::assertSame(2, $sheet->getCell('F3')->getCalculatedValue());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class SinTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerSin')]
public function testSin(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 2);
$sheet->getCell('A1')->setValue("=SIN($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
}
public static function providerSin(): array
{
return require 'tests/data/Calculation/MathTrig/SIN.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerSinArray')]
public function testSinArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=SIN({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerSinArray(): array
{
return [
'row vector' => [[[0.84147098480790, 0.47942553860420, -0.84147098480790]], '{1, 0.5, -1}'],
'column vector' => [[[0.84147098480790], [0.47942553860420], [-0.84147098480790]], '{1; 0.5; -1}'],
'matrix' => [[[0.84147098480790, 0.47942553860420], [0.0, -0.84147098480790]], '{1, 0.5; 0, -1}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumX2PY2Test.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumX2PY2Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\Attributes\DataProvider;
class SumX2PY2Test extends AllSetupTeardown
{
/**
* @param mixed[] $matrixData1
* @param mixed[] $matrixData2
*/
#[DataProvider('providerSUMX2PY2')]
public function testSUMX2PY2(mixed $expectedResult, array $matrixData1, array $matrixData2): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$maxRow = 0;
$funcArg1 = '';
foreach (Functions::flattenArray($matrixData1) as $arg) {
++$maxRow;
$funcArg1 = "A1:A$maxRow";
$this->setCell("A$maxRow", $arg);
}
$maxRow = 0;
$funcArg2 = '';
foreach (Functions::flattenArray($matrixData2) as $arg) {
++$maxRow;
$funcArg2 = "C1:C$maxRow";
$this->setCell("C$maxRow", $arg);
}
$sheet->getCell('B1')->setValue("=SUMX2PY2($funcArg1, $funcArg2)");
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerSUMX2PY2(): array
{
return require 'tests/data/Calculation/MathTrig/SUMX2PY2.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RoundTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RoundTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class RoundTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerRound')]
public function testRound(float|int|string $expectedResult, float|int|string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=ROUND($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerRound(): array
{
return require 'tests/data/Calculation/MathTrig/ROUND.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerRoundArray')]
public function testRoundArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=ROUND({$argument1},{$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerRoundArray(): array
{
return [
'first argument row vector' => [
[[0.145, 1.373, -931.683, 3.142]],
'{0.14527, 1.3725, -931.6829, 3.14159265}',
'3',
],
'first argument column vector' => [
[[0.145], [1.373], [-931.683], [3.142]],
'{0.14527; 1.3725; -931.6829; 3.14159265}',
'3',
],
'first argument matrix' => [
[[0.145, 1.373], [-931.683, 3.142]],
'{0.14527, 1.3725; -931.6829, 3.14159265}',
'3',
],
'second argument row vector' => [
[[0.1, 0.12, 0.123, 0.1235, 0.12345]],
'0.12345',
'{1, 2, 3, 4, 5}',
],
'second argument column vector' => [
[[0.1], [0.12], [0.123], [0.1235], [0.12345]],
'0.12345',
'{1; 2; 3; 4; 5}',
],
'second argument matrix' => [
[[0.1, 0.12], [0.123, 0.1235]],
'0.12345',
'{1, 2; 3, 4}',
],
'A row and a column vector' => [
[
[0.1, 0.15, 0.145, 0.1453],
[1.4, 1.37, 1.373, 1.3725],
[-931.7, -931.68, -931.683, -931.6829],
[3.1, 3.14, 3.142, 3.1416],
],
'{0.14527; 1.37250; -931.68290; 3.14159265}',
'{1, 2, 3, 4}',
],
'Two row vectors' => [
[[0.1, 1.37, -931.683, 3.1416]],
'{0.14527, 1.37250, -931.68290, 3.14159265}',
'{1, 2, 3, 4}',
],
'Two different size row vectors' => [
[[0.1, 1.37]],
'{0.14527, 1.37250, -931.68290, 3.14159265}',
'{1, 2}',
],
'Two column vectors' => [
[[0.1], [1.37], [-931.683], [3.1416]],
'{0.14527; 1.37250; -931.68290; 3.14159265}',
'{1; 2; 3; 4}',
],
'Two matching square matrices' => [
[
[10000, 46000, 78900],
[23460, 56789, 89012.3],
[34567.89, 67890.123, 90123.4568],
],
'{12345.67890, 45678.90123, 78901.23456; 23456.78901, 56789.01234, 89012.34567; 34567.89012, 67890.12345, 90123.45678}',
'{-4, -3, -2; -1, 0, 1; 2, 3, 4}',
],
'Two paired 2x3 matrices' => [
[
[10000, 46000, 78900],
[23460, 56789, 89012.3],
],
'{12345.67890, 45678.90123, 78901.23456; 23456.78901, 56789.01234, 89012.34567}',
'{-4, -3, -2; -1, 0, 1}',
],
'Two paired 3x2 matrices' => [
[
[10000, 46000],
[23460, 56789],
[34567.89, 67890.123],
],
'{12345.67890, 45678.90123; 23456.78901, 56789.01234; 34567.89012, 67890.12345}',
'{-4, -3; -1, 0; 2, 3}',
],
'Two mismatched matrices (2x3 and 2x2)' => [
[
[10000, 46000],
[23460, 56789],
],
'{12345.67890, 45678.90123, 78901.23456; 23456.78901, 56789.01234, 89012.34567}',
'{-4, -3; -1, 0}',
],
'Two mismatched matrices (3x2 and 2x1 vector)' => [
[
[10000, 50000],
[23460, 56790],
],
'{12345.67890, 45678.90123; 23456.78901, 56789.01234; 34567.89012, 67890.12345}',
'{-4; -1}',
],
'Two mismatched matrices (3x1 vector and 2x2)' => [
[
[10000, 12000],
[23460, 23457],
],
'{12345.67890; 23456.78901; 34567.89012}',
'{-4, -3; -1, 0}',
],
'Two mismatched matrices (1x3 vector and 2x2)' => [
[
[10000, 46000],
[12350, 45679],
],
'{12345.67890, 45678.90123, 78901.23456}',
'{-4, -3; -1, 0}',
],
'Larger mismatched matrices (5x1 vector and 3x3)' => [
[
[3.1, 6.28, 9.425],
[12.6, 15.71, 18.85],
[22, 25.13, 28.274],
],
'{3.14159265, 6.2831853, 9.424777959; 12.5663706, 15.70796325, 18.8495559; 21.99114855, 25.1327412, 28.27433385}',
'{1, 2, 3, 4, 5}',
],
'Two different sized column vectors' => [
[[0.1], [1.37]],
'{0.14527; 1.37250}',
'{1; 2; 3; 4}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanhTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanhTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class AtanhTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerAtanh')]
public function testAtanh(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->getCell('A2')->setValue(0.8);
$sheet->getCell('A1')->setValue("=ATANH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
}
public static function providerAtanh(): array
{
return require 'tests/data/Calculation/MathTrig/ATANH.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerAtanhArray')]
public function testAtanhArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=ATANH({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerAtanhArray(): array
{
return [
'row vector' => [[[1.83178082306482, 0.54930614433406, -1.83178082306482]], '{0.95, 0.5, -0.95}'],
'column vector' => [[[1.83178082306482], [0.54930614433406], [-1.83178082306482]], '{0.95; 0.5; -0.95}'],
'matrix' => [[[1.83178082306482, 0.54930614433406], [0.0, -1.83178082306482]], '{0.95, 0.5; 0, -0.95}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumProduct2Test.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumProduct2Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as XlsxReader;
class SumProduct2Test extends AllSetupTeardown
{
public function testSUMPRODUCT(): void
{
$file = 'tests/data/Reader/XLSX/issue.3909b.xlsx';
$reader = new XlsxReader();
$this->spreadsheet = $reader->load($file);
$this->setArrayAsValue();
$sheet = $this->getSheet();
self::assertSame('=SUMPRODUCT(((calNames=I3)*(calTiers=$K$2))*calHours)', $sheet->getCell('K3')->getValue());
self::assertSame(40, $sheet->getCell('K3')->getCalculatedValue());
self::assertSame(4, $sheet->getCell('L3')->getCalculatedValue());
self::assertSame(40, $sheet->getCell('M3')->getCalculatedValue());
self::assertSame(4, $sheet->getCell('N3')->getCalculatedValue());
self::assertSame(40, $sheet->getCell('K4')->getCalculatedValue());
self::assertSame(0, $sheet->getCell('L4')->getCalculatedValue());
self::assertSame(40, $sheet->getCell('M4')->getCalculatedValue());
self::assertSame(0, $sheet->getCell('N4')->getCalculatedValue());
self::assertSame(24, $sheet->getCell('K5')->getCalculatedValue());
self::assertSame(0, $sheet->getCell('L5')->getCalculatedValue());
self::assertSame(24, $sheet->getCell('M5')->getCalculatedValue());
self::assertSame(0, $sheet->getCell('N5')->getCalculatedValue());
self::assertSame('=SUMPRODUCT(calHours*((calNames=I3)*(calTiers=$K$2)))', $sheet->getCell('I14')->getValue());
self::assertSame(40, $sheet->getCell('I14')->getCalculatedValue());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RandArrayTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RandArrayTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
class RandArrayTest extends AllSetupTeardown
{
public function testRANDARRAYInteger(): void
{
$rows = 3;
$cols = 2;
$min = -5;
$max = 5;
$result = MathTrig\Random::randArray($rows, $cols, $min, $max, true);
self::assertIsArray($result);
self::assertCount($rows, $result);
self::assertIsArray($result[0]);
self::assertCount($cols, $result[0]);
$values = Functions::flattenArray($result);
array_walk(
$values,
function (mixed $value) use ($min, $max): void {
self::assertIsInt($value);
self::assertTrue($value >= $min && $value <= $max);
}
);
}
public function testRANDARRAYFloat(): void
{
$rows = 3;
$cols = 2;
$min = -2;
$max = 2;
$result = MathTrig\Random::randArray($rows, $cols, $min, $max, false);
self::assertIsArray($result);
self::assertCount($rows, $result);
self::assertIsArray($result[0]);
self::assertCount($cols, $result[0]);
$values = Functions::flattenArray($result);
array_walk(
$values,
function (mixed $value) use ($min, $max): void {
self::assertIsFloat($value);
self::assertTrue($value >= $min && $value <= $max);
}
);
}
public function testRANDARRAYExceptions(): void
{
$rows = 'THREE';
$cols = 2;
$min = 2;
$max = -2;
$result = MathTrig\Random::randArray($rows, $cols, $min, $max, false);
self::assertSame(ExcelError::VALUE(), $result);
$rows = 3;
$cols = 2;
$min = 2;
$max = -2;
$result = MathTrig\Random::randArray($rows, $cols, $min, $max, false);
self::assertSame(ExcelError::VALUE(), $result);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FloorTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FloorTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PHPUnit\Framework\Attributes\DataProvider;
class FloorTest extends AllSetupTeardown
{
#[DataProvider('providerFLOOR')]
public function testFLOOR(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=FLOOR($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerFLOOR(): array
{
return require 'tests/data/Calculation/MathTrig/FLOOR.php';
}
public function testFLOORGnumericClashingSigns(): void
{
self::setGnumeric();
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=FLOOR(17,8)');
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta(16, $result, 1E-12);
$sheet->getCell('A2')->setValue('=FLOOR(-17,-8)');
$result = $sheet->getCell('A2')->getCalculatedValue();
self::assertEqualsWithDelta(-16, $result, 1E-12);
$sheet->getCell('A3')->setValue('=FLOOR(17,-8)');
$result = $sheet->getCell('A3')->getCalculatedValue();
self::assertSame('#NUM!', $result);
$sheet->getCell('A4')->setValue('=FLOOR(-17,8)');
$result = $sheet->getCell('A4')->getCalculatedValue();
self::assertSame('#NUM!', $result);
}
public function testFLOORGnumeric1Arg(): void
{
self::setGnumeric();
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=FLOOR(5.1)');
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta(5, $result, 1E-12);
}
public function testFLOOROpenOffice1Arg(): void
{
self::setOpenOffice();
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=FLOOR(5.1)');
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta(5, $result, 1E-12);
}
public function testFLOORExcel1Arg(): void
{
$this->mightHaveException('exception');
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=FLOOR(5.1)');
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta(5, $result, 1E-12);
}
#[DataProvider('providerFloorArray')]
public function testFloorArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=FLOOR({$argument1}, {$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerFloorArray(): array
{
return [
'matrix' => [[[3.14, 3.14], [3.14155, 3.141592]], '3.1415926536', '{0.01, 0.002; 0.00005, 0.000002}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CschTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CschTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class CschTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCSCH')]
public function testCSCH(float|int|string $expectedResult, float|int|string $angle): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=CSCH($angle)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
}
public static function providerCSCH(): array
{
return require 'tests/data/Calculation/MathTrig/CSCH.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerCschArray')]
public function testCschArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=CSCH({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerCschArray(): array
{
return [
'row vector' => [[[0.85091812823932, 1.91903475133494, -0.85091812823932]], '{1, 0.5, -1}'],
'column vector' => [[[0.85091812823932], [1.91903475133494], [-0.85091812823932]], '{1; 0.5; -1}'],
'matrix' => [[[0.85091812823932, 1.91903475133494], ['#DIV/0!', -0.85091812823932]], '{1, 0.5; 0, -1}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AbsTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AbsTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class AbsTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerAbs')]
public function testAbs(mixed $expectedResult, mixed $number = 'omitted'): void
{
$sheet = $this->getSheet();
$this->mightHaveException($expectedResult);
$this->setCell('A1', $number);
if ($number === 'omitted') {
$sheet->getCell('B1')->setValue('=ABS()');
} else {
$sheet->getCell('B1')->setValue('=ABS(A1)');
}
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
public static function providerAbs(): array
{
return require 'tests/data/Calculation/MathTrig/ABS.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerAbsArray')]
public function testAbsoluteArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=ABS({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerAbsArray(): array
{
return [
'row vector' => [[[1, 0, 1]], '{-1, 0, 1}'],
'column vector' => [[[1], [0], [1]], '{-1; 0; 1}'],
'matrix' => [[[1, 0], [1, 1.4]], '{-1, 0; 1, -1.4}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TruncTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TruncTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class TruncTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerTRUNC')]
public function testTRUNC(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=TRUNC($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerTRUNC(): array
{
return require 'tests/data/Calculation/MathTrig/TRUNC.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerTruncArray')]
public function testTruncArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=TRUNC({$argument1}, {$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerTruncArray(): array
{
return [
'matrix' => [[[3.14, 3.141], [3.14159, 3.14159265]], '3.1415926536', '{2, 3; 5, 8}'],
];
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerTooMuchPrecision')]
public function testTooMuchPrecision(mixed $expectedResult, float|int|string $value, int $digits = 1): void
{
// This test is pretty screwy. Possibly shouldn't even attempt it.
// At any rate, these results seem to indicate that PHP
// maximum precision is PHP_FLOAT_DIG - 1 digits, not PHP_FLOAT_DIG.
// If that changes, at least one of these tests will have to change.
$sheet = $this->getSheet();
$sheet->getCell('E1')->setValue($value);
$sheet->getCell('E2')->setValue("=TRUNC(E1,$digits)");
/** @var float|string */
$result = $sheet->getCell('E2')->getCalculatedValue();
self::assertSame($expectedResult, (string) $result);
}
public static function providerTooMuchPrecision(): array
{
$max64Plus1 = 9223372036854775808;
$stringMax = (string) $max64Plus1;
return [
'2 digits less than PHP_FLOAT_DIG' => ['1' . str_repeat('0', PHP_FLOAT_DIG - 4) . '1.2', 10.0 ** (PHP_FLOAT_DIG - 3) + 1.2, 1],
'1 digit less than PHP_FLOAT_DIG' => ['1' . str_repeat('0', PHP_FLOAT_DIG - 3) . '1', 10.0 ** (PHP_FLOAT_DIG - 2) + 1.2, 1],
'PHP_FLOAT_DIG' => ['1.0E+' . (PHP_FLOAT_DIG - 1), 10.0 ** (PHP_FLOAT_DIG - 1) + 1.2, 1],
'1 digit more than PHP_FLOAT_DIG' => ['1.0E+' . PHP_FLOAT_DIG, 10.0 ** PHP_FLOAT_DIG + 1.2, 1],
'32bit exceed int max' => ['3123456780', 3123456789, -1],
'64bit exceed int max neg decimals' => [$stringMax, $max64Plus1, -1],
'64bit exceed int max pos decimals' => [$stringMax, $max64Plus1, 1],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/OddTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/OddTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class OddTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerODD')]
public function testODD(int|string $expectedResult, float|int|string $value): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue("=ODD($value)");
$sheet->getCell('A2')->setValue(3.7);
self::assertEquals($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
}
public static function providerODD(): array
{
return require 'tests/data/Calculation/MathTrig/ODD.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerOddArray')]
public function testOddArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=ODD({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerOddArray(): array
{
return [
'row vector' => [[[-3, 1, 5]], '{-3, 1, 4}'],
'column vector' => [[[-3], [1], [5]], '{-3; 1; 4}'],
'matrix' => [[[-3, 1], [5, 3]], '{-3, 1; 4, 1.5}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CeilingMathTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CeilingMathTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class CeilingMathTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCEILINGMATH')]
public function testCEILINGMATH(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=CEILING.MATH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerCEILINGMATH(): array
{
return require 'tests/data/Calculation/MathTrig/CEILINGMATH.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerCeilingArray')]
public function testCeilingArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=CEILING.MATH({$argument1}, {$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerCeilingArray(): array
{
return [
'matrix' => [[[3.15, 3.142], [3.1416, 3.141594]], '3.1415926536', '{0.01, 0.002; 0.00005, 0.000002}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/GcdTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/GcdTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
class GcdTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerGCD')]
public function testGCD(mixed $expectedResult, mixed ...$args): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$row = 0;
foreach ($args as $arg) {
++$row;
if ($arg !== null) {
$sheet->getCell("A$row")->setValue($arg);
}
}
if ($row < 1) {
$sheet->getCell('B1')->setValue('=GCD()');
} else {
$sheet->getCell('B1')->setValue("=GCD(A1:A$row)");
}
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerGCD(): array
{
return require 'tests/data/Calculation/MathTrig/GCD.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RoundDownTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RoundDownTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class RoundDownTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerRoundDown')]
public function testRoundDown(float|int|string $expectedResult, float|int|string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=ROUNDDOWN($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerRoundDown(): array
{
return require 'tests/data/Calculation/MathTrig/ROUNDDOWN.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerRoundDownArray')]
public function testRoundDownArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=ROUNDDOWN({$argument1},{$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerRoundDownArray(): array
{
return [
'first argument row vector' => [
[[0.145, 1.372, -931.682, 3.141]],
'{0.14527, 1.3725, -931.6829, 3.14159265}',
'3',
],
'first argument column vector' => [
[[0.145], [1.372], [-931.682], [3.141]],
'{0.14527; 1.3725; -931.6829; 3.14159265}',
'3',
],
'first argument matrix' => [
[[0.145, 1.372], [-931.682, 3.141]],
'{0.14527, 1.3725; -931.6829, 3.14159265}',
'3',
],
'second argument row vector' => [
[[0.1, 0.14, 0.145, 0.1452, 0.14527]],
'0.14527',
'{1, 2, 3, 4, 5}',
],
'second argument column vector' => [
[[0.1], [0.14], [0.145], [0.1452], [0.14527]],
'0.14527',
'{1; 2; 3; 4; 5}',
],
'second argument matrix' => [
[[0.1, 0.14], [0.145, 0.1452]],
'0.14527',
'{1, 2; 3, 4}',
],
'A row and a column vector' => [
[
[0.1, 0.14, 0.145, 0.1452],
[1.3, 1.37, 1.372, 1.3725],
[-931.6, -931.68, -931.682, -931.6829],
[3.1, 3.14, 3.141, 3.1415],
],
'{0.14527; 1.37250; -931.68290; 3.14159265}',
'{1, 2, 3, 4}',
],
'Two row vectors' => [
[[0.1, 1.37, -931.682, 3.1415]],
'{0.14527, 1.37250, -931.68290, 3.14159265}',
'{1, 2, 3, 4}',
],
'Two column vectors' => [
[[0.1], [1.37], [-931.682], [3.1415]],
'{0.14527; 1.37250; -931.68290; 3.14159265}',
'{1; 2; 3; 4}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SqrtPiTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SqrtPiTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class SqrtPiTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerSQRTPI')]
public function testSQRTPI(mixed $expectedResult, mixed $number): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
if ($number !== null) {
$sheet->getCell('A1')->setValue($number);
}
if ($number === 'omitted') {
$sheet->getCell('B1')->setValue('=SQRTPI()');
} else {
$sheet->getCell('B1')->setValue('=SQRTPI(A1)');
}
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerSQRTPI(): array
{
return require 'tests/data/Calculation/MathTrig/SQRTPI.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerSqrtPiArray')]
public function testSqrtPiArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=SQRTPI({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
}
public static function providerSqrtPiArray(): array
{
return [
'row vector' => [[[5.317361552716, 6.2665706865775, 8.6832150546992]], '{9, 12.5, 24}'],
'column vector' => [[[5.3173615527166], [6.2665706865775], [8.6832150546992]], '{9; 12.5; 24}'],
'matrix' => [[[5.3173615527166, 6.2665706865775], [8.6832150546992, 14.1796308072441]], '{9, 12.5; 24, 64}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CoshTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CoshTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class CoshTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCosh')]
public function testCosh(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 2);
$sheet->getCell('A1')->setValue("=COSH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
}
public static function providerCosh(): array
{
return require 'tests/data/Calculation/MathTrig/COSH.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerCoshArray')]
public function testCoshArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=COSH({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerCoshArray(): array
{
return [
'row vector' => [[[1.54308063481524, 1.12762596520638, 1.54308063481524]], '{1, 0.5, -1}'],
'column vector' => [[[1.54308063481524], [1.12762596520638], [1.54308063481524]], '{1; 0.5; -1}'],
'matrix' => [[[1.54308063481524, 1.12762596520638], [1.0, 1.54308063481524]], '{1, 0.5; 0, -1}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MInverseTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MInverseTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PHPUnit\Framework\Attributes\DataProvider;
class MInverseTest extends AllSetupTeardown
{
/** @param mixed[] $args */
#[DataProvider('providerMINVERSE')]
public function testMINVERSE(mixed $expectedResult, array $args): void
{
$result = MathTrig\MatrixFunctions::inverse($args);
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
}
public static function providerMINVERSE(): array
{
return require 'tests/data/Calculation/MathTrig/MINVERSE.php';
}
public function testOnSpreadsheet(): void
{
// very limited ability to test this in the absence of dynamic arrays
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=MINVERSE({1,2,3})'); // not square
self::assertSame('#VALUE!', $sheet->getCell('A1')->getCalculatedValue());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ArabicTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ArabicTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class ArabicTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerARABIC')]
public function testARABIC(mixed $expectedResult, string $romanNumeral): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue($romanNumeral);
$sheet->getCell('B1')->setValue('=ARABIC(A1)');
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
public static function providerARABIC(): array
{
return require 'tests/data/Calculation/MathTrig/ARABIC.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerArabicArray')]
public function testArabicArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=ARABIC({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerArabicArray(): array
{
return [
'row vector' => [[[49, 2022, 499]], '{"XLIX", "MMXXII", "VDIV"}'],
'column vector' => [[[49], [2022], [499]], '{"XLIX"; "MMXXII"; "VDIV"}'],
'matrix' => [[[49, 2022], [-499, 499]], '{"XLIX", "MMXXII"; "-ID", "VDIV"}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumIfsTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumIfsTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
class SumIfsTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerSUMIFS')]
public function testSUMIFS(mixed $expectedResult, mixed ...$args): void
{
$result = Statistical\Conditional::SUMIFS(...$args);
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerSUMIFS(): array
{
return require 'tests/data/Calculation/MathTrig/SUMIFS.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcoshTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcoshTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class AcoshTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerAcosh')]
public function testAcosh(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->getCell('A2')->setValue('1.5');
$sheet->getCell('A1')->setValue("=ACOSH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
}
public static function providerAcosh(): array
{
return require 'tests/data/Calculation/MathTrig/ACOSH.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerAcoshArray')]
public function testAcoshArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=ACOSH({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerAcoshArray(): array
{
return [
'row vector' => [[[0.0, 1.31695789692482, 1.76274717403909]], '{1, 2, 3}'],
'column vector' => [[[0.0], [1.31695789692482], [1.76274717403909]], '{1; 2; 3}'],
'matrix' => [[[0.0, 1.31695789692482], [1.76274717403909, 2.06343706889556]], '{1, 2; 3, 4}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ExpTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ExpTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class ExpTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerEXP')]
public function testEXP(mixed $expectedResult, mixed $number = 'omitted'): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
if ($number !== null) {
$sheet->getCell('A1')->setValue($number);
}
if ($number === 'omitted') {
$sheet->getCell('B1')->setValue('=EXP()');
} else {
$sheet->getCell('B1')->setValue('=EXP(A1)');
}
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerEXP(): array
{
return require 'tests/data/Calculation/MathTrig/EXP.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerExpArray')]
public function testExpArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=EXP({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerExpArray(): array
{
return [
'row vector' => [[[1.0, 2.718281828459045, 12.182493960703473]], '{0, 1, 2.5}'],
'column vector' => [[[1.0], [2.718281828459045], [12.182493960703473]], '{0; 1; 2.5}'],
'matrix' => [[[1.0, 2.718281828459045], [12.182493960703473, 0.0820849986239]], '{0, 1; 2.5, -2.5}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcothTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcothTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class AcothTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerACOTH')]
public function testACOTH(float|int|string $expectedResult, float|int|string $number): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -10);
$sheet->getCell('A1')->setValue("=ACOTH($number)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
}
public static function providerACOTH(): array
{
return require 'tests/data/Calculation/MathTrig/ACOTH.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerAcothArray')]
public function testAcothArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=ACOTH({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerAcothArray(): array
{
return [
'row vector' => [[[-0.20273255405408, 0.54930614433406, 0.13413199329734]], '{-5, 2, 7.5}'],
'column vector' => [[[-0.20273255405408], [0.54930614433406], [0.13413199329734]], '{-5; 2; 7.5}'],
'matrix' => [[[-0.20273255405408, 0.54930614433406], ['#NUM!', 0.13413199329734]], '{-5, 2; 0, 7.5}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CombinTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CombinTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class CombinTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCOMBIN')]
public function testCOMBIN(mixed $expectedResult, mixed $numObjs, mixed $numInSet): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
if ($numObjs !== null) {
$sheet->getCell('A1')->setValue($numObjs);
}
if ($numInSet !== null) {
$sheet->getCell('A2')->setValue($numInSet);
}
$sheet->getCell('B1')->setValue('=COMBIN(A1,A2)');
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public static function providerCOMBIN(): array
{
return require 'tests/data/Calculation/MathTrig/COMBIN.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerCombinArray')]
public function testCombinArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=COMBIN({$argument1},{$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerCombinArray(): array
{
return [
'first argument row vector' => [
[[56, 10]],
'{8, 5}',
'3',
],
'first argument column vector' => [
[[56], [10]],
'{8; 5}',
'3',
],
'first argument matrix' => [
[[56, 10], [1, 35]],
'{8, 5; 3, 7}',
'3',
],
'second argument row vector' => [
[[286, 1716]],
'13',
'{3, 6}',
],
'second argument column vector' => [
[[286], [1716]],
'13',
'{3; 6}',
],
'second argument matrix' => [
[[286, 1716], [715, 1287]],
'13',
'{3, 6; 4, 8}',
],
'A row and a column vector' => [
[
[792, 495, 220, 66],
[252, 210, 120, 45],
[56, 70, 56, 28],
[6, 15, 20, 15],
],
'{12; 10; 8; 6}',
'{5, 4, 3, 2}',
],
'Two row vectors' => [
[[792, 210, 56, 15]],
'{12, 10, 8, 6}',
'{5, 4, 3, 2}',
],
'Two column vectors' => [
[[792], [210], [56], [15]],
'{12; 10; 8; 6}',
'{5; 4; 3; 2}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SignTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SignTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class SignTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerSIGN')]
public function testSIGN(float|int|string $expectedResult, float|int|string $value): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 0);
$sheet->setCellValue('A4', -3.8);
$sheet->getCell('A1')->setValue("=SIGN($value)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public static function providerSIGN(): array
{
return require 'tests/data/Calculation/MathTrig/SIGN.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerSignArray')]
public function testSignArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=SIGN({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerSignArray(): array
{
return [
'row vector' => [[[-1, 0, 1]], '{-1.5, 0, 0.3}'],
'column vector' => [[[-1], [0], [1]], '{-1.5; 0; 0.3}'],
'matrix' => [[[-1, 0], [1, 1]], '{-1.5, 0; 0.3, 12.5}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MMultTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MMultTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig;
use PHPUnit\Framework\Attributes\DataProvider;
class MMultTest extends AllSetupTeardown
{
#[DataProvider('providerMMULT')]
public function testMMULT(mixed $expectedResult, mixed ...$args): void
{
$result = MathTrig\MatrixFunctions::multiply(...$args);
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
}
public static function providerMMULT(): array
{
return require 'tests/data/Calculation/MathTrig/MMULT.php';
}
public function testOnSpreadsheet(): void
{
// very limited ability to test this in the absence of dynamic arrays
$this->setArrayAsValue();
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=MMULT({1,2,3}, {1,2,3})'); // incompatible dimensions
self::assertSame('#VALUE!', $sheet->getCell('A1')->getCalculatedValue());
$sheet->getCell('A11')->setValue('=MMULT({1, 2, 3, 4}, {5; 6; 7; 8})');
self::assertEquals(70, $sheet->getCell('A11')->getCalculatedValue());
$sheet->getCell('A2')->setValue(1);
$sheet->getCell('B2')->setValue(2);
$sheet->getCell('C2')->setValue(3);
$sheet->getCell('D2')->setValue(4);
$sheet->getCell('D3')->setValue(5);
$sheet->getCell('D4')->setValue(6);
$sheet->getCell('A12')->setValue('=MMULT(A2:C2,D2:D4)');
self::assertEquals(32, $sheet->getCell('A12')->getCalculatedValue());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SecTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SecTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class SecTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerSEC')]
public function testSEC(float|int|string $expectedResult, float|int|string $angle): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=SEC($angle)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
}
public static function providerSEC(): array
{
return require 'tests/data/Calculation/MathTrig/SEC.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerSecArray')]
public function testSecArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=SEC({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerSecArray(): array
{
return [
'row vector' => [[[1.85081571768093, 1.13949392732455, 1.85081571768093]], '{1, 0.5, -1}'],
'column vector' => [[[1.85081571768093], [1.13949392732455], [1.85081571768093]], '{1; 0.5; -1}'],
'matrix' => [[[1.85081571768093, 1.13949392732455], [1.0, 1.85081571768093]], '{1, 0.5; 0, -1}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/BaseTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/BaseTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class BaseTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerBASE')]
public function testBASE(mixed $expectedResult, mixed $arg1 = 'omitted', mixed $arg2 = 'omitted', mixed $arg3 = 'omitted'): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
if ($arg1 !== null) {
$sheet->getCell('A1')->setValue($arg1);
}
if ($arg2 !== null) {
$sheet->getCell('A2')->setValue($arg2);
}
if ($arg3 !== null) {
$sheet->getCell('A3')->setValue($arg3);
}
if ($arg1 === 'omitted') {
$sheet->getCell('B1')->setValue('=BASE()');
} elseif ($arg2 === 'omitted') {
$sheet->getCell('B1')->setValue('=BASE(A1)');
} elseif ($arg3 === 'omitted') {
$sheet->getCell('B1')->setValue('=BASE(A1, A2)');
} else {
$sheet->getCell('B1')->setValue('=BASE(A1, A2, A3)');
}
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public static function providerBASE(): array
{
return require 'tests/data/Calculation/MathTrig/BASE.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerBaseArray')]
public function testBaseArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=BASE({$argument1}, {$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerBaseArray(): array
{
return [
'matrix' => [[['1111111', '177'], ['127', '7F']], '127', '{2, 8; 10, 16}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/IntTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/IntTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class IntTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerINT')]
public function testINT(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=INT($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerINT(): array
{
return require 'tests/data/Calculation/MathTrig/INT.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerIntArray')]
public function testIntArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=INT({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerIntArray(): array
{
return [
'row vector' => [[[-2, 0, 0]], '{-1.5, 0, 0.3}'],
'column vector' => [[[-2], [0], [0]], '{-1.5; 0; 0.3}'],
'matrix' => [[[-2, 0], [0, 12]], '{-1.5, 0; 0.3, 12.5}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RadiansTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RadiansTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class RadiansTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerRADIANS')]
public function testRADIANS(mixed $expectedResult, mixed $number = 'omitted'): void
{
$sheet = $this->getSheet();
$this->mightHaveException($expectedResult);
$this->setCell('A1', $number);
if ($number === 'omitted') {
$sheet->getCell('B1')->setValue('=RADIANS()');
} else {
$sheet->getCell('B1')->setValue('=RADIANS(A1)');
}
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
}
public static function providerRADIANS(): array
{
return require 'tests/data/Calculation/MathTrig/RADIANS.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerRadiansArray')]
public function testRadiansArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=RADIANS({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerRadiansArray(): array
{
return [
'row vector' => [[[1.48352986419518, 3.92699081698724, -0.26179938779915]], '{85, 225, -15}'],
'column vector' => [[[1.48352986419518], [3.92699081698724], [-0.26179938779915]], '{85; 225; -15}'],
'matrix' => [[[1.48352986419518, 3.92699081698724], [7.85398163397448, -0.26179938779915]], '{85, 225; 450, -15}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/PowerTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/PowerTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class PowerTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerPOWER')]
public function testPOWER(mixed $expectedResult, mixed $base = 'omitted', mixed $exponent = 'omitted'): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
if ($base !== null) {
$sheet->getCell('A1')->setValue($base);
}
if ($exponent !== null) {
$sheet->getCell('A2')->setValue($exponent);
}
if ($base === 'omitted') {
$sheet->getCell('B1')->setValue('=POWER()');
} elseif ($exponent === 'omitted') {
$sheet->getCell('B1')->setValue('=POWER(A1)');
} else {
$sheet->getCell('B1')->setValue('=POWER(A1,A2)');
}
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerPOWER(): array
{
return require 'tests/data/Calculation/MathTrig/POWER.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerPowerArray')]
public function testPowerArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=POWER({$argument1}, {$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerPowerArray(): array
{
return [
'matrix' => [[[729, 512, 343], [216, 125, 64], [27, 8, 1]], '{9, 8, 7; 6, 5, 4; 3, 2, 1}', '3'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CeilingTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CeilingTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PHPUnit\Framework\Attributes\DataProvider;
class CeilingTest extends AllSetupTeardown
{
#[DataProvider('providerCEILING')]
public function testCEILING(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=CEILING($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerCEILING(): array
{
return require 'tests/data/Calculation/MathTrig/CEILING.php';
}
public function testCEILINGGnumericClashingSigns(): void
{
self::setGnumeric();
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=CEILING(17,8)');
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta(24, $result, 1E-12);
$sheet->getCell('A2')->setValue('=CEILING(-17,-8)');
$result = $sheet->getCell('A2')->getCalculatedValue();
self::assertEqualsWithDelta(-24, $result, 1E-12);
$sheet->getCell('A3')->setValue('=CEILING(17,-8)');
$result = $sheet->getCell('A3')->getCalculatedValue();
self::assertSame('#NUM!', $result);
$sheet->getCell('A4')->setValue('=CEILING(-17,8)');
$result = $sheet->getCell('A4')->getCalculatedValue();
self::assertSame('#NUM!', $result);
}
public function testCEILINGGnumeric1Arg(): void
{
self::setGnumeric();
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=CEILING(5.1)');
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta(6, $result, 1E-12);
}
public function testCELINGOpenOffice1Arg(): void
{
self::setOpenOffice();
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=CEILING(5.1)');
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta(6, $result, 1E-12);
}
public function testCEILINGExcel1Arg(): void
{
$this->mightHaveException('exception');
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=CEILING(5.1)');
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta(6, $result, 1E-12);
}
#[DataProvider('providerCeilingArray')]
public function testCeilingArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=CEILING({$argument1}, {$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerCeilingArray(): array
{
return [
'matrix' => [[[3.15, 3.142], [3.1416, 3.141594]], '3.1415926536', '{0.01, 0.002; 0.00005, 0.000002}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class AsinTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerAsin')]
public function testAsin(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->getCell('A2')->setValue(0.5);
$sheet->getCell('A1')->setValue("=ASIN($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
}
public static function providerAsin(): array
{
return require 'tests/data/Calculation/MathTrig/ASIN.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerAsinArray')]
public function testAsinArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=ASIN({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerAsinArray(): array
{
return [
'row vector' => [[[1.57079632679490, 0.52359877559830, -1.57079632679490]], '{1, 0.5, -1}'],
'column vector' => [[[1.57079632679490], [0.52359877559830], [-1.57079632679490]], '{1; 0.5; -1}'],
'matrix' => [[[1.57079632679490, 0.52359877559830], [0.0, -1.57079632679490]], '{1, 0.5; 0, -1}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/EvenTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/EvenTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class EvenTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerEVEN')]
public function testEVEN(int|string $expectedResult, float|int|string $value): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue("=EVEN($value)");
$sheet->getCell('A2')->setValue(3.7);
self::assertEquals($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
}
public static function providerEVEN(): array
{
return require 'tests/data/Calculation/MathTrig/EVEN.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerEvenArray')]
public function testEvenArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=EVEN({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerEvenArray(): array
{
return [
'row vector' => [[[-4, 2, 4]], '{-3, 1, 4}'],
'column vector' => [[[-4], [2], [4]], '{-3; 1; 4}'],
'matrix' => [[[-4, 2], [4, 2]], '{-3, 1; 4, 1.5}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/PiTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/PiTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
class PiTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerPI')]
public function testPI(mixed $expectedResult, mixed $number = 'omitted'): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
if ($number !== null) {
$sheet->getCell('A1')->setValue($number);
}
if ($number === 'omitted') {
$sheet->getCell('B1')->setValue('=PI()');
} else {
$sheet->getCell('B1')->setValue('=PI(A1)');
}
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerPI(): array
{
return require 'tests/data/Calculation/MathTrig/PI.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SubTotalTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SubTotalTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column;
use PhpOffice\PhpSpreadsheet\Worksheet\AutoFilter\Column\Rule;
use PHPUnit\Framework\Attributes\DataProvider;
class SubTotalTest extends AllSetupTeardown
{
#[DataProvider('providerSUBTOTAL')]
public function testSubtotal(float|int|string $expectedResult, float|int|string $type): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->fromArray([[0], [1], [1], [2], [3], [5], [8], [13], [21], [34], [55], [89]], null, 'A1', true);
$maxCol = $sheet->getHighestColumn();
$maxRow = $sheet->getHighestRow();
$sheet->getCell('D2')->setValue("=SUBTOTAL($type, A1:$maxCol$maxRow)");
$result = $sheet->getCell('D2')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerSUBTOTAL(): array
{
return require 'tests/data/Calculation/MathTrig/SUBTOTAL.php';
}
#[DataProvider('providerSUBTOTAL')]
public function testSubtotalColumnHidden(float|int|string $expectedResult, float|int|string $type): void
{
// Hidden columns don't affect calculation, only hidden rows
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->fromArray([0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89], null, 'A1', true);
$maxCol = $sheet->getHighestColumn();
$maxRow = $sheet->getHighestRow();
$hiddenColumns = [
'A' => false,
'B' => true,
'C' => false,
'D' => true,
'E' => false,
'F' => false,
'G' => false,
'H' => true,
'I' => false,
'J' => true,
'K' => true,
'L' => false,
];
foreach ($hiddenColumns as $col => $hidden) {
$columnDimension = $sheet->getColumnDimension($col);
$columnDimension->setVisible($hidden);
}
$sheet->getCell('D2')->setValue("=SUBTOTAL($type, A1:$maxCol$maxRow)");
$result = $sheet->getCell('D2')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
#[DataProvider('providerSUBTOTALHIDDEN')]
public function testSubtotalRowHidden(mixed $expectedResult, int $type): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->fromArray([[0], [1], [1], [2], [3], [5], [8], [13], [21], [34], [55], [89]], null, 'A1', true);
$maxCol = $sheet->getHighestColumn();
$maxRow = $sheet->getHighestRow();
$visibleRows = [
'1' => false,
'2' => true,
'3' => false,
'4' => true,
'5' => false,
'6' => false,
'7' => false,
'8' => true,
'9' => false,
'10' => true,
'11' => true,
'12' => false,
];
foreach ($visibleRows as $row => $visible) {
$rowDimension = $sheet->getRowDimension((int) $row);
$rowDimension->setVisible($visible);
}
$sheet->getCell('D2')->setValue("=SUBTOTAL($type, A1:$maxCol$maxRow)");
$result = $sheet->getCell('D2')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerSUBTOTALHIDDEN(): array
{
return require 'tests/data/Calculation/MathTrig/SUBTOTALHIDDEN.php';
}
public function testSubtotalNested(): void
{
$sheet = $this->getSheet();
$sheet->fromArray(
[
[123],
[234],
['=SUBTOTAL(1,A1:A2)'],
['=ROMAN(SUBTOTAL(1, A1:A2))'],
['This is text containing "=" and "SUBTOTAL("'],
['=AGGREGATE(1, 0, A1:A2)'],
['=SUM(2, 3)'],
],
null,
'A1',
true
);
$maxCol = $sheet->getHighestColumn();
$maxRow = $sheet->getHighestRow();
$sheet->getCell('H1')->setValue("=SUBTOTAL(9, A1:$maxCol$maxRow)");
self::assertEquals(362, $sheet->getCell('H1')->getCalculatedValue());
}
public function testRefError(): void
{
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=SUBTOTAL(9, #REF!)');
self::assertEquals('#REF!', $sheet->getCell('A1')->getCalculatedValue());
}
public function testSecondaryRefError(): void
{
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=SUBTOTAL(9, B1:B9,#REF!,C1:C9)');
self::assertEquals('#REF!', $sheet->getCell('A1')->getCalculatedValue());
}
public function testNonStringSingleCellRefError(): void
{
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=SUBTOTAL(9, 1, C1, Sheet99!A11)');
self::assertEquals('#REF!', $sheet->getCell('A1')->getCalculatedValue());
}
public function testNonStringCellRangeRefError(): void
{
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=SUBTOTAL(9, Sheet99!A1)');
self::assertEquals('#REF!', $sheet->getCell('A1')->getCalculatedValue());
}
public function testTypesOfHidden(): void
{
$worksheet = $this->getSheet();
$worksheet->SetCellValue('A1', 'Status');
$worksheet->SetCellValue('B1', 'Amount');
$worksheet->SetCellValue('A2', 'Active');
$worksheet->SetCellValue('B2', 500);
$worksheet->SetCellValue('A3', 'Snoozed');
$worksheet->SetCellValue('B3', 700);
$worksheet->SetCellValue('A4', 'Active');
$worksheet->SetCellValue('B4', 300);
$worksheet->setAutoFilter('A1:B4');
$autoFilter = $worksheet->getAutoFilter();
$autoFilter->getColumn('A')
->setFilterType(Column::AUTOFILTER_FILTERTYPE_FILTER)
->createRule()
->setRule(
Rule::AUTOFILTER_COLUMN_RULE_EQUAL,
'Active'
);
$autoFilter->showHideRows(); // row 3 is filtered
$worksheet->getRowDimension(4)->setVisible(false); // row 4 is hidden but not filtered
$worksheet->SetCellValue('D14', '=SUM(B2:B4)');
self::assertSame(
1500,
$worksheet->getCell('D14')->getCalculatedValue(),
'all 3 rows are considered'
);
$worksheet->SetCellValue('D15', '=SUBTOTAL(109,B2:B4)');
self::assertSame(
500,
$worksheet->getCell('D15')->getCalculatedValue(),
'excude row 3 (filtered) and row 4 (hidden)'
);
$worksheet->SetCellValue('D16', '=SUBTOTAL(9,B2:B4)');
self::assertSame(
800,
$worksheet->getCell('D16')->getCalculatedValue(),
'exclude row 3 (filtered) but include row 4 (hidden)'
);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MultinomialTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MultinomialTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
class MultinomialTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerMULTINOMIAL')]
public function testMULTINOMIAL(mixed $expectedResult, mixed ...$args): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$row = 0;
$excelArg = '';
foreach ($args as $arg) {
++$row;
$excelArg = "A1:A$row";
if ($arg !== null) {
$sheet->getCell("A$row")->setValue($arg);
}
}
$sheet->getCell('B1')->setValue("=MULTINOMIAL($excelArg)");
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerMULTINOMIAL(): array
{
return require 'tests/data/Calculation/MathTrig/MULTINOMIAL.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumSqTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumSqTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
class SumSqTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerSUMSQ')]
public function testSUMSQ(mixed $expectedResult, mixed ...$args): void
{
$this->mightHaveException($expectedResult);
$maxRow = 0;
$funcArg = '';
$sheet = $this->getSheet();
foreach ($args as $arg) {
++$maxRow;
$funcArg = "A1:A$maxRow";
if ($arg !== null) {
$sheet->getCell("A$maxRow")->setValue($arg);
}
}
$sheet->getCell('B1')->setValue("=SUMSQ($funcArg)");
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerSUMSQ(): array
{
return require 'tests/data/Calculation/MathTrig/SUMSQ.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SequenceTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SequenceTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\MathTrig\MatrixFunctions;
class SequenceTest extends AllSetupTeardown
{
/**
* @param mixed[] $arguments
* @param mixed[]|string $expectedResult
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerSEQUENCE')]
public function testSEQUENCE(array $arguments, array|string $expectedResult): void
{
if (count($arguments) === 0) {
$result = MatrixFunctions::sequence();
} elseif (count($arguments) === 1) {
$result = MatrixFunctions::sequence($arguments[0]);
} elseif (count($arguments) === 2) {
$result = MatrixFunctions::sequence($arguments[0], $arguments[1]);
} elseif (count($arguments) === 3) {
$result = MatrixFunctions::sequence($arguments[0], $arguments[1], $arguments[2]);
} else {
$result = MatrixFunctions::sequence($arguments[0], $arguments[1], $arguments[2], $arguments[3]);
}
self::assertEquals($expectedResult, $result);
}
public static function providerSEQUENCE(): array
{
return require 'tests/data/Calculation/MathTrig/SEQUENCE.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RomanTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RomanTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class RomanTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerROMAN')]
public function testROMAN(string $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A3', 49);
$sheet->getCell('A1')->setValue("=ROMAN($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public static function providerROMAN(): array
{
return require 'tests/data/Calculation/MathTrig/ROMAN.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerRomanArray')]
public function testRomanArray(array $expectedResult, string $values, string $styles): void
{
$calculation = Calculation::getInstance();
$formula = "=ROMAN({$values}, {$styles})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerRomanArray(): array
{
return [
'row vector' => [[['XLIX', 'MMXXII', 'CDXCIX']], '{49, 2022, 499}', '0'],
'column vector' => [[['XLIX'], ['MMXXII'], ['CDXCIX']], '{49; 2022; 499}', '0'],
'matrix' => [[['XLIX', 'MMXXII'], ['LXIV', 'CDXCIX']], '{49, 2022; 64, 499}', '0'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumIfTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumIfTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException;
use PHPUnit\Framework\Attributes\DataProvider;
class SumIfTest extends AllSetupTeardown
{
/**
* @param mixed[] $array1
* @param null|mixed[] $array2
*/
#[DataProvider('providerSUMIF')]
public function testSUMIF2(mixed $expectedResult, array $array1, mixed $condition, ?array $array2 = null): void
{
$this->mightHaveException($expectedResult);
if ($expectedResult === 'incomplete') {
self::markTestIncomplete('Raises formula error - researching solution');
}
$this->setArrayAsValue();
$sheet = $this->getSheet();
$sheet->fromArray($array1, null, 'A1', true);
$maxARow = count($array1);
$firstArg = "A1:A$maxARow";
$this->setCell('B1', $condition);
$secondArg = 'B1';
if (empty($array2)) {
$sheet->getCell('D1')->setValue("=SUMIF($firstArg, $secondArg)");
} else {
$sheet->fromArray($array2, null, 'C1', true);
$maxCRow = count($array2);
$thirdArg = "C1:C$maxCRow";
$sheet->getCell('D1')->setValue("=SUMIF($firstArg, $secondArg, $thirdArg)");
}
$result = $sheet->getCell('D1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerSUMIF(): array
{
return require 'tests/data/Calculation/MathTrig/SUMIF.php';
}
public function testOutliers(): void
{
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=SUMIF(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('A4')->setValue('=SUMIF(#REF!,"<32")');
self::assertSame('#REF!', $sheet->getCell('A4')->getCalculatedValue());
$sheet->getCell('A5')->setValue('=SUMIF(D1:D4, 1, #REF!)');
self::assertSame('#REF!', $sheet->getCell('A5')->getCalculatedValue());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SeriesSumTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SeriesSumTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class SeriesSumTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerSERIESSUM')]
public function testSERIESSUM(mixed $expectedResult, mixed $arg1, mixed $arg2, mixed $arg3, mixed ...$args): void
{
$sheet = $this->getSheet();
if ($arg1 !== null) {
$sheet->getCell('C1')->setValue($arg1);
}
if ($arg2 !== null) {
$sheet->getCell('C2')->setValue($arg2);
}
if ($arg3 !== null) {
$sheet->getCell('C3')->setValue($arg3);
}
$row = 0;
$aArgs = Functions::flattenArray($args);
foreach ($aArgs as $arg) {
++$row;
if ($arg !== null) {
$sheet->getCell("A$row")->setValue($arg);
}
}
$sheet->getCell('B1')->setValue("=SERIESSUM(C1, C2, C3, A1:A$row)");
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerSERIESSUM(): array
{
return require 'tests/data/Calculation/MathTrig/SERIESSUM.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerSeriesSumArray')]
public function testSeriesSumArray(array $expectedResult, string $x, string $n, string $m, string $values): void
{
$calculation = Calculation::getInstance();
$formula = "=SERIESSUM({$x}, {$n}, {$m}, {$values})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerSeriesSumArray(): array
{
return [
'row vector #1' => [[[3780, 756]], '5', '{1, 0}', '1', '{1, 1, 0, 1, 1}'],
'column vector #1' => [[[54], [3780]], '{2; 5}', '1', '1', '{1, 1, 0, 1, 1}'],
'matrix #1' => [[[54, 27], [3780, 756]], '{2; 5}', '{1, 0}', '1', '{1, 1, 0, 1, 1}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/Log10Test.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/Log10Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class Log10Test extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerLOG10')]
public function testLOG10(mixed $expectedResult, mixed $number = 'omitted'): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
if ($number !== null) {
$sheet->getCell('A1')->setValue($number);
}
if ($number === 'omitted') {
$sheet->getCell('B1')->setValue('=LOG10()');
} else {
$sheet->getCell('B1')->setValue('=LOG10(A1)');
}
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
}
public static function providerLOG10(): array
{
return require 'tests/data/Calculation/MathTrig/LOG10.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerLog10Array')]
public function testLog10Array(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=LOG10({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerLog10Array(): array
{
return [
'row vector' => [[[-0.90308998699194, 0.3701428470511, 1.09691001300806]], '{0.125, 2.345, 12.5}'],
'column vector' => [[[-0.90308998699194], [0.3701428470511], [1.09691001300806]], '{0.125; 2.345; 12.5}'],
'matrix' => [[[-0.90308998699194, 0.3701428470511], [0.0, 1.09691001300806]], '{0.125, 2.345; 1.0, 12.5}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SqrtTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SqrtTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class SqrtTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerSQRT')]
public function testSQRT(mixed $expectedResult, mixed $number = 'omitted'): void
{
$sheet = $this->getSheet();
$this->mightHaveException($expectedResult);
$this->setCell('A1', $number);
if ($number === 'omitted') {
$sheet->getCell('B1')->setValue('=SQRT()');
} else {
$sheet->getCell('B1')->setValue('=SQRT(A1)');
}
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
}
public static function providerSqrt(): array
{
return require 'tests/data/Calculation/MathTrig/SQRT.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerSqrtArray')]
public function testSqrtArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=SQRT({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerSqrtArray(): array
{
return [
'row vector' => [[[3, 3.5355339059327378, 4.898979485566356]], '{9, 12.5, 24}'],
'column vector' => [[[3], [3.5355339059327378], [4.898979485566356]], '{9; 12.5; 24}'],
'matrix' => [[[3, 3.5355339059327378], [4.898979485566356, 8]], '{9, 12.5; 24, 64}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinhTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SinhTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class SinhTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCosh')]
public function testSinh(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 2);
$sheet->getCell('A1')->setValue("=SINH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
}
public static function providerCosh(): array
{
return require 'tests/data/Calculation/MathTrig/SINH.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerSinhArray')]
public function testSinhArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=SINH({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerSinhArray(): array
{
return [
'row vector' => [[[1.17520119364380, 0.52109530549375, -1.17520119364380]], '{1, 0.5, -1}'],
'column vector' => [[[1.17520119364380], [0.52109530549375], [-1.17520119364380]], '{1; 0.5; -1}'],
'matrix' => [[[1.17520119364380, 0.52109530549375], [0.0, -1.17520119364380]], '{1, 0.5; 0, -1}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/LogTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/LogTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class LogTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerLOG')]
public function testLOG(mixed $expectedResult, mixed $number = 'omitted', mixed $base = 'omitted'): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
if ($number !== null) {
$sheet->getCell('A1')->setValue($number);
}
if ($base !== null) {
$sheet->getCell('A2')->setValue($base);
}
if ($number === 'omitted') {
$sheet->getCell('B1')->setValue('=LOG()');
} elseif ($base === 'omitted') {
$sheet->getCell('B1')->setValue('=LOG(A1)');
} else {
$sheet->getCell('B1')->setValue('=LOG(A1,A2)');
}
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerLOG(): array
{
return require 'tests/data/Calculation/MathTrig/LOG.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerLogArray')]
public function testLogArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=LOG({$argument1}, {$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerLogArray(): array
{
return [
'matrix' => [
[
[-0.90308998699194, 0.3701428470511, 0.0, 1.09691001300806],
[-2.07944154167984, 0.85228540189824, 0.0, 2.525728644308256],
],
'{0.125, 2.345, 1.0, 12.5}',
'{10; 2.718281828459045}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/Atan2Test.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/Atan2Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class Atan2Test extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerATAN2')]
public function testATAN2(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->getCell('A2')->setValue(5);
$sheet->getCell('A3')->setValue(6);
$sheet->getCell('A1')->setValue("=ATAN2($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
}
public static function providerATAN2(): array
{
return require 'tests/data/Calculation/MathTrig/ATAN2.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerAtan2Array')]
public function testAtan2Array(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=ATAN2({$argument1},{$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerAtan2Array(): array
{
return [
'first argument row vector' => [
[[1.81577498992176, 1.17600520709514]],
'{-0.75, 1.25}',
'3',
],
'first argument column vector' => [
[[1.17600520709514], [0.98279372324733]],
'{1.25; 2}',
'3',
],
'first argument matrix' => [
[[2.03444393579570, 1.48765509490646], [1.57079632679490, 1.24904577239825]],
'{-1.5, 0.25; 0, 1}',
'3',
],
'second argument row vector' => [
[[-0.24497866312686, 0.39479111969976]],
'3',
'{-0.75, 1.25}',
],
'second argument column vector' => [
[[0.39479111969976], [0.58800260354757]],
'3',
'{1.25; 2}',
],
'second argument matrix' => [
[[-0.46364760900081, 0.08314123188844], [0.0, 0.32175055439664]],
'3',
'{-1.5, 0.25; 0, 1}',
],
'A row and a column vector' => [
[
[-2.21429743558818, 2.81984209919315, 2.55359005004223, 1.92956699706547],
[-1.69515132134166, 2.03444393579570, 1.81577498992176, 1.63321513679085],
[-1.01219701145133, 0.38050637711237, 0.67474094222355, 1.26791145841993],
[-0.51914611424652, 0.14189705460416, 0.27829965900511, 0.85196632717327],
],
'{-1.5; -0.25; 1.25; 3.5}',
'{-2, 0.5, 1, 4}',
],
'Two row vectors' => [
[[-2.21429743558818, 2.03444393579570, 0.67474094222355, 0.85196632717327]],
'{-1.5, -0.25, 1.25, 3.5}',
'{-2, 0.5, 1, 4}',
],
'Two column vectors' => [
[[-2.21429743558818], [2.03444393579570], [0.67474094222355], [0.85196632717327]],
'{-1.5; -0.25; 1.25; 3.5}',
'{-2; 0.5; 1; 4}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RandBetweenTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/RandBetweenTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class RandBetweenTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerRANDBETWEEN')]
public function testRANDBETWEEN(int|string $expectedResult, null|bool|int|string $min = 'omitted', null|bool|int|string $max = 'omitted'): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$lower = (int) $min;
$upper = (int) $max;
if ($min !== null) {
$sheet->getCell('A1')->setValue($min);
}
if ($max !== null) {
$sheet->getCell('A2')->setValue($max);
}
if ($min === 'omitted') {
$sheet->getCell('B1')->setValue('=RANDBETWEEN()');
} elseif ($max === 'omitted') {
$sheet->getCell('B1')->setValue('=RANDBETWEEN(A1)');
} else {
$sheet->getCell('B1')->setValue('=RANDBETWEEN(A1,A2)');
}
$result = $sheet->getCell('B1')->getCalculatedValue();
if (is_numeric($expectedResult)) {
self::assertGreaterThanOrEqual($lower, $result);
self::assertLessThanOrEqual($upper, $result);
} else {
self::assertSame($expectedResult, $result);
}
}
public static function providerRANDBETWEEN(): array
{
return require 'tests/data/Calculation/MathTrig/RANDBETWEEN.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerRandBetweenArray')]
public function testRandBetweenArray(
int $expectedRows,
int $expectedColumns,
string $argument1,
string $argument2
): void {
$calculation = Calculation::getInstance();
$formula = "=RandBetween({$argument1}, {$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertIsArray($result);
self::assertCount($expectedRows, $result);
self::assertIsArray($result[0]);
self::assertCount($expectedColumns, $result[0]);
}
public static function providerRandBetweenArray(): array
{
return [
'row/column vectors' => [2, 2, '{1, 10}', '{10; 100}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanhTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/TanhTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class TanhTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerTanh')]
public function testTanh(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1);
$sheet->getCell('A1')->setValue("=TANH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
}
public static function providerTanh(): array
{
return require 'tests/data/Calculation/MathTrig/TANH.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerTanhArray')]
public function testTanhArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=TANH({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerTanhArray(): array
{
return [
'row vector' => [[[0.76159415595577, 0.46211715726001, -0.76159415595577]], '{1, 0.5, -1}'],
'column vector' => [[[0.76159415595577], [0.46211715726001], [-0.76159415595577]], '{1; 0.5; -1}'],
'matrix' => [[[0.76159415595577, 0.46211715726001], [0.0, -0.76159415595577]], '{1, 0.5; 0, -1}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumXMY2Test.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumXMY2Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\Attributes\DataProvider;
class SumXMY2Test extends AllSetupTeardown
{
/**
* @param mixed[] $matrixData1
* @param mixed[] $matrixData2
*/
#[DataProvider('providerSUMXMY2')]
public function testSUMXMY2(mixed $expectedResult, array $matrixData1, array $matrixData2): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$maxRow = 0;
$funcArg1 = '';
foreach (Functions::flattenArray($matrixData1) as $arg) {
++$maxRow;
$funcArg1 = "A1:A$maxRow";
$this->setCell("A$maxRow", $arg);
}
$maxRow = 0;
$funcArg2 = '';
foreach (Functions::flattenArray($matrixData2) as $arg) {
++$maxRow;
$funcArg2 = "C1:C$maxRow";
$this->setCell("C$maxRow", $arg);
}
$sheet->getCell('B1')->setValue("=SUMXMY2($funcArg1, $funcArg2)");
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerSUMXMY2(): array
{
return require 'tests/data/Calculation/MathTrig/SUMXMY2.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MdeTermTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MdeTermTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PHPUnit\Framework\Attributes\DataProvider;
class MdeTermTest extends AllSetupTeardown
{
/** @param array<mixed>|float|int|string $matrix */
#[DataProvider('providerMDETERM')]
public function testMDETERM2(float|int|string $expectedResult, array|int|float|string $matrix): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
if (is_array($matrix)) {
$sheet->fromArray($matrix, null, 'A1', true);
$maxCol = $sheet->getHighestColumn();
$maxRow = $sheet->getHighestRow();
$sheet->getCell('Z1')->setValue("=MDETERM(A1:$maxCol$maxRow)");
} else {
$sheet->getCell('Z1')->setValue("=MDETERM($matrix)");
}
$result = $sheet->getCell('Z1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerMDETERM(): array
{
return require 'tests/data/Calculation/MathTrig/MDETERM.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MRoundTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/MRoundTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class MRoundTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerMROUND')]
public function testMROUND(float|int|string $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=MROUND($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerMROUND(): array
{
return require 'tests/data/Calculation/MathTrig/MROUND.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerMRoundArray')]
public function testMRoundArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=MROUND({$argument1},{$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerMRoundArray(): array
{
return [
'first argument row vector' => [
[[0.15, 1.375, 931.675, 3.15]],
'{0.14527, 1.3725, 931.6829, 3.14159265}',
'0.025',
],
'first argument column vector' => [
[[0.15], [1.375], [931.675], [3.15]],
'{0.14527; 1.3725; 931.6829; 3.14159265}',
'0.025',
],
'first argument matrix' => [
[[0.15, 1.375], [931.675, 3.15]],
'{0.14527, 1.3725; 931.6829, 3.14159265}',
'0.025',
],
'second argument row vector' => [
[[123.125, 123.125, 123.1, 123.2, 125]],
'123.12345',
'{0.005, 0.025, 0.1, 0.2, 5}',
],
'second argument column vector' => [
[[123.125], [123.125], [123.1], [123.2], [125]],
'123.12345',
'{0.005; 0.025; 0.1; 0.2; 5}',
],
'second argument matrix' => [
[[123.125, 123.125], [123.2, 125.0]],
'123.12345',
'{0.005, 0.025; 0.2, 5}',
],
'A row and a column vector' => [
[
[0.145, 0.15, 0.2, 0.0],
[1.375, 1.375, 1.4, 0.0],
[931.685, 931.675, 931.6, 930.0],
[3.14, 3.15, 3.2, 5.0],
],
'{0.14527; 1.37250; 931.68290; 3.14159265}',
'{0.005, 0.025, 0.2, 5}',
],
'Two row vectors' => [
[[0.145, 1.375, 931.6, 5.0]],
'{0.14527, 1.3725, 931.6, 3.14159265}',
'{0.005, 0.025, 0.2, 5}',
],
'Two column vectors' => [
[[0.145], [1.375], [931.6], [5.0]],
'{0.14527; 1.37250; 931.6; 5}',
'{0.005; 0.025; 0.2; 5}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FactTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/FactTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class FactTest extends AllSetupTeardown
{
const FACT_PRECISION = 1E-12;
#[\PHPUnit\Framework\Attributes\DataProvider('providerFACT')]
public function testFACT(mixed $expectedResult, mixed $arg1): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
if ($arg1 !== null) {
$sheet->getCell('A1')->setValue($arg1);
}
if ($arg1 === 'omitted') {
$sheet->getCell('B1')->setValue('=FACT()');
} else {
$sheet->getCell('B1')->setValue('=FACT(A1)');
}
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public static function providerFACT(): array
{
return require 'tests/data/Calculation/MathTrig/FACT.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerFACTGnumeric')]
public function testFACTGnumeric(mixed $expectedResult, mixed $arg1): void
{
$this->mightHaveException($expectedResult);
self::setGnumeric();
$sheet = $this->getSheet();
if ($arg1 !== null) {
$sheet->getCell('A1')->setValue($arg1);
}
if ($arg1 === 'omitted') {
$sheet->getCell('B1')->setValue('=FACT()');
} else {
$sheet->getCell('B1')->setValue('=FACT(A1)');
}
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, self::FACT_PRECISION);
}
public static function providerFACTGnumeric(): array
{
return require 'tests/data/Calculation/MathTrig/FACTGNUMERIC.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerFactArray')]
public function testFactArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=FACT({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, self::FACT_PRECISION);
}
public static function providerFactArray(): array
{
return [
'row vector' => [[['#NUM!', 120, 362880]], '{-2, 5, 9}'],
'column vector' => [[['#NUM!'], [120], [362880]], '{-2; 5; 9}'],
'matrix' => [[['#NUM!', 120], [362880, 6]], '{-2, 5; 9, 3.5}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ModTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ModTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class ModTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerMOD')]
public function testMOD(mixed $expectedResult, mixed $dividend = 'omitted', mixed $divisor = 'omitted'): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
if ($dividend !== null) {
$sheet->getCell('A1')->setValue($dividend);
}
if ($divisor !== null) {
$sheet->getCell('A2')->setValue($divisor);
}
if ($dividend === 'omitted') {
$sheet->getCell('B1')->setValue('=MOD()');
} elseif ($divisor === 'omitted') {
$sheet->getCell('B1')->setValue('=MOD(A1)');
} else {
$sheet->getCell('B1')->setValue('=MOD(A1,A2)');
}
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerMOD(): array
{
return require 'tests/data/Calculation/MathTrig/MOD.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerModArray')]
public function testModArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=MOD({$argument1}, {$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerModArray(): array
{
return [
'matrix' => [[[4, 3, 2], [1, 0, 4], [3, 2, 1]], '{9, 8, 7; 6, 5, 4; 3, 2, 1}', '5'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CosTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CosTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class CosTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCos')]
public function testCos(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 2);
$sheet->getCell('A1')->setValue("=COS($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
}
public static function providerCos(): array
{
return require 'tests/data/Calculation/MathTrig/COS.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerCosArray')]
public function testCosArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=COS({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerCosArray(): array
{
return [
'row vector' => [[[0.54030230586814, 0.87758256189037, 0.54030230586814]], '{1, 0.5, -1}'],
'column vector' => [[[0.54030230586814], [0.87758256189037], [0.54030230586814]], '{1; 0.5; -1}'],
'matrix' => [[[0.54030230586814, 0.87758256189037], [1.0, 0.54030230586814]], '{1, 0.5; 0, -1}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ProductTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/ProductTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
class ProductTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerPRODUCT')]
public function testPRODUCT(mixed $expectedResult, mixed ...$args): void
{
$sheet = $this->getSheet();
$row = 0;
foreach ($args as $arg) {
++$row;
$sheet->getCell("A$row")->setValue($arg);
}
$sheet->getCell('B1')->setValue("=PRODUCT(A1:A$row)");
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerPRODUCT(): array
{
return require 'tests/data/Calculation/MathTrig/PRODUCT.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AtanTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class AtanTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerAtan')]
public function testAtan(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->getCell('A2')->setValue(5);
$sheet->getCell('A1')->setValue("=ATAN($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
}
public static function providerAtan(): array
{
return require 'tests/data/Calculation/MathTrig/ATAN.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerAtanArray')]
public function testAtanArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=ATAN({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerAtanArray(): array
{
return [
'row vector' => [[[0.78539816339745, 0.46364760900081, -0.78539816339745]], '{1, 0.5, -1}'],
'column vector' => [[[0.78539816339745], [0.46364760900081], [-0.78539816339745]], '{1; 0.5; -1}'],
'matrix' => [[[0.78539816339745, 0.46364760900081], [0.0, -0.78539816339745]], '{1, 0.5; 0, -1}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/SumTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\Attributes\DataProvider;
class SumTest extends AllSetupTeardown
{
#[DataProvider('providerSUM')]
public function testSUM(mixed $expectedResult, mixed ...$args): void
{
$this->setArrayAsValue();
$sheet = $this->getSheet();
$row = 0;
foreach ($args as $arg) {
++$row;
$sheet->getCell("A$row")->setValue($arg);
}
$sheet->getCell('B1')->setValue("=SUM(A1:A$row)");
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerSUM(): array
{
return require 'tests/data/Calculation/MathTrig/SUM.php';
}
#[DataProvider('providerSUMLiterals')]
public function testSUMLiterals(mixed $expectedResult, string $args): void
{
$sheet = $this->getSheet();
$sheet->getCell('B1')->setValue("=SUM($args)");
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerSUMLiterals(): array
{
return require 'tests/data/Calculation/MathTrig/SUMLITERALS.php';
}
#[DataProvider('providerSUMWITHINDEXMATCH')]
public function testSumWithIndexMatch(mixed $expectedResult, string $formula): void
{
$spreadsheet = $this->getSpreadsheet();
$this->setArrayAsValue();
$sheet1 = $spreadsheet->getActiveSheet();
$sheet1->setTitle('Formula');
$sheet1->fromArray(
[
['Number', 'Formula'],
[83, $formula],
]
);
$sheet2 = $spreadsheet->createSheet();
$sheet2->setTitle('Lookup');
$sheet2->fromArray(
[
['Lookup', 'Match'],
[83, 16],
]
);
self::assertSame($expectedResult, $sheet1->getCell('B2')->getCalculatedValue());
}
public static function providerSUMWITHINDEXMATCH(): array
{
return require 'tests/data/Calculation/MathTrig/SUMWITHINDEXMATCH.php';
}
public function testSumWithIndexMatchMoved(): void
{
$spreadsheet = new Spreadsheet();
$sheet1 = $spreadsheet->getActiveSheet();
$sheet1->setTitle('Formula');
$sheet1->getCell('G5')->setValue('Number');
$sheet1->getCell('H5')->setValue('Formula');
$sheet1->getCell('G6')->setValue(83);
$sheet1->getCell('H6')->setValue('=SUM(4 * INDEX(Lookup!D4:D6, MATCH(G6, Lookup!C4:C6, 0)))');
$sheet2 = $spreadsheet->createSheet();
$sheet2->setTitle('Lookup');
$sheet2->getCell('C3')->setValue('Lookup');
$sheet2->getCell('D3')->setValue('Match');
$sheet2->getCell('C4')->setValue(82);
$sheet2->getCell('D4')->setValue(15);
$sheet2->getCell('C5')->setValue(83);
$sheet2->getCell('D5')->setValue(16);
$sheet2->getCell('C6')->setValue(84);
$sheet2->getCell('D6')->setValue(17);
self::assertSame(64, $sheet1->getCell('H6')->getCalculatedValue());
$spreadsheet->disconnectWorksheets();
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CothTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/CothTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class CothTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCOTH')]
public function testCOTH(float|int|string $expectedResult, float|int|string $angle): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setCellValue('A2', 1.3);
$sheet->setCellValue('A3', 2.7);
$sheet->setCellValue('A4', -3.8);
$sheet->setCellValue('A5', -5.2);
$sheet->getCell('A1')->setValue("=COTH($angle)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-9);
}
public static function providerCOTH(): array
{
return require 'tests/data/Calculation/MathTrig/COTH.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerCothArray')]
public function testCothArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=COTH({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerCothArray(): array
{
return [
'row vector' => [[[1.31303528549933, 2.16395341373865, -1.31303528549933]], '{1, 0.5, -1}'],
'column vector' => [[[1.31303528549933], [2.16395341373865], [-1.31303528549933]], '{1; 0.5; -1}'],
'matrix' => [[[1.31303528549933, 2.16395341373865], ['#DIV/0!', -1.31303528549933]], '{1, 0.5; 0, -1}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinhTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AsinhTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class AsinhTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerAsinh')]
public function testAsinh(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->getCell('A2')->setValue(0.5);
$sheet->getCell('A1')->setValue("=ASINH($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
}
public static function providerAsinh(): array
{
return require 'tests/data/Calculation/MathTrig/ASINH.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerAsinhArray')]
public function testAsinhArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=ASINH({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerAsinhArray(): array
{
return [
'row vector' => [[[0.88137358701954, 0.48121182505960, -0.88137358701954]], '{1, 0.5, -1}'],
'column vector' => [[[0.88137358701954], [0.48121182505960], [-0.88137358701954]], '{1; 0.5; -1}'],
'matrix' => [[[0.88137358701954, 0.48121182505960], [0.0, -0.88137358701954]], '{1, 0.5; 0, -1}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcosTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/MathTrig/AcosTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class AcosTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerAcos')]
public function testAcos(mixed $expectedResult, string $formula): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->getCell('A2')->setValue(0.5);
$sheet->getCell('A1')->setValue("=ACOS($formula)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1E-6);
}
public static function providerAcos(): array
{
return require 'tests/data/Calculation/MathTrig/ACOS.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerAcosArray')]
public function testAcosArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=ACOS({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerAcosArray(): array
{
return [
'row vector' => [[[0.0, 1.04719755119660, 3.14159265358979]], '{1, 0.5, -1}'],
'column vector' => [[[0.0], [1.04719755119660], [3.14159265358979]], '{1; 0.5; -1}'],
'matrix' => [[[0.0, 1.04719755119660], [1.57079632679490, 3.14159265358979]], '{1, 0.5; 0, -1}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Web/UrlEncodeTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Web/UrlEncodeTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Web;
use PhpOffice\PhpSpreadsheet\Calculation\Web\Service;
use PHPUnit\Framework\TestCase;
class UrlEncodeTest extends TestCase
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerURLENCODE')]
public function testURLENCODE(string $expectedResult, mixed $text): void
{
$result = Service::urlEncode($text);
self::assertSame($expectedResult, $result);
}
public static function providerURLENCODE(): array
{
return require 'tests/data/Calculation/Web/URLENCODE.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.