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/Statistical/PermutationATest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/PermutationATest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class PermutationATest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerPERMUT')]
public function testPERMUT(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('PERMUTATIONA', $expectedResult, ...$args);
}
public static function providerPERMUT(): array
{
return require 'tests/data/Calculation/Statistical/PERMUTATIONA.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerPermutationAArray')]
public function testPermutationAArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=PERMUTATIONA({$argument1},{$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerPermutationAArray(): array
{
return [
'first argument row vector' => [
[[512, 125]],
'{8, 5}',
'3',
],
'first argument column vector' => [
[[512], [125]],
'{8; 5}',
'3',
],
'first argument matrix' => [
[[512, 125], [27, 343]],
'{8, 5; 3, 7}',
'3',
],
'second argument row vector' => [
[[2197, 4826809]],
'13',
'{3, 6}',
],
'second argument column vector' => [
[[2197], [4826809]],
'13',
'{3; 6}',
],
'second argument matrix' => [
[[2197, 4826809], [28561, 815730721]],
'13',
'{3, 6; 4, 8}',
],
'A row and a column vector' => [
[
[248832, 20736, 1728, 144],
[100000, 10000, 1000, 100],
[32768, 4096, 512, 64],
[7776, 1296, 216, 36],
],
'{12; 10; 8; 6}',
'{5, 4, 3, 2}',
],
'Two row vectors' => [
[[248832, 10000, 512, 36]],
'{12, 10, 8, 6}',
'{5, 4, 3, 2}',
],
'Two column vectors' => [
[[248832], [10000], [512], [36]],
'{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/Statistical/MedianTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/MedianTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class MedianTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerMEDIAN')]
public function testMEDIAN(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('MEDIAN', $expectedResult, ...$args);
}
public static function providerMEDIAN(): array
{
return require 'tests/data/Calculation/Statistical/MEDIAN.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/MaxATest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/MaxATest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class MaxATest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerMAXA')]
public function testMAXA(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('MAXA', $expectedResult, ...$args);
}
public static function providerMAXA(): array
{
return require 'tests/data/Calculation/Statistical/MAXA.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/KurtTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/KurtTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class KurtTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerKURT')]
public function testKURT(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('KURT', $expectedResult, ...$args);
}
public static function providerKURT(): array
{
return require 'tests/data/Calculation/Statistical/KURT.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/ChiTestTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/ChiTestTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
// TODO Convert to Spreadsheet context.
class ChiTestTest extends TestCase
{
/**
* @param float[] $actual
* @param float[] $expected
*/
#[DataProvider('providerCHITEST')]
public function testCHITEST(mixed $expectedResult, array $actual, array $expected): void
{
$result = Statistical\Distributions\ChiSquared::test($actual, $expected);
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerCHITEST(): array
{
return require 'tests/data/Calculation/Statistical/CHITEST.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/QuartileTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/QuartileTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class QuartileTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerQUARTILE')]
public function testQUARTILE(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('QUARTILE', $expectedResult, ...$args);
}
public static function providerQUARTILE(): array
{
return require 'tests/data/Calculation/Statistical/QUARTILE.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/SmallTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/SmallTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class SmallTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerSMALL')]
public function testSMALL(mixed $expectedResult, mixed $values, mixed $position): void
{
$this->runTestCaseReference('SMALL', $expectedResult, $values, $position);
}
public static function providerSMALL(): array
{
return require 'tests/data/Calculation/Statistical/SMALL.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/LinEstTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/LinEstTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
// TODO run test in spreadsheet context
class LinEstTest extends TestCase
{
/**
* @param mixed[] $yValues
* @param mixed[] $xValues
*/
#[DataProvider('providerLINEST')]
public function testLINEST(array $expectedResult, array $yValues, array $xValues, mixed $const, mixed $stats): void
{
$result = Statistical\Trends::LINEST($yValues, $xValues, $const, $stats);
self::assertIsArray($result);
$elements = count($expectedResult);
for ($element = 0; $element < $elements; ++$element) {
self::assertEqualsWithDelta($expectedResult[$element], $result[$element], 1E-12);
}
}
public static function providerLINEST(): array
{
return require 'tests/data/Calculation/Statistical/LINEST.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GammaDistTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GammaDistTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class GammaDistTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerGAMMADIST')]
public function testGAMMADIST(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('GAMMA.DIST', $expectedResult, ...$args);
}
public static function providerGAMMADIST(): array
{
return require 'tests/data/Calculation/Statistical/GAMMADIST.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerGammaDistArray')]
public function testGammaDistArray(array $expectedResult, string $values, string $alpha, string $beta): void
{
$calculation = Calculation::getInstance();
$formula = "=GAMMA.DIST({$values}, {$alpha}, {$beta}, false)";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerGammaDistArray(): array
{
return [
'row/column vectors' => [
[
[0.0012393760883331792, 0.007436256529999079, 0.0669263087699917],
[0.012446767091965986, 0.03734030127589798, 0.04200783893538521],
[0.018143590657882503, 0.043544617578918025, 0.02508169972545678],
],
'12',
'{1, 2, 5}',
'{2; 4; 5}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/NormSInvTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/NormSInvTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class NormSInvTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerNORMSINV')]
public function testNORMSINV(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('NORMSINV', $expectedResult, ...$args);
}
public static function providerNORMSINV(): array
{
return require 'tests/data/Calculation/Statistical/NORMSINV.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerNormSInvArray')]
public function testNormSInvArray(array $expectedResult, string $probabilities): void
{
$calculation = Calculation::getInstance();
$formula = "=NORMSINV({$probabilities})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerNormSInvArray(): array
{
return [
'row/column vectors' => [
[
['#NUM!', -1.959963986120195],
[-0.3853204662702544, 0.6744897502234225],
],
'{-0.75, 0.025; 0.35, 0.75}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/CountIfTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/CountIfTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException;
use PHPUnit\Framework\Attributes\DataProvider;
class CountIfTest extends AllSetupTeardown
{
#[DataProvider('providerCOUNTIF')]
public function testCOUNTIF(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseNoBracket('COUNTIF', $expectedResult, ...$args);
}
public function testMultipleRows(): void
{
$sheet = $this->getSheet();
$sheet->fromArray([
['apples', 'oranges', 'peaches', 'apples'],
['bananas', 'mangoes', 'grapes', 'cherries'],
]);
$sheet->getCell('Z99')->setValue('=COUNTIF(A1:D2,"*p*e*")');
self::assertSame(4, $sheet->getCell('Z99')->getCalculatedValue());
}
public static function providerCOUNTIF(): array
{
return require 'tests/data/Calculation/Statistical/COUNTIF.php';
}
public function testOutliers(): void
{
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=COUNTIF(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('=COUNTIF(#REF!,1)');
self::assertSame('#REF!', $sheet->getCell('A4')->getCalculatedValue());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/AverageIf2Test.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/AverageIf2Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;
class AverageIf2Test extends TestCase
{
public function testAVERAGEIF(): void
{
$table = [
['n', 1],
['', 2],
['y', 3],
['', 4],
['n', 5],
['n', 6],
['n', 7],
['', 8],
[null, 9],
];
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->fromArray($table, null, 'A1', true);
$sheet->getCell('C1')->setValue('=AVERAGEIF(A:A,"",B:B)');
$sheet->getCell('C2')->setValue('=AVERAGEIF(A:A,,B:B)');
$sheet->getCell('C3')->setValue('=AVERAGEIF(A:A,"n",B:B)');
$sheet->getCell('C4')->setValue('=AVERAGEIF(A:A,"y",B:B)');
$sheet->getCell('C5')->setValue('=AVERAGEIF(A:A,"x",B:B)');
self::assertEqualsWithDelta(5.75, $sheet->getCell('C1')->getCalculatedValue(), 1E-12);
self::assertEquals('#DIV/0!', $sheet->getCell('C2')->getCalculatedValue());
self::assertEqualsWithDelta(4.75, $sheet->getCell('C3')->getCalculatedValue(), 1E-12);
self::assertEqualsWithDelta(3, $sheet->getCell('C4')->getCalculatedValue(), 1E-12);
self::assertEquals('#DIV/0!', $sheet->getCell('C5')->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/Statistical/BetaInvTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/BetaInvTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class BetaInvTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerBETAINV')]
public function testBETAINV(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('BETAINV', $expectedResult, ...$args);
}
public static function providerBETAINV(): array
{
return require 'tests/data/Calculation/Statistical/BETAINV.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerBetaInvArray')]
public function testBetaInvArray(array $expectedResult, string $argument1, string $argument2, string $argument3): void
{
$calculation = Calculation::getInstance();
$formula = "=BETAINV({$argument1}, {$argument2}, {$argument3})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerBetaInvArray(): array
{
return [
'row/column vectors' => [
[[0.24709953547, 0.346789605377], [0.215382947588, 0.307844847105]],
'0.25',
'{5, 7.5}',
'{10; 12}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/MinATest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/MinATest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class MinATest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerMINA')]
public function testMINA(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('MINA', $expectedResult, ...$args);
}
public static function providerMINA(): array
{
return require 'tests/data/Calculation/Statistical/MINA.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/HarMeanTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/HarMeanTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class HarMeanTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerHARMEAN')]
public function testHARMEAN(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('HARMEAN', $expectedResult, ...$args);
}
public static function providerHARMEAN(): array
{
return require 'tests/data/Calculation/Statistical/HARMEAN.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/FisherInvTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/FisherInvTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class FisherInvTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerFISHERINV')]
public function testFISHERINV(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('FISHERINV', $expectedResult, ...$args);
}
public static function providerFISHERINV(): array
{
return require 'tests/data/Calculation/Statistical/FISHERINV.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerFisherArray')]
public function testFisherArray(array $expectedResult, string $values): void
{
$calculation = Calculation::getInstance();
$formula = "=FISHERINV({$values})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerFisherArray(): array
{
return [
'row vector' => [
[[-0.7162978701990245, 0.197375320224904, 0.6351489523872873, 0.9051482536448664]],
'{-0.9, 0.2, 0.75, 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/Statistical/BinomDistRangeTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/BinomDistRangeTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class BinomDistRangeTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerBINOMDISTRANGE')]
public function testBINOMDISTRANGE(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('BINOM.DIST.RANGE', $expectedResult, ...$args);
}
public static function providerBINOMDISTRANGE(): array
{
return require 'tests/data/Calculation/Statistical/BINOMDISTRANGE.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerBinomDistRangeArray')]
public function testBinomDistRangeArray(
array $expectedResult,
string $trials,
string $probabilities,
string $successes
): void {
$calculation = Calculation::getInstance();
$formula = "=BINOM.DIST.RANGE({$trials}, {$probabilities}, {$successes})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerBinomDistRangeArray(): array
{
return [
'row/column vectors' => [
[[0.17303466796875, 0.01153564453125], [0.258103609085083, 0.1032414436340332]],
'{7; 12}',
'0.25',
'{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/Statistical/MinTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/MinTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class MinTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerMIN')]
public function testMIN(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('MIN', $expectedResult, ...$args);
}
public static function providerMIN(): array
{
return require 'tests/data/Calculation/Statistical/MIN.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/FDistTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/FDistTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class FDistTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerFDIST')]
public function testFDIST(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('F.DIST', $expectedResult, ...$args);
}
public static function providerFDIST(): array
{
return require 'tests/data/Calculation/Statistical/FDIST.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerFDistArray')]
public function testFDistArray(array $expectedResult, string $values, string $u, string $v): void
{
$calculation = Calculation::getInstance();
$formula = "=F.DIST({$values}, {$u}, {$v}, false)";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerFDistArray(): array
{
return [
'row/column vectors' => [
[
[0.005510833927217306, 0.005917159763313607, 0.006191501336451844],
[0.0033829117335328167, 0.00291545189504373, 0.0024239018640028246],
[0.0027880880388152654, 0.002128148956848886, 0.0015205263468794615],
],
'12',
'{1, 2, 5}',
'{2; 4; 5}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/TDotInvTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/TDotInvTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PHPUnit\Framework\Attributes\DataProvider;
class TDotInvTest extends AllSetupTeardown
{
/**
* @var false|string
*/
private $currentLocale;
protected function setUp(): void
{
parent::setUp();
$this->currentLocale = setlocale(LC_ALL, '0');
}
protected function tearDown(): void
{
parent::tearDown();
if (is_string($this->currentLocale)) {
setlocale(LC_ALL, $this->currentLocale);
}
}
#[DataProvider('providerTdotINV')]
public function testTdotINV(mixed $expectedResult, mixed $probability, mixed $degrees): void
{
$this->runTestCaseReference('T.INV', $expectedResult, $probability, $degrees);
}
#[DataProvider('providerTdotINV')]
public function testTdotINVLocale(mixed $expectedResult, mixed $probability, mixed $degrees): void
{
if (!setlocale(LC_ALL, 'fr_FR.UTF-8', 'fra_fra.utf8')) {
self::markTestSkipped('Unable to set locale for testing.');
}
$this->runTestCaseReference('T.INV', $expectedResult, $probability, $degrees);
}
public static function providerTdotINV(): array
{
return require 'tests/data/Calculation/Statistical/TdotINV.php';
}
#[DataProvider('providerTInvArray')]
public function testTInvArray(array $expectedResult, string $values, string $degrees): void
{
$calculation = Calculation::getInstance();
$formula = "=T.INV({$values}, {$degrees})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-6);
}
public static function providerTInvArray(): array
{
return [
'row vector' => [
[
[0.509525, 0.424202, 0.399469],
],
'0.65',
'{1.5, 3.5, 8}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/NormSDist2Test.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/NormSDist2Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class NormSDist2Test extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerNORMSDIST2')]
public function testNORMSDIST2(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('NORM.S.DIST', $expectedResult, ...$args);
}
public static function providerNORMSDIST2(): array
{
return require 'tests/data/Calculation/Statistical/NORMSDIST2.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerNormSDist2Array')]
public function testNormSDist2Array(array $expectedResult, string $values): void
{
$calculation = Calculation::getInstance();
$formula = "=NORM.S.DIST({$values}, true)";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerNormSDist2Array(): array
{
return [
'row/column vectors' => [
[
[0.3085375387259869, 0.7733726476231317],
[0.99865010196837, 1.0],
],
'{-0.5, 0.75; 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/Statistical/MinIfsTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/MinIfsTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class MinIfsTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerMINIFS')]
public function testMINIFS(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseNoBracket('MINIFS', $expectedResult, ...$args);
}
public static function providerMINIFS(): array
{
return require 'tests/data/Calculation/Statistical/MINIFS.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/TdotDistFalseTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/TdotDistFalseTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PHPUnit\Framework\Attributes\DataProvider;
class TdotDistFalseTest extends AllSetupTeardown
{
#[DataProvider('providerTdotDistFalse')]
public function testTdotDistFalse(mixed $expectedResult, mixed $value, mixed $degrees): void
{
$this->runTestCaseReference('T.DIST', $expectedResult, $value, $degrees, false);
}
public static function providerTdotDistFalse(): array
{
return require 'tests/data/Calculation/Statistical/tDotDistFalse.php';
}
#[DataProvider('providerTdotDistArray')]
public function testTdotDistArray(array $expectedResult, string $values, string $degrees): void
{
$calculation = Calculation::getInstance();
$formula = "=T.DIST({$values}, {$degrees}, false)";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-6);
}
public static function providerTdotDistArray(): array
{
return [
'row/column vectors' => [
[
[0.063662, 0.0675096606638932, 0.06236808463468194],
],
'2',
'{1.5, 3.5, 8}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/FisherTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/FisherTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class FisherTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerFISHER')]
public function testFISHER(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('FISHER', $expectedResult, ...$args);
}
public static function providerFISHER(): array
{
return require 'tests/data/Calculation/Statistical/FISHER.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerFisherArray')]
public function testFisherArray(array $expectedResult, string $values): void
{
$calculation = Calculation::getInstance();
$formula = "=FISHER({$values})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerFisherArray(): array
{
return [
'row vector' => [
[[-1.4722194895832204, 0.2027325540540821, 0.9729550745276566]],
'{-0.9, 0.2, 0.75}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GammaTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GammaTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class GammaTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerGAMMA')]
public function testGAMMA(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('GAMMA', $expectedResult, ...$args);
}
public static function providerGAMMA(): array
{
return require 'tests/data/Calculation/Statistical/GAMMA.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerGammaArray')]
public function testGammaArray(array $expectedResult, string $values): void
{
$calculation = Calculation::getInstance();
$formula = "=GAMMA({$values})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerGammaArray(): array
{
return [
'matrix' => [
[[2.363271800901467, 4.590843711999102], [1.2254167024651963, 17.837861981813575]],
'{-1.5, 0.2; 0.75, 4.8}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/ForecastTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/ForecastTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PHPUnit\Framework\TestCase;
// TODO Spreadsheet context.
// Note that null in reference is treated differently than null in array.
class ForecastTest extends TestCase
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerFORECAST')]
public function testFORECAST(mixed $expectedResult, mixed ...$args): void
{
$result = Statistical\Trends::FORECAST(...$args);
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerFORECAST(): array
{
return require 'tests/data/Calculation/Statistical/FORECAST.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerForecastArray')]
public function testForecastArray(array $expectedResult, string $testValues, string $yValues, string $xValues): void
{
$calculation = Calculation::getInstance();
$formula = "=FORECAST({$testValues}, {$yValues}, {$xValues})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerForecastArray(): array
{
return [
'row vector' => [[[-11.047619047619047, 22.95238095238095, 42.38095238095237]], '{-2, 5, 9}', '{3, 7, 15, 20, 22, 27}', '{1, 2, 3, 4, 5, 6}'],
'column vector' => [[[-11.047619047619047], [22.95238095238095], [42.38095238095237]], '{-2; 5; 9}', '{3, 7, 15, 20, 22, 27}', '{1, 2, 3, 4, 5, 6}'],
'matrix' => [[[-11.047619047619047, 22.95238095238095], [42.38095238095237, 15.66666666666666]], '{-2, 5; 9, 3.5}', '{3, 7, 15, 20, 22, 27}', '{1, 2, 3, 4, 5, 6}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/CorrelTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/CorrelTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Statistical;
use PHPUnit\Framework\TestCase;
class CorrelTest extends TestCase
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCORREL')]
public function testCORREL(mixed $expectedResult, mixed $xargs, mixed $yargs): void
{
$result = Statistical\Trends::CORREL($xargs, $yargs);
self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
}
public static function providerCORREL(): array
{
return require 'tests/data/Calculation/Statistical/CORREL.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/StDevPTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/StDevPTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class StDevPTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerSTDEVP')]
public function testSTDEVP(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('STDEVP', $expectedResult, ...$args);
}
public static function providerSTDEVP(): array
{
return require 'tests/data/Calculation/Statistical/STDEVP.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerOdsSTDEVP')]
public function testOdsSTDEVP(mixed $expectedResult, mixed ...$args): void
{
$this->setOpenOffice();
$this->runTestCaseReference('STDEVP', $expectedResult, ...$args);
}
public static function providerOdsSTDEVP(): array
{
return require 'tests/data/Calculation/Statistical/STDEVP_ODS.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/BetaDistTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/BetaDistTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class BetaDistTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerBETADIST')]
public function testBETADIST(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('BETADIST', $expectedResult, ...$args);
}
public static function providerBETADIST(): array
{
return require 'tests/data/Calculation/Statistical/BETADIST.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerBetaDistArray')]
public function testBetaDistArray(array $expectedResult, string $argument1, string $argument2, string $argument3): void
{
$calculation = Calculation::getInstance();
$formula = "=BETADIST({$argument1}, {$argument2}, {$argument3})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerBetaDistArray(): array
{
return [
'row/column vectors' => [
[[0.25846539810299873, 0.05696312425682317], [0.3698138247709718, 0.10449584381010533]],
'0.25',
'{5, 7.5}',
'{10; 12}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/SteyxTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/SteyxTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PHPUnit\Framework\Attributes\DataProvider;
class SteyxTest extends AllSetupTeardown
{
/**
* @param mixed[] $xargs
* @param mixed[] $yargs
*/
#[DataProvider('providerSTEYX')]
public function testSTEYX(mixed $expectedResult, array $xargs, array $yargs): void
{
//$result = Statistical\Trends::STEYX($xargs, $yargs);
//self::assertEqualsWithDelta($expectedResult, $result, 1E-12);
$this->runTestCaseReference('STEYX', $expectedResult, $xargs, $yargs);
}
public static function providerSTEYX(): array
{
return require 'tests/data/Calculation/Statistical/STEYX.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/RankTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/RankTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class RankTest extends AllSetupTeardown
{
/**
* @param mixed[] $valueSet
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerRANK')]
public function testRANK(mixed $expectedResult, mixed $value, array $valueSet, mixed $order = null): void
{
if ($order === null) {
$this->runTestCaseReference('RANK', $expectedResult, $value, $valueSet);
} else {
$this->runTestCaseReference('RANK', $expectedResult, $value, $valueSet, $order);
}
}
public static function providerRANK(): array
{
return require 'tests/data/Calculation/Statistical/RANK.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GeoMeanTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GeoMeanTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class GeoMeanTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerGEOMEAN')]
public function testGEOMEAN(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('GEOMEAN', $expectedResult, ...$args);
}
public static function providerGEOMEAN(): array
{
return require 'tests/data/Calculation/Statistical/GEOMEAN.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/AverageTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/AverageTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class AverageTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerAVERAGE')]
public function testAVERAGE(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('AVERAGE', $expectedResult, ...$args);
}
public static function providerAVERAGE(): array
{
return require 'tests/data/Calculation/Statistical/AVERAGE.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/IfsTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Logical/IfsTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PHPUnit\Framework\Attributes\DataProvider;
class IfsTest extends AllSetupTeardown
{
#[DataProvider('providerIFS')]
public function testIFS(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('IFS', $expectedResult, ...$args);
}
public static function providerIFS(): array
{
return require 'tests/data/Calculation/Logical/IFS.php';
}
#[DataProvider('providerIfsArray')]
public function testIfsArray(array $expectedResult, string $bool1, string $argument1, string $bool2, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=IFS($bool1, {" . "$argument1}, $bool2, {" . "$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
public static function providerIfsArray(): array
{
return [
'array return first item' => [
[[1, 2, 3]],
'true',
'1, 2, 3',
'true',
'4, 5, 6',
],
'array return second item' => [
[[4, 5, 6]],
'false',
'1, 2, 3',
'true',
'4, 5, 6',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/AllSetupTeardown.php | tests/PhpSpreadsheetTests/Calculation/Functions/Logical/AllSetupTeardown.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
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;
private ?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 runTestCase(string $functionName, mixed $expectedResult, mixed ...$args): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$formula = "=$functionName(";
$comma = '';
$row = 0;
foreach ($args as $arg) {
++$row;
$cellId = "A$row";
$formula .= "$comma$cellId";
$comma = ',';
$this->setCell($cellId, $arg);
}
$formula .= ')';
$this->setCell('B1', $formula);
self::assertSame($expectedResult, $sheet->getCell('B1')->getCalculatedValue());
}
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/Logical/FalseTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Logical/FalseTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
class FalseTest extends AllSetupTeardown
{
public function testFALSE(): void
{
$this->runTestCase('FALSE', false);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/IfTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Logical/IfTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
class IfTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerIF')]
public function testIF(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('IF', $expectedResult, ...$args);
}
public static function providerIF(): array
{
return require 'tests/data/Calculation/Logical/IF.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/NotTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Logical/NotTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PHPUnit\Framework\Attributes\DataProvider;
class NotTest extends AllSetupTeardown
{
#[DataProvider('providerNOT')]
public function testNOT(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('NOT', $expectedResult, ...$args);
}
public static function providerNOT(): array
{
return require 'tests/data/Calculation/Logical/NOT.php';
}
#[DataProvider('providerNotArray')]
public function testNotArray(array $expectedResult, string $argument1): void
{
$calculation = Calculation::getInstance();
$formula = "=NOT({$argument1})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
public static function providerNotArray(): array
{
return [
'vector' => [
[[false, true, true, false]],
'{TRUE, FALSE, 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/Logical/OrTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Logical/OrTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
class OrTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerOR')]
public function testOR(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('OR', $expectedResult, ...$args);
}
public static function providerOR(): array
{
return require 'tests/data/Calculation/Logical/OR.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerORLiteral')]
public function testORLiteral(bool|string $expectedResult, float|int|string $formula): void
{
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue("=OR($formula)");
self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
}
public static function providerORLiteral(): array
{
return require 'tests/data/Calculation/Logical/ORLiteral.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/XorTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Logical/XorTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
class XorTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerXOR')]
public function testXOR(mixed $expectedResult, mixed ...$args): void
{
$this->setArrayAsValue();
$this->runTestCase('XOR', $expectedResult, ...$args);
}
public static function providerXOR(): array
{
return require 'tests/data/Calculation/Logical/XOR.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerXORLiteral')]
public function testXORLiteral(mixed $expectedResult, float|string $formula): void
{
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue("=XOR($formula)");
self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
}
public static function providerXORLiteral(): array
{
return require 'tests/data/Calculation/Logical/XORLiteral.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/IfNaTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Logical/IfNaTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PHPUnit\Framework\Attributes\DataProvider;
class IfNaTest extends AllSetupTeardown
{
#[DataProvider('providerIFNA')]
public function testIFNA(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('IFNA', $expectedResult, ...$args);
}
public static function providerIFNA(): array
{
return require 'tests/data/Calculation/Logical/IFNA.php';
}
#[DataProvider('providerIfNaArray')]
public function testIfNaArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=IFNA({$argument1}, {$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
public static function providerIfNaArray(): array
{
return [
'vector' => [
[[2.5, '#DIV/0!', 6]],
'{5/2, 5/0, "#N/A"}',
'MAX(ABS({-2,4,-6}))',
],
'return value' => [
[[2.5, '#DIV/0!', [[2, 3, 4]]]],
'{5/2, 5/0, "#N/A"}',
'{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/Logical/TrueTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Logical/TrueTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
class TrueTest extends AllSetupTeardown
{
public function testTRUE(): void
{
$this->runTestCase('TRUE', true);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/SwitchTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Logical/SwitchTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PHPUnit\Framework\Attributes\DataProvider;
class SwitchTest extends AllSetupTeardown
{
#[DataProvider('providerSwitch')]
public function testSWITCH(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('SWITCH', $expectedResult, ...$args);
}
public static function providerSwitch(): array
{
return require 'tests/data/Calculation/Logical/SWITCH.php';
}
#[DataProvider('providerSwitchArray')]
public function testIfsArray(array $expectedResult, int $expression, int $value1, string $result1, int $value2, string $result2, string $default): void
{
$calculation = Calculation::getInstance();
$formula = "=SWITCH($expression, $value1, {" . "$result1}, $value2, {" . "$result2}, {" . "$default})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
public static function providerSwitchArray(): array
{
return [
'Array return' => [
[[4, 5, 6]],
2,
1,
'1, 2, 3',
2,
'4, 5, 6',
'7, 8, 9',
],
'Array return default' => [
[[7, 8, 9]],
3,
1,
'1, 2, 3',
2,
'4, 5, 6',
'7, 8, 9',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/AndTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Logical/AndTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PHPUnit\Framework\Attributes\DataProvider;
class AndTest extends AllSetupTeardown
{
#[DataProvider('providerAND')]
public function testAND(mixed $expectedResult, mixed ...$args): void
{
$this->setArrayAsValue();
$this->runTestCase('AND', $expectedResult, ...$args);
}
public static function providerAND(): array
{
return require 'tests/data/Calculation/Logical/AND.php';
}
#[DataProvider('providerANDLiteral')]
public function testANDLiteral(bool|string $expectedResult, float|int|string $formula): void
{
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue("=AND($formula)");
self::assertSame($expectedResult, $sheet->getCell('A1')->getCalculatedValue());
}
public static function providerANDLiteral(): array
{
return require 'tests/data/Calculation/Logical/ANDLiteral.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/IfErrorTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Logical/IfErrorTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PHPUnit\Framework\Attributes\DataProvider;
class IfErrorTest extends AllSetupTeardown
{
#[DataProvider('providerIFERROR')]
public function testIFERROR(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('IFERROR', $expectedResult, ...$args);
}
public static function providerIFERROR(): array
{
return require 'tests/data/Calculation/Logical/IFERROR.php';
}
#[DataProvider('providerIfErrorArray')]
public function testIfErrorArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=IFERROR({$argument1}, {$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
public static function providerIfErrorArray(): array
{
return [
'vector' => [
[[2.5, 6]],
'{5/2, 5/0}',
'MAX(ABS({-2,4,-6}))',
],
'return value' => [
[[2.5, [[2, 3, 4]]]],
'{5/2, 5/0}',
'{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/Financial/PvTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/PvTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PHPUnit\Framework\Attributes\DataProvider;
class PvTest extends AllSetupTeardown
{
/** @param mixed[] $args */
#[DataProvider('providerPV')]
public function testPV(mixed $expectedResult, array $args): void
{
$this->runTestCase('PV', $expectedResult, $args);
}
public static function providerPV(): array
{
return require 'tests/data/Calculation/Financial/PV.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/CumIpmtTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/CumIpmtTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class CumIpmtTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCUMIPMT')]
public function testCUMIPMT(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('CUMIPMT', $expectedResult, $args);
}
public static function providerCUMIPMT(): array
{
return require 'tests/data/Calculation/Financial/CUMIPMT.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/DollarFrTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/DollarFrTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class DollarFrTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerDOLLARFR')]
public function testDOLLARFR(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('DOLLARFR', $expectedResult, $args);
}
public static function providerDOLLARFR(): array
{
return require 'tests/data/Calculation/Financial/DOLLARFR.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/DollarDeTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/DollarDeTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PHPUnit\Framework\Attributes\DataProvider;
class DollarDeTest extends AllSetupTeardown
{
#[DataProvider('providerDOLLARDE')]
public function testDOLLARDE(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('DOLLARDE', $expectedResult, $args);
}
public static function providerDOLLARDE(): array
{
return require 'tests/data/Calculation/Financial/DOLLARDE.php';
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerDollarDeArray')]
public function testDollarDeArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=DollarDe({$argument1},{$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
}
public static function providerDollarDeArray(): array
{
return [
'first argument row vector' => [
[[1.125, 2.0625, -12.625, 3.5]],
'{1.02, 2.01, -12.1, 1.4}',
'16',
],
'first argument column vector' => [
[[1.0625], [2.03125], [-12.3125], [2.25]],
'{1.02; 2.01; -12.1; 1.4}',
'32',
],
'first argument matrix' => [
[[1.05, 2.25], [-12.5, 2.0]],
'{1.02, 2.1; -12.2, 1.4}',
'4',
],
'second argument row vector' => [
[[4.25, 3.625, 6.125, 4.5625]],
'3.5',
'{4, 8, 16, 32}',
],
'second argument column vector' => [
[[5.5], [4.25], [3.625], [6.125]],
'3.5',
'{2; 4; 8; 16}',
],
'second argument matrix' => [
[[-4.875, -3.9375], [-9.25, -7.6875]],
'-3.75',
'{4, 8; 12, 16}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/TBillEqTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/TBillEqTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class TBillEqTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerTBILLEQ')]
public function testTBILLEQ(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('TBILLEQ', $expectedResult, $args);
}
public static function providerTBILLEQ(): array
{
return require 'tests/data/Calculation/Financial/TBILLEQ.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/IrrTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/IrrTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
class IrrTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerIRR')]
public function testIRR(mixed $expectedResult, mixed $values = null, mixed $guess = null): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$formula = '=IRR(';
if ($values !== null) {
if (is_array($values)) {
$row = 0;
foreach ($values as $value) {
if (is_array($value)) {
foreach ($value as $arrayValue) {
++$row;
$sheet->getCell("A$row")->setValue($arrayValue);
}
} else {
++$row;
$sheet->getCell("A$row")->setValue($value);
}
}
$formula .= "A1:A$row";
} else {
$sheet->getCell('A1')->setValue($values);
$formula .= 'A1';
}
}
if ($guess !== null) {
$formula .= ',' . StringHelper::convertToString($guess);
}
$formula .= ')';
$sheet->getCell('D1')->setValue($formula);
$result = $sheet->getCell('D1')->getCalculatedValue();
$this->adjustResult($result, $expectedResult);
self::assertEqualsWithDelta($expectedResult, $result, 0.1E-8);
}
public static function providerIRR(): array
{
return require 'tests/data/Calculation/Financial/IRR.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/AllSetupTeardown.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/AllSetupTeardown.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
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;
private ?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;
}
/**
* Adjust result if it is close enough to expected by ratio
* rather than offset.
*/
protected function adjustResult(mixed &$result, mixed $expectedResult): void
{
if (is_numeric($result) && is_numeric($expectedResult)) {
if ($expectedResult != 0) {
$frac = $result / $expectedResult;
if ($frac > 0.999999 && $frac < 1.000001) {
$result = $expectedResult;
}
}
}
}
/** @param mixed[] $args */
public function runTestCase(string $functionName, mixed $expectedResult, array $args): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$formula = "=$functionName(";
$row = 0;
$col = 'A';
$comma = '';
foreach ($args as $arg) {
++$row;
$cell = "$col$row";
$this->setCell($cell, $arg);
$formula .= "$comma$cell";
$comma = ',';
}
$formula .= ')';
$sheet->getCell('B1')->setValue($formula);
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-7);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/CoupPcdTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/CoupPcdTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class CoupPcdTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCOUPPCD')]
public function testCOUPPCD(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('COUPPCD', $expectedResult, $args);
}
public static function providerCOUPPCD(): array
{
return require 'tests/data/Calculation/Financial/COUPPCD.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/PriceMatTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/PriceMatTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class PriceMatTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerPRICEMAT')]
public function testPRICEMAT(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('PRICEMAT', $expectedResult, $args);
}
public static function providerPRICEMAT(): array
{
return require 'tests/data/Calculation/Financial/PRICEMAT.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/YieldDiscTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/YieldDiscTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class YieldDiscTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerYIELDDISC')]
public function testYIELDDISC(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('YIELDDISC', $expectedResult, $args);
}
public static function providerYIELDDISC(): array
{
return require 'tests/data/Calculation/Financial/YIELDDISC.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/FvScheduleTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/FvScheduleTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PHPUnit\Framework\Attributes\DataProvider;
class FvScheduleTest extends AllSetupTeardown
{
/** @param null|mixed[] $schedule */
#[DataProvider('providerFVSCHEDULE')]
public function testFVSCHEDULE(mixed $expectedResult, mixed $principal = null, ?array $schedule = null): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$formula = '=FVSCHEDULE(';
if ($principal !== null) {
$this->setCell('A1', $principal);
$formula .= 'A1';
if (!empty($schedule)) {
$row = 0;
foreach ($schedule as $value) {
++$row;
$this->setCell("B$row", $value);
}
$formula .= ",B1:B$row";
}
}
$formula .= ')';
$sheet->getCell('D1')->setValue($formula);
$result = $sheet->getCell('D1')->getCalculatedValue();
$this->adjustResult($result, $expectedResult);
self::assertEqualsWithDelta($expectedResult, $result, 1.0E-8);
}
public static function providerFVSCHEDULE(): array
{
return require 'tests/data/Calculation/Financial/FVSCHEDULE.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/TBillPriceTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/TBillPriceTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class TBillPriceTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerTBILLPRICE')]
public function testTBILLPRICE(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('TBILLPRICE', $expectedResult, $args);
}
public static function providerTBILLPRICE(): array
{
return require 'tests/data/Calculation/Financial/TBILLPRICE.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/AmorLincTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/AmorLincTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class AmorLincTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerAMORLINC')]
public function testAMORLINC(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('AMORLINC', $expectedResult, $args);
}
public static function providerAMORLINC(): array
{
return require 'tests/data/Calculation/Financial/AMORLINC.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/PDurationTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/PDurationTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PHPUnit\Framework\Attributes\DataProvider;
class PDurationTest extends AllSetupTeardown
{
/** @param mixed[] $args */
#[DataProvider('providerPDURATION')]
public function testPDURATION(mixed $expectedResult, array $args): void
{
$this->runTestCase('PDURATION', $expectedResult, $args);
}
public static function providerPDURATION(): array
{
return require 'tests/data/Calculation/Financial/PDURATION.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/CoupNumTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/CoupNumTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class CoupNumTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCOUPNUM')]
public function testCOUPNUM(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('COUPNUM', $expectedResult, $args);
}
public static function providerCOUPNUM(): array
{
return require 'tests/data/Calculation/Financial/COUPNUM.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/SlnTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/SlnTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PHPUnit\Framework\Attributes\DataProvider;
class SlnTest extends AllSetupTeardown
{
/** @param mixed[] $args */
#[DataProvider('providerSLN')]
public function testSLN(mixed $expectedResult, array $args): void
{
$this->runTestCase('SLN', $expectedResult, $args);
}
public static function providerSLN(): array
{
return require 'tests/data/Calculation/Financial/SLN.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/DbTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/DbTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class DbTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerDB')]
public function testDB(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('DB', $expectedResult, $args);
}
public static function providerDB(): array
{
return require 'tests/data/Calculation/Financial/DB.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/EffectTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/EffectTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class EffectTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerEFFECT')]
public function testEFFECT(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('EFFECT', $expectedResult, $args);
}
public static function providerEFFECT(): array
{
return require 'tests/data/Calculation/Financial/EFFECT.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/NominalTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/NominalTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class NominalTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerNOMINAL')]
public function testNOMINAL(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('NOMINAL', $expectedResult, $args);
}
public static function providerNOMINAL(): array
{
return require 'tests/data/Calculation/Financial/NOMINAL.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/CoupDayBsTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/CoupDayBsTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class CoupDayBsTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCOUPDAYBS')]
public function testCOUPDAYBS(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('COUPDAYBS', $expectedResult, $args);
}
public static function providerCOUPDAYBS(): array
{
return require 'tests/data/Calculation/Financial/COUPDAYBS.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/CumPrincTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/CumPrincTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class CumPrincTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCUMPRINC')]
public function testCUMPRINC(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('CUMPRINC', $expectedResult, $args);
}
public static function providerCUMPRINC(): array
{
return require 'tests/data/Calculation/Financial/CUMPRINC.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/PpmtTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/PpmtTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PHPUnit\Framework\Attributes\DataProvider;
class PpmtTest extends AllSetupTeardown
{
/** @param mixed[] $args */
#[DataProvider('providerPPMT')]
public function testPPMT(mixed $expectedResult, array $args): void
{
$this->runTestCase('PPMT', $expectedResult, $args);
}
public static function providerPPMT(): array
{
return require 'tests/data/Calculation/Financial/PPMT.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/SydTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/SydTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PHPUnit\Framework\Attributes\DataProvider;
class SydTest extends AllSetupTeardown
{
/** @param mixed[] $args */
#[DataProvider('providerSYD')]
public function testSYD(mixed $expectedResult, array $args): void
{
$this->runTestCase('SYD', $expectedResult, $args);
}
public static function providerSYD(): array
{
return require 'tests/data/Calculation/Financial/SYD.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/FvTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/FvTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PHPUnit\Framework\Attributes\DataProvider;
class FvTest extends AllSetupTeardown
{
/** @param mixed[] $args */
#[DataProvider('providerFV')]
public function testFV(mixed $expectedResult, array $args): void
{
$this->runTestCase('FV', $expectedResult, $args);
}
public static function providerFV(): array
{
return require 'tests/data/Calculation/Financial/FV.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/PriceTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/PriceTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class PriceTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerPRICE')]
public function testPRICE(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('PRICE', $expectedResult, $args);
}
public static function providerPRICE(): array
{
return require 'tests/data/Calculation/Financial/PRICE.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerPRICE3')]
public function testPRICE3(mixed $expectedResult, mixed ...$args): void
{
// These results (PRICE function with basis codes 2 and 3)
// agree with published algorithm, LibreOffice, and Gnumeric.
// They do not agree with Excel.
$this->runTestCase('PRICE', $expectedResult, $args);
}
public static function providerPRICE3(): array
{
return require 'tests/data/Calculation/Financial/PRICE3.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/RriTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/RriTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PHPUnit\Framework\Attributes\DataProvider;
class RriTest extends AllSetupTeardown
{
/** @param mixed[] $args */
#[DataProvider('providerRRI')]
public function testRRI(mixed $expectedResult, array $args): void
{
$this->runTestCase('RRI', $expectedResult, $args);
}
public static function providerRRI(): array
{
return require 'tests/data/Calculation/Financial/RRI.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/HelpersTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/HelpersTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Financial\Helpers;
use PHPUnit\Framework\TestCase;
class HelpersTest extends TestCase
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerDaysPerYear')]
public function testDaysPerYear(mixed $expectedResult, int $year, int|string $basis): void
{
$result = Helpers::daysPerYear($year, $basis);
self::assertSame($expectedResult, $result);
}
public static function providerDaysPerYear(): array
{
return require 'tests/data/Calculation/Financial/DaysPerYear.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/TBillYieldTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/TBillYieldTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class TBillYieldTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerTBILLYIELD')]
public function testTBILLYIELD(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('TBILLYIELD', $expectedResult, $args);
}
public static function providerTBILLYIELD(): array
{
return require 'tests/data/Calculation/Financial/TBILLYIELD.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/AccrintTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/AccrintTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class AccrintTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerACCRINT')]
public function testACCRINT(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('ACCRINT', $expectedResult, $args);
}
public static function providerACCRINT(): array
{
return require 'tests/data/Calculation/Financial/ACCRINT.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/AmorDegRcTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/AmorDegRcTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class AmorDegRcTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerAMORDEGRC')]
public function testAMORDEGRC(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('AMORDEGRC', $expectedResult, $args);
}
public static function providerAMORDEGRC(): array
{
return require 'tests/data/Calculation/Financial/AMORDEGRC.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/IsPmtTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/IsPmtTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class IsPmtTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerISPMT')]
public function testISPMT(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('ISPMT', $expectedResult, $args);
}
public static function providerISPMT(): array
{
return require 'tests/data/Calculation/Financial/ISPMT.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/NpvTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/NpvTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class NpvTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerNPV')]
public function testNPV(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('NPV', $expectedResult, $args);
}
public static function providerNPV(): array
{
return require 'tests/data/Calculation/Financial/NPV.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/DdbTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/DdbTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class DdbTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerDDB')]
public function testDDB(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('DDB', $expectedResult, $args);
}
public static function providerDDB(): array
{
return require 'tests/data/Calculation/Financial/DDB.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/AccrintMTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/AccrintMTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class AccrintMTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerACCRINTM')]
public function testACCRINTM(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('ACCRINTM', $expectedResult, $args);
}
public static function providerACCRINTM(): array
{
return require 'tests/data/Calculation/Financial/ACCRINTM.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/CoupDaysNcTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/CoupDaysNcTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class CoupDaysNcTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCOUPDAYSNC')]
public function testCOUPDAYSNC(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('COUPDAYSNC', $expectedResult, $args);
}
public static function providerCOUPDAYSNC(): array
{
return require 'tests/data/Calculation/Financial/COUPDAYSNC.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/NPerTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/NPerTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PHPUnit\Framework\Attributes\DataProvider;
class NPerTest extends AllSetupTeardown
{
/** @param mixed[] $args */
#[DataProvider('providerNPER')]
public function testNPER(mixed $expectedResult, array $args): void
{
$this->runTestCase('NPER', $expectedResult, $args);
}
public static function providerNPER(): array
{
return require 'tests/data/Calculation/Financial/NPER.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/IntRateTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/IntRateTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class IntRateTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerINTRATE')]
public function testINTRATE(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('INTRATE', $expectedResult, $args);
}
public static function providerINTRATE(): array
{
return require 'tests/data/Calculation/Financial/INTRATE.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/CoupNcdTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/CoupNcdTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class CoupNcdTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCOUPNCD')]
public function testCOUPNCD(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('COUPNCD', $expectedResult, $args);
}
public static function providerCOUPNCD(): array
{
return require 'tests/data/Calculation/Financial/COUPNCD.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/PmtTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/PmtTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PHPUnit\Framework\Attributes\DataProvider;
class PmtTest extends AllSetupTeardown
{
/** @param mixed[] $args */
#[DataProvider('providerPMT')]
public function testPMT(mixed $expectedResult, array $args): void
{
$this->runTestCase('PMT', $expectedResult, $args);
}
public static function providerPMT(): array
{
return require 'tests/data/Calculation/Financial/PMT.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/CoupDaysTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/CoupDaysTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class CoupDaysTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCOUPDAYS')]
public function testCOUPDAYS(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('COUPDAYS', $expectedResult, $args);
}
public static function providerCOUPDAYS(): array
{
return require 'tests/data/Calculation/Financial/COUPDAYS.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/YieldMatTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/YieldMatTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class YieldMatTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerYIELDMAT')]
public function testYIELDMAT(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('YIELDMAT', $expectedResult, $args);
}
public static function providerYIELDMAT(): array
{
return require 'tests/data/Calculation/Financial/YIELDMAT.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/XNpvTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/XNpvTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class XNpvTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerXNPV')]
public function testXNPV(mixed $expectedResult, mixed $rate = null, mixed $values = null, mixed $dates = null): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$formula = '=XNPV(';
if ($rate !== null) {
$this->setCell('C1', $rate);
$formula .= 'C1,';
if ($values !== null) {
if (is_array($values)) {
$row = 0;
foreach ($values as $value) {
++$row;
$sheet->getCell("A$row")->setValue($value);
}
$formula .= "A1:A$row";
} else {
$sheet->getCell('A1')->setValue($values);
$formula .= 'A1';
}
if ($dates !== null) {
if (is_array($dates)) {
$row = 0;
foreach ($dates as $date) {
++$row;
$sheet->getCell("B$row")->setValue($date);
}
$formula .= ",B1:B$row";
} else {
$sheet->getCell('B1')->setValue($dates);
$formula .= ',B1';
}
}
}
}
$formula .= ')';
$sheet->getCell('D1')->setValue($formula);
$result = $sheet->getCell('D1')->getCalculatedValue();
if (is_numeric($result) && is_numeric($expectedResult)) {
if ($expectedResult != 0) {
$frac = $result / $expectedResult;
if ($frac > 0.999999 && $frac < 1.000001) {
$result = $expectedResult;
}
} elseif (abs((float) $result) < 1E-4) {
$result = 0;
}
}
self::assertEquals($expectedResult, $result);
}
public static function providerXNPV(): array
{
return require 'tests/data/Calculation/Financial/XNPV.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/DiscTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/DiscTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class DiscTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerDISC')]
public function testDISC(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('DISC', $expectedResult, $args);
}
public static function providerDISC(): array
{
return require 'tests/data/Calculation/Financial/DISC.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/PriceDiscTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/PriceDiscTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PHPUnit\Framework\Attributes\DataProvider;
class PriceDiscTest extends AllSetupTeardown
{
/** @param mixed[] $args */
#[DataProvider('providerPRICEDISC')]
public function testPRICEDISC(mixed $expectedResult, array $args): void
{
$this->runTestCase('PRICEDISC', $expectedResult, $args);
}
public static function providerPRICEDISC(): array
{
return require 'tests/data/Calculation/Financial/PRICEDISC.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/IPmtTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/IPmtTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PHPUnit\Framework\Attributes\DataProvider;
class IPmtTest extends AllSetupTeardown
{
/** @param mixed[] $args */
#[DataProvider('providerIPMT')]
public function testIPMT(mixed $expectedResult, array $args): void
{
$this->runTestCase('IPMT', $expectedResult, $args);
}
public static function providerIPMT(): array
{
return require 'tests/data/Calculation/Financial/IPMT.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/ReceivedTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/ReceivedTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class ReceivedTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerRECEIVED')]
public function testRECEIVED(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('RECEIVED', $expectedResult, $args);
}
public static function providerRECEIVED(): array
{
return require 'tests/data/Calculation/Financial/RECEIVED.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/MirrTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/MirrTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
class MirrTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerMIRR')]
public function testMIRR(mixed $expectedResult, mixed $values, mixed $financeRate = null, mixed $reinvestRate = null): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$formula = '=MIRR(';
if ($values !== null) {
if (is_array($values)) {
$values = Functions::flattenArray($values);
$row = 0;
foreach ($values as $value) {
++$row;
$this->setCell("A$row", $value);
}
$formula .= "A1:A$row";
} else {
$this->setCell('A1', $values);
$formula .= 'A1';
}
if ($financeRate !== null) {
$this->setCell('B1', $financeRate);
$formula .= ',B1';
if ($reinvestRate !== null) {
$this->setCell('B2', $reinvestRate);
$formula .= ',B2';
}
}
}
$formula .= ')';
$sheet->getCell('D1')->setValue($formula);
$result = $sheet->getCell('D1')->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1.0E-8);
}
public static function providerMIRR(): array
{
return require 'tests/data/Calculation/Financial/MIRR.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/UsDollarTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/UsDollarTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class UsDollarTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerUSDOLLAR')]
public function testUSDOLLAR(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('USDOLLAR', $expectedResult, $args);
}
public static function providerUSDOLLAR(): array
{
return require 'tests/data/Calculation/Financial/USDOLLAR.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/XirrTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/XirrTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class XirrTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerXIRR')]
public function testXIRR(mixed $expectedResult, mixed $values = null, mixed $dates = null, mixed $guess = null): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$formula = '=XIRR(';
if ($values !== null) {
if (is_array($values)) {
$row = 0;
foreach ($values as $value) {
++$row;
$sheet->getCell("A$row")->setValue($value);
}
$formula .= "A1:A$row";
} else {
$sheet->getCell('A1')->setValue($values);
$formula .= 'A1';
}
if ($dates !== null) {
if (is_array($dates)) {
$row = 0;
foreach ($dates as $date) {
++$row;
$sheet->getCell("B$row")->setValue($date);
}
$formula .= ",B1:B$row";
} else {
$sheet->getCell('B1')->setValue($dates);
$formula .= ',B1';
}
if ($guess !== null) {
if ($guess !== 'C1') {
$sheet->getCell('C1')->setValue($guess);
}
$formula .= ', C1';
}
}
}
$formula .= ')';
$sheet->getCell('D1')->setValue($formula);
$result = $sheet->getCell('D1')->getCalculatedValue();
$this->adjustResult($result, $expectedResult);
self::assertEqualsWithDelta($expectedResult, $result, 0.1E-7);
}
public static function providerXIRR(): array
{
return require 'tests/data/Calculation/Financial/XIRR.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/RateTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Financial/RateTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
class RateTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerRATE')]
public function testRATE(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('RATE', $expectedResult, $args);
}
public static function providerRATE(): array
{
return require 'tests/data/Calculation/Financial/RATE.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeValueTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeValueTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\DateTime;
use DateTimeInterface;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\DateTimeExcel\TimeValue;
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 TimeValueTest 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('providerTIMEVALUE')]
public function testDirectCallToTIMEVALUE(int|float|string $expectedResult, bool|int|string $value): void
{
$result = TimeValue::fromString($value);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-8);
}
#[DataProvider('providerTIMEVALUE')]
public function testTIMEVALUEAsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=TIMEVALUE({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-8);
}
#[DataProvider('providerTIMEVALUE')]
public function testTIMEVALUEInWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=TIMEVALUE({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-8);
$spreadsheet->disconnectWorksheets();
}
public static function providerTIMEVALUE(): array
{
return require 'tests/data/Calculation/DateTime/TIMEVALUE.php';
}
public function testRefArgNull(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue('=TIMEVALUE(B1)');
self::assertSame('#VALUE!', $sheet->getCell('A1')->getCalculatedValue());
$spreadsheet->disconnectWorksheets();
}
public function testTIMEVALUEtoUnixTimestamp(): void
{
Functions::setReturnDateType(Functions::RETURNDATE_UNIX_TIMESTAMP);
$result = TimeValue::fromString('7:30:20');
self::assertEquals(23420, $result);
self::assertEqualsWithDelta(23420, $result, 1.0e-8);
}
public function testTIMEVALUEtoDateTimeObject(): void
{
Functions::setReturnDateType(Functions::RETURNDATE_PHP_DATETIME_OBJECT);
$result = TimeValue::fromString('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');
}
#[DataProvider('providerUnhappyTIMEVALUE')]
public function testTIMEVALUEUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=TIMEVALUE({$argumentCells})";
$this->expectException(CalculationException::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyTIMEVALUE(): array
{
return [
['Formula Error: Wrong number of arguments for TIMEVALUE() function'],
];
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerTimeValueArray')]
public function testTimeValueArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=TIMEVALUE({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerTimeValueArray(): array
{
return [
'row vector' => [[[0.04309027777777, 0.5515625, 0.80579861111111]], '{"2022-02-09 01:02:03", "2022-02-09 13:14:15", "2022-02-09 19:20:21"}'],
'column vector' => [[[0.04309027777777], [0.5515625], [0.80579861111111]], '{"2022-02-09 01:02:03"; "2022-02-09 13:14:15"; "2022-02-09 19:20:21"}'],
'matrix' => [[[0.04309027777777, 0.5515625], [0.80579861111111, 0.99998842592592]], '{"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/DayTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DayTest.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\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class DayTest extends TestCase
{
private string $compatibilityMode;
protected function setUp(): void
{
parent::setUp();
$this->compatibilityMode = Functions::getCompatibilityMode();
}
protected function tearDown(): void
{
parent::tearDown();
Functions::setCompatibilityMode($this->compatibilityMode);
}
#[DataProvider('providerDAY')]
public function testDirectCallToDAY(mixed $expectedResultExcel, mixed ...$args): void
{
$result = DateParts::day(...$args);
self::assertSame($expectedResultExcel, $result);
}
#[DataProvider('providerDAY')]
public function testDAYAsFormula(mixed $expectedResultExcel, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=DAY({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResultExcel, $result);
}
#[DataProvider('providerDAY')]
public function testDAYInWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=DAY({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public static function providerDAY(): array
{
return require 'tests/data/Calculation/DateTime/DAY.php';
}
#[DataProvider('providerDAYOpenOffice')]
public function testDirectCallToDAYOpenOffice(mixed $expectedResultOpenOffice, mixed ...$args): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
$result = DateParts::day(...$args);
self::assertSame($expectedResultOpenOffice, $result);
}
#[DataProvider('providerDAYOpenOffice')]
public function testDAYAsFormulaOpenOffice(mixed $expectedResultOpenOffice, mixed ...$args): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=DAY({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResultOpenOffice, $result);
}
public static function providerDAYOpenOffice(): array
{
return require 'tests/data/Calculation/DateTime/DAYOpenOffice.php';
}
#[DataProvider('providerUnhappyDAY')]
public function testDAYUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=DAY({$argumentCells})";
$this->expectException(CalculationException::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyDAY(): array
{
return [
['Formula Error: Wrong number of arguments for DAY() function'],
];
}
public function testDirectCallToDAYWithNull(): void
{
$result = DateParts::day(null);
self::assertSame(0, $result);
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerDayArray')]
public function testDayArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=DAY({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerDayArray(): array
{
return [
'row vector' => [[[1, 12, 22]], '{"2022-01-01", "2022-06-12", "2023-07-22"}'],
'column vector' => [[[1], [3], [6]], '{"2022-01-01"; "2022-01-03"; "2022-01-06"}'],
'matrix' => [[[1, 10], [15, 31]], '{"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/WeekDayTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekDayTest.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\Shared\Date as SharedDate;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class WeekDayTest 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('providerWEEKDAY')]
public function testDirectCallToWEEKDAY(int|string $expectedResult, bool|int|string $dateValue, null|int|string $style = null): void
{
$result = ($style === null) ? Week::day($dateValue) : Week::day($dateValue, $style);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerWEEKDAY')]
public function testWEEKDAYAsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=WEEKDAY({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerWEEKDAY')]
public function testWEEKDAYInWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=WEEKDAY({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public static function providerWEEKDAY(): array
{
return require 'tests/data/Calculation/DateTime/WEEKDAY.php';
}
#[DataProvider('providerUnhappyWEEKDAY')]
public function testWEEKDAYUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=WEEKDAY({$argumentCells})";
$this->expectException(\PhpOffice\PhpSpreadsheet\Calculation\Exception::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyWEEKDAY(): array
{
return [
['Formula Error: Wrong number of arguments for WEEKDAY() function'],
];
}
public function testWEEKDAYWith1904Calendar(): void
{
SharedDate::setExcelCalendar(SharedDate::CALENDAR_MAC_1904);
self::assertEquals(7, Week::day('1904-01-02'));
self::assertEquals(6, Week::day('1904-01-01'));
self::assertEquals(6, Week::day(null));
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerWeekDayArray')]
public function testWeekDayArray(array $expectedResult, string $dateValues, string $styles): void
{
$calculation = Calculation::getInstance();
$formula = "=WEEKDAY({$dateValues}, {$styles})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerWeekDayArray(): array
{
return [
'row vector #1' => [[[7, 1, 7]], '{"2022-01-01", "2022-06-12", "2023-07-22"}', '1'],
'column vector #1' => [[[1], [7], [7]], '{"2023-01-01"; "2023-04-01"; "2023-07-01"}', '1'],
'matrix #1' => [[[6, 6], [1, 1]], '{"2021-01-01", "2021-12-31"; "2023-01-01", "2023-12-31"}', '1'],
'row vector #2' => [[[7, 6]], '"2022-01-01"', '{1, 2}'],
'column vector #2' => [[[1], [7]], '"2023-01-01"', '{1; 2}'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MinuteTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MinuteTest.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 MinuteTest extends TestCase
{
#[DataProvider('providerMINUTE')]
public function testDirectCallToMINUTE(mixed $expectedResult, mixed ...$args): void
{
$result = TimeParts::MINUTE(...$args);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerMINUTE')]
public function testMINUTEAsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=MINUTE({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerMINUTE')]
public function testMINUTEInWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=MINUTE({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public static function providerMINUTE(): array
{
return require 'tests/data/Calculation/DateTime/MINUTE.php';
}
#[DataProvider('providerUnhappyMINUTE')]
public function testMINUTEUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=MINUTE({$argumentCells})";
$this->expectException(CalculationException::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyMINUTE(): array
{
return [
['Formula Error: Wrong number of arguments for MINUTE() function'],
];
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerMinuteArray')]
public function testMinuteArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=MINUTE({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerMinuteArray(): array
{
return [
'row vector' => [[[2, 14, 20]], '{"2022-02-09 01:02:03", "2022-02-09 13:14:15", "2022-02-09 19:20:21"}'],
'column vector' => [[[2], [14], [20]], '{"2022-02-09 01:02:03"; "2022-02-09 13:14:15"; "2022-02-09 19:20:21"}'],
'matrix' => [[[2, 14], [20, 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/YearTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/YearTest.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\Spreadsheet;
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class YearTest extends TestCase
{
#[DataProvider('providerYEAR')]
public function testDirectCallToYEAR(mixed $expectedResultExcel, mixed ...$args): void
{
$result = DateParts::year(...$args);
self::assertSame($expectedResultExcel, $result);
}
#[DataProvider('providerYEAR')]
public function testYEARAsFormula(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$calculation = Calculation::getInstance();
$formula = "=YEAR({$arguments})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
#[DataProvider('providerYEAR')]
public function testYEARInWorksheet(mixed $expectedResult, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=YEAR({$argumentCells})";
$result = $worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public static function providerYEAR(): array
{
return require 'tests/data/Calculation/DateTime/YEAR.php';
}
#[DataProvider('providerUnhappyYEAR')]
public function testYEARUnhappyPath(string $expectedException, mixed ...$args): void
{
$arguments = new FormulaArguments(...$args);
$spreadsheet = new Spreadsheet();
$worksheet = $spreadsheet->getActiveSheet();
$argumentCells = $arguments->populateWorksheet($worksheet);
$formula = "=YEAR({$argumentCells})";
$this->expectException(\PhpOffice\PhpSpreadsheet\Calculation\Exception::class);
$this->expectExceptionMessage($expectedException);
$worksheet->setCellValue('A1', $formula)
->getCell('A1')
->getCalculatedValue();
$spreadsheet->disconnectWorksheets();
}
public static function providerUnhappyYEAR(): array
{
return [
['Formula Error: Wrong number of arguments for YEAR() function'],
];
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerYearArray')]
public function testYearArray(array $expectedResult, string $array): void
{
$calculation = Calculation::getInstance();
$formula = "=YEAR({$array})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerYearArray(): array
{
return [
'row vector' => [[[2021, 2022, 2023]], '{"2021-01-01", "2022-01-01", "2023-01-01"}'],
'column vector' => [[[2021], [2022], [2023]], '{"2021-01-01"; "2022-01-01"; "2023-01-01"}'],
'matrix' => [[[2021, 2022], [2023, 1999]], '{"2021-01-01", "2022-01-01"; "2023-01-01", "1999-12-31"}'],
];
}
}
| 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.