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/LookupRef/IndirectInternationalTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/IndirectInternationalTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Settings;
class IndirectInternationalTest extends AllSetupTeardown
{
private string $locale;
protected function setUp(): void
{
parent::setUp();
$this->locale = Settings::getLocale();
}
protected function tearDown(): void
{
Settings::setLocale($this->locale);
// CompatibilityMode is restored in parent
parent::tearDown();
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerInternational')]
public function testR1C1International(string $locale): void
{
Settings::setLocale($locale);
$sameAsEnglish = ['en', 'xx', 'ru', 'tr', 'cs', 'pl'];
$sheet = $this->getSheet();
$sheet->getCell('C1')->setValue('text');
$sheet->getCell('A2')->setValue('en');
$sheet->getCell('B2')->setValue('=INDIRECT("R1C3", false)');
$sheet->getCell('A3')->setValue('fr');
$sheet->getCell('B3')->setValue('=INDIRECT("L1C3", false)');
$sheet->getCell('A4')->setValue('de');
$sheet->getCell('B4')->setValue('=INDIRECT("Z1S3", false)');
$sheet->getCell('A5')->setValue('es');
$sheet->getCell('B5')->setValue('=INDIRECT("F1C3", false)');
$sheet->getCell('A6')->setValue('xx');
$sheet->getCell('B6')->setValue('=INDIRECT("R1C3", false)');
$sheet->getCell('A7')->setValue('ru');
$sheet->getCell('B7')->setValue('=INDIRECT("R1C3", false)');
$sheet->getCell('A8')->setValue('cs');
$sheet->getCell('B8')->setValue('=INDIRECT("R1C3", false)');
$sheet->getCell('A9')->setValue('tr');
$sheet->getCell('B9')->setValue('=INDIRECT("R1C3", false)');
$sheet->getCell('A10')->setValue('pl');
$sheet->getCell('B10')->setValue('=INDIRECT("R1C3", false)');
$maxRow = $sheet->getHighestRow();
for ($row = 2; $row <= $maxRow; ++$row) {
/** @var null|bool|float|int|string */
$rowLocale = $sheet->getCell("A$row")->getValue();
if (in_array($rowLocale, $sameAsEnglish, true) && in_array($locale, $sameAsEnglish, true)) {
$expectedResult = 'text';
} else {
$expectedResult = ($locale === $sheet->getCell("A$row")->getValue()) ? 'text' : '#REF!';
}
self::assertSame($expectedResult, $sheet->getCell("B$row")->getCalculatedValue(), "Locale $locale error in cell B$row $rowLocale");
}
}
public static function providerInternational(): array
{
return [
'English' => ['en'],
'French' => ['fr'],
'German' => ['de'],
'Made-up' => ['xx'],
'Spanish' => ['es'],
'Russian' => ['ru'],
'Czech' => ['cs'],
'Polish' => ['pl'],
'Turkish' => ['tr'],
];
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerRelativeInternational')]
public function testRelativeInternational(string $locale, string $cell, string $relative): void
{
Settings::setLocale($locale);
$sheet = $this->getSheet();
$sheet->getCell('C3')->setValue('text');
$sheet->getCell($cell)->setValue("=INDIRECT(\"$relative\", false)");
self::assertSame('text', $sheet->getCell($cell)->getCalculatedValue());
}
public static function providerRelativeInternational(): array
{
return [
'English A3' => ['en', 'A3', 'R[]C[+2]'],
'French B4' => ['fr', 'B4', 'L[-1]C[+1]'],
'German C5' => ['de', 'C5', 'Z[-2]S[]'],
'Spanish E1' => ['es', 'E1', 'F[+2]C[-2]'],
];
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerCompatibility')]
public function testCompatibilityInternational(string $compatibilityMode): void
{
Functions::setCompatibilityMode($compatibilityMode);
if ($compatibilityMode === Functions::COMPATIBILITY_EXCEL) {
$expected1 = '#REF!';
$expected2 = 'text';
} else {
$expected2 = '#REF!';
$expected1 = 'text';
}
Settings::setLocale('fr');
$sheet = $this->getSheet();
$sheet->getCell('C3')->setValue('text');
$sheet->getCell('A1')->setValue('=INDIRECT("R3C3", false)');
$sheet->getCell('A2')->setValue('=INDIRECT("L3C3", false)');
self::assertSame($expected1, $sheet->getCell('A1')->getCalculatedValue());
self::assertSame($expected2, $sheet->getCell('A2')->getCalculatedValue());
}
public static function providerCompatibility(): array
{
return [
[Functions::COMPATIBILITY_EXCEL],
[Functions::COMPATIBILITY_OPENOFFICE],
[Functions::COMPATIBILITY_GNUMERIC],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ColumnsTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ColumnsTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class ColumnsTest extends TestCase
{
/** @param null|mixed[]|string $arg */
#[DataProvider('providerCOLUMNS')]
public function testCOLUMNS(mixed $expectedResult, null|array|string $arg): void
{
$result = LookupRef\RowColumnInformation::COLUMNS($arg);
self::assertEquals($expectedResult, $result);
}
public static function providerCOLUMNS(): array
{
return require 'tests/data/Calculation/LookupRef/COLUMNS.php';
}
#[DataProvider('providerColumnsArray')]
public function testColumnsArray(int $expectedResult, string $argument): void
{
$calculation = Calculation::getInstance();
$formula = "=COLUMNS({$argument})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
public static function providerColumnsArray(): array
{
return [
[
3,
'{1,2,3;4,5,6}',
],
[
5,
'{1,2,3,4,5}',
],
[
1,
'{1;2;3;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/LookupRef/AllSetupTeardown.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/AllSetupTeardown.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
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
{
protected string $compatibilityMode;
protected string $arrayReturnType;
protected ?Spreadsheet $spreadsheet = null;
private ?Worksheet $sheet = null;
protected function setUp(): void
{
$this->compatibilityMode = Functions::getCompatibilityMode();
$this->arrayReturnType = Calculation::getArrayReturnType();
}
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
Calculation::setArrayReturnType($this->arrayReturnType);
$this->sheet = null;
if ($this->spreadsheet !== null) {
$this->spreadsheet->disconnectWorksheets();
$this->spreadsheet = null;
}
}
protected static function setOpenOffice(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
}
protected static function setGnumeric(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_GNUMERIC);
}
protected function mightHaveException(mixed $expectedResult): void
{
if ($expectedResult === 'exception') {
$this->expectException(CalcException::class);
}
}
protected function setCell(string $cell, mixed $value): void
{
if ($value !== null) {
if (is_string($value) && is_numeric($value)) {
$this->getSheet()->getCell($cell)->setValueExplicit($value, DataType::TYPE_STRING);
} else {
$this->getSheet()->getCell($cell)->setValue($value);
}
}
}
protected function getSpreadsheet(): Spreadsheet
{
if ($this->spreadsheet !== null) {
return $this->spreadsheet;
}
$this->spreadsheet = new Spreadsheet();
return $this->spreadsheet;
}
protected function getSheet(): Worksheet
{
if ($this->sheet !== null) {
return $this->sheet;
}
$this->sheet = $this->getSpreadsheet()->getActiveSheet();
return $this->sheet;
}
protected function setArrayAsValue(): void
{
$spreadsheet = $this->getSpreadsheet();
$calculation = Calculation::getInstance($spreadsheet);
$calculation->setInstanceArrayReturnType(
Calculation::RETURN_ARRAY_AS_VALUE
);
}
protected function setArrayAsArray(): void
{
$spreadsheet = $this->getSpreadsheet();
$calculation = Calculation::getInstance($spreadsheet);
$calculation->setInstanceArrayReturnType(
Calculation::RETURN_ARRAY_AS_ARRAY
);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/HyperlinkTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/HyperlinkTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
class HyperlinkTest extends AllSetupTeardown
{
private bool $issue2464 = true;
#[\PHPUnit\Framework\Attributes\DataProvider('providerHYPERLINK')]
public function testHYPERLINK(mixed $expectedResult, ?string $linkUrl, ?string $description): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$formula = '=HYPERLINK(';
if ($linkUrl !== null) {
$formula .= '"' . $linkUrl . '"';
if ($description !== null) {
$formula .= ',"' . $description . '"';
}
}
$formula .= ')';
$sheet->getCell('A1')->setValue($formula);
$result = $sheet->getCell('A1')->getCalculatedValue();
if (!is_array($expectedResult)) {
self::assertSame($expectedResult, $result);
} else {
self::assertSame($expectedResult[1], $result);
$hyperlink = $sheet->getCell('A1')->getHyperlink();
self::assertSame($expectedResult[0], $hyperlink->getUrl());
self::assertSame($expectedResult[1], $hyperlink->getTooltip());
}
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerHYPERLINK')]
public function testHYPERLINKcellRef(mixed $expectedResult, ?string $linkUrl, ?string $description): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$formula = '=HYPERLINK(';
if ($linkUrl !== null) {
$sheet->getCell('A2')->setValue($linkUrl);
$formula .= 'A2';
if ($description !== null) {
$sheet->getCell('A3')->setValue($description);
$formula .= ',A3';
}
}
$formula .= ')';
$sheet->getCell('A1')->setValue($formula);
$result = $sheet->getCell('A1')->getCalculatedValue();
if (!is_array($expectedResult)) {
self::assertSame($expectedResult, $result);
} else {
self::assertSame($expectedResult[1], $result);
if (!$this->issue2464) {
$hyperlink = $sheet->getCell('A1')->getHyperlink();
self::assertSame($expectedResult[0], $hyperlink->getUrl());
self::assertSame($expectedResult[1], $hyperlink->getTooltip());
}
}
}
public function testLen(): void
{
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=LEN(HYPERLINK("http://www.example.com","Example"))');
$value = $sheet->getCell('A1')->getCalculatedValue();
self::assertSame(7, $value);
if ($this->issue2464) {
self::markTestIncomplete('testLen and testHYPERLINKcellRef incomplete due to issue 2464');
} else {
$hyperlink = $sheet->getCell('A1')->getHyperlink();
self::assertSame('', $hyperlink->getUrl());
self::assertSame('', $hyperlink->getTooltip());
}
}
public static function providerHYPERLINK(): array
{
return require 'tests/data/Calculation/LookupRef/HYPERLINK.php';
}
public function testHYPERLINKwithoutCell(): void
{
$result = LookupRef\Hyperlink::set('https://phpspreadsheet.readthedocs.io/en/latest/', 'Read the Docs');
self::assertSame(ExcelError::REF(), $result);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ChooseTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ChooseTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class ChooseTest extends TestCase
{
#[DataProvider('providerCHOOSE')]
public function testCHOOSE(mixed $expectedResult, mixed ...$args): void
{
$result = LookupRef\Selection::choose(...$args);
self::assertEquals($expectedResult, $result);
}
public static function providerCHOOSE(): array
{
return require 'tests/data/Calculation/LookupRef/CHOOSE.php';
}
/** @param mixed[] $selections */
#[DataProvider('providerChooseArray')]
public function testChooseArray(array $expectedResult, string $values, array $selections): void
{
$calculation = Calculation::getInstance();
$selections = implode(',', $selections);
$formula = "=CHOOSE({$values}, {$selections})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
public static function providerChooseArray(): array
{
return [
'row vector' => [
[['Orange', 'Blue', 'Yellow']],
'{2, 5, 3}',
['"Red"', '"Orange"', '"Yellow"', '"Green"', '"Blue"'],
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/RowsOnSpreadsheetTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/RowsOnSpreadsheetTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\NamedRange;
class RowsOnSpreadsheetTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerROWSonSpreadsheet')]
public function testRowsOnSpreadsheet(mixed $expectedResult, string $cellReference = 'omitted'): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setTitle('ThisSheet');
$this->getSpreadsheet()->addNamedRange(new NamedRange('namedrangex', $sheet, '$E$2:$E$6'));
$this->getSpreadsheet()->addNamedRange(new NamedRange('namedrangey', $sheet, '$F$2:$H$2'));
$this->getSpreadsheet()->addNamedRange(new NamedRange('namedrange3', $sheet, '$F$4:$H$4'));
$this->getSpreadsheet()->addNamedRange(new NamedRange('namedrange5', $sheet, '$F$5:$H$5', true));
$sheet1 = $this->getSpreadsheet()->createSheet();
$sheet1->setTitle('OtherSheet');
$this->getSpreadsheet()->addNamedRange(new NamedRange('localname', $sheet1, '$F$6:$H$6', true));
if ($cellReference === 'omitted') {
$sheet->getCell('B3')->setValue('=ROWS()');
} else {
$sheet->getCell('B3')->setValue("=ROWS($cellReference)");
}
$result = $sheet->getCell('B3')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
public static function providerROWSOnSpreadsheet(): array
{
return require 'tests/data/Calculation/LookupRef/ROWSonSpreadsheet.php';
}
public function testRowsLocalDefinedName(): void
{
$sheet = $this->getSheet();
$sheet1 = $this->getSpreadsheet()->createSheet();
$sheet1->setTitle('OtherSheet');
$this->getSpreadsheet()->addNamedRange(new NamedRange('newnr', $sheet1, '$F$5:$H$10', true)); // defined locally, only usable on sheet1
$sheet1->getCell('B3')->setValue('=ROWS(newnr)');
$result = $sheet1->getCell('B3')->getCalculatedValue();
self::assertSame(6, $result);
$sheet->getCell('B3')->setValue('=ROWS(newnr)');
$result = $sheet->getCell('B3')->getCalculatedValue();
self::assertSame('#NAME?', $result);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/LookupTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/LookupTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class LookupTest extends TestCase
{
#[DataProvider('providerLOOKUP')]
public function testLOOKUP(mixed $expectedResult, mixed ...$args): void
{
$result = LookupRef\Lookup::lookup(...$args);
self::assertEquals($expectedResult, $result);
}
public static function providerLOOKUP(): array
{
return require 'tests/data/Calculation/LookupRef/LOOKUP.php';
}
#[DataProvider('providerLookupArray')]
public function testLookupArray(array $expectedResult, string $values, string $lookup, string $return): void
{
$calculation = Calculation::getInstance();
$formula = "=LOOKUP({$values}, {$lookup}, {$return})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
public static function providerLookupArray(): array
{
return [
'row vector' => [
[['Orange', 'Green', 'Red']],
'{4.19, 5.77, 4.14}',
'{4.14; 4.19; 5.17; 5.77; 6.39}',
'{"Red"; "Orange"; "Yellow"; "Green"; "Blue"}',
],
];
}
public function testBoolsAsInt(): void
{
// issue 3396 not handling math operation for bool in array
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A59')->setValue('start');
$sheet->getCell('B59')->setValue('end');
$sheet->getCell('C59')->setValue('percent');
$sheet->getCell('A60')->setValue('=DATEVALUE("1950-01-01")');
$sheet->getCell('B60')->setValue('=DATEVALUE("2016-06-03")');
$sheet->getCell('C60')->setValue(0.05);
$sheet->getCell('A61')->setValue('=DATEVALUE("2016-06-04")');
$sheet->getCell('B61')->setValue('=DATEVALUE("2021-01-05")');
$sheet->getCell('C61')->setValue(0.08);
$sheet->getCell('A62')->setValue('=DATEVALUE("2021-01-16")');
$sheet->getCell('B62')->setValue('=DATEVALUE("2022-04-08")');
$sheet->getCell('C62')->setValue(0.03);
$sheet->getCell('A63')->setValue('=DATEVALUE("2022-04-09")');
$sheet->getCell('B63')->setValue('=DATEVALUE("2500-12-31")');
$sheet->getCell('C63')->setValue(0.04);
$sheet->getCell('D5')->setValue(5);
$sheet->getCell('E5')->setValue('=DATEVALUE("2023-01-01")');
$sheet->getCell('D7')->setValue('=IF(E5<>"",LOOKUP(2,1/($A$60:$A$63<=E5)/($B$60:$B$63>=E5),$C$60:$C$63)*D5,"")');
self::assertSame(0.2, $sheet->getCell('D7')->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/LookupRef/SortTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/SortTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Sort;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class SortTest extends TestCase
{
public function testSortOnScalar(): void
{
$value = 'NON-ARRAY';
$result = Sort::sort($value, 1, -1);
self::assertSame([[$value]], $result);
}
#[DataProvider('providerSortWithScalarArgumentErrorReturns')]
public function testSortWithScalarArgumentErrorReturns(mixed $sortIndex, mixed $sortOrder = 1): void
{
$value = [[1, 2], [3, 4], [5, 6]];
$result = Sort::sort($value, $sortIndex, $sortOrder);
self::assertSame(ExcelError::VALUE(), $result);
}
public static function providerSortWithScalarArgumentErrorReturns(): array
{
return [
'Negative sortIndex' => [-1, -1],
'Non-numeric sortIndex' => ['A', -1],
'Zero sortIndex' => [0, -1],
'Too high sortIndex' => [3, -1],
'Non-numeric sortOrder' => [1, 'A'],
'Invalid negative sortOrder' => [1, -2],
'Zero sortOrder' => [1, 0],
'Invalid positive sortOrder' => [1, 2],
'Too many sortOrders (scalar and array)' => [1, [-1, 1]],
'Too many sortOrders (both array)' => [[1, 2], [1, 2, 3]],
'Zero positive sortIndex in vector' => [[0, 1]],
'Too high sortIndex in vector' => [[1, 3]],
'Invalid sortOrder in vector' => [[1, 2], [1, -2]],
];
}
/** @param mixed[] $matrix */
#[DataProvider('providerSortByRow')]
public function testSortByRow(array $expectedResult, array $matrix, int $sortIndex, int $sortOrder = Sort::ORDER_ASCENDING): void
{
$result = Sort::sort($matrix, $sortIndex, $sortOrder);
self::assertSame($expectedResult, $result);
}
/** @return mixed[] */
public static function providerSortByRow(): array
{
return [
[
[[142], [378], [404], [445], [483], [622], [650], [691], [783], [961]],
self::sampleDataForRow(),
1,
],
[
[[961], [783], [691], [650], [622], [483], [445], [404], [378], [142]],
self::sampleDataForRow(),
1,
Sort::ORDER_DESCENDING,
],
[
[['Peaches', 25], ['Cherries', 29], ['Grapes', 31], ['Lemons', 34], ['Oranges', 36], ['Apples', 38], ['Pears', 40]],
[['Apples', 38], ['Cherries', 29], ['Grapes', 31], ['Lemons', 34], ['Oranges', 36], ['Peaches', 25], ['Pears', 40]],
2,
],
];
}
/**
* @param mixed[] $matrix
* @param mixed[] $sortIndex
*/
#[DataProvider('providerSortByRowMultiLevel')]
public function testSortByRowMultiLevel(array $expectedResult, array $matrix, array $sortIndex, int $sortOrder = Sort::ORDER_ASCENDING): void
{
$result = Sort::sort($matrix, $sortIndex, $sortOrder);
self::assertSame($expectedResult, $result);
}
public static function providerSortByRowMultiLevel(): array
{
return [
[
[
['East', 'Grapes', 31],
['East', 'Lemons', 36],
['North', 'Cherries', 29],
['North', 'Grapes', 27],
['North', 'Peaches', 25],
['South', 'Apples', 38],
['South', 'Cherries', 28],
['South', 'Oranges', 36],
['South', 'Pears', 40],
['West', 'Apples', 30],
['West', 'Lemons', 34],
['West', 'Oranges', 25],
],
self::sampleDataForMultiRow(),
[1, 2],
],
[
[
['East', 'Grapes', 31],
['East', 'Lemons', 36],
['North', 'Peaches', 25],
['North', 'Grapes', 27],
['North', 'Cherries', 29],
['South', 'Cherries', 28],
['South', 'Oranges', 36],
['South', 'Apples', 38],
['South', 'Pears', 40],
['West', 'Oranges', 25],
['West', 'Apples', 30],
['West', 'Lemons', 34],
],
self::sampleDataForMultiRow(),
[1, 3],
],
[
[
['West', 'Apples', 30],
['South', 'Apples', 38],
['South', 'Cherries', 28],
['North', 'Cherries', 29],
['North', 'Grapes', 27],
['East', 'Grapes', 31],
['West', 'Lemons', 34],
['East', 'Lemons', 36],
['West', 'Oranges', 25],
['South', 'Oranges', 36],
['North', 'Peaches', 25],
['South', 'Pears', 40],
],
self::sampleDataForMultiRow(),
[2, 3],
],
];
}
/** @param mixed[] $matrix */
#[DataProvider('providerSortByColumn')]
public function testSortByColumn(array $expectedResult, array $matrix, int $sortIndex, int $sortOrder): void
{
$result = Sort::sort($matrix, $sortIndex, $sortOrder, true);
self::assertSame($expectedResult, $result);
}
public static function providerSortByColumn(): array
{
return [
[
[[142, 378, 404, 445, 483, 622, 650, 691, 783, 961]],
self::sampleDataForColumn(),
1,
Sort::ORDER_ASCENDING,
],
[
[[961, 783, 691, 650, 622, 483, 445, 404, 378, 142]],
self::sampleDataForColumn(),
1,
Sort::ORDER_DESCENDING,
],
];
}
/** @return array<int[]> */
public static function sampleDataForRow(): array
{
return [
[622], [961], [691], [445], [378], [483], [650], [783], [142], [404],
];
}
/** @return array<array{string, string, int}> */
public static function sampleDataForMultiRow(): array
{
return [
['South', 'Pears', 40],
['South', 'Apples', 38],
['South', 'Oranges', 36],
['East', 'Lemons', 36],
['West', 'Lemons', 34],
['East', 'Grapes', 31],
['West', 'Apples', 30],
['North', 'Cherries', 29],
['South', 'Cherries', 28],
['North', 'Grapes', 27],
['North', 'Peaches', 25],
['West', 'Oranges', 25],
];
}
/** @return array<int[]> */
public static function sampleDataForColumn(): array
{
return [
[622, 961, 691, 445, 378, 483, 650, 783, 142, 404],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/IndexOnSpreadsheetTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/IndexOnSpreadsheetTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PHPUnit\Framework\Attributes\DataProvider;
class IndexOnSpreadsheetTest extends AllSetupTeardown
{
/** @param mixed[] $matrix */
#[DataProvider('providerINDEXonSpreadsheet')]
public function testIndexOnSpreadsheet(mixed $expectedResult, array $matrix, null|int|string $rowNum = null, null|int|string $colNum = null): void
{
$this->mightHaveException($expectedResult);
$this->setArrayAsValue();
$sheet = $this->getSheet();
$sheet->fromArray($matrix);
$maxRow = $sheet->getHighestRow();
$maxColumn = $sheet->getHighestColumn();
$formulaArray = "A1:$maxColumn$maxRow";
if ($rowNum === null) {
$formula = "=INDEX($formulaArray)";
} elseif ($colNum === null) {
$formula = "=INDEX($formulaArray, $rowNum)";
} else {
$formula = "=INDEX($formulaArray, $rowNum, $colNum)";
}
$sheet->getCell('ZZ98')->setValue('x');
$sheet->getCell('ZZ99')->setValue($formula);
$result = $sheet->getCell('ZZ99')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public static function providerINDEXonSpreadsheet(): array
{
return require 'tests/data/Calculation/LookupRef/INDEXonSpreadsheet.php';
}
#[DataProvider('providerIndexLiteralArrays')]
public function testLiteralArrays(mixed $expectedResult, string $indexArgs): void
{
$this->setArrayAsValue();
$sheet = $this->getSheet();
$sheet->getCell('A10')->setValue(10);
$sheet->getCell('B10')->setValue(11);
$sheet->getCell('C10')->setValue(12);
$sheet->getCell('D10')->setValue(13);
$sheet->getCell('X10')->setValue(10);
$sheet->getCell('X11')->setValue(11);
$sheet->getCell('X12')->setValue(12);
$sheet->getCell('X13')->setValue(13);
$sheet->getCell('A1')->setValue("=INDEX($indexArgs)");
$result = $sheet->getCell('A1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public static function providerIndexLiteralArrays(): array
{
return [
'issue 64' => ['Fourth', '{"First","Second","Third","Fourth","Fifth","Sixth","Seventh"}, 4'],
'issue 64 selecting first "row"' => ['First', '{"First","Second","Third","Fourth","Fifth","Sixth","Seventh"}, 1'],
'array result condensed to single value' => [40, '{10,11;20,21;30,31;40,41;50,51;60,61},4'],
'both row and column' => [41, '{10,11;20,21;30,31;40,41;50,51;60,61},4,2'],
'1*1 array' => ['first', '{"first"},1'],
'array expressed in rows' => [20, '{10;20;30;40},2'],
'spreadsheet single row' => [11, 'A10:D10,2'],
'spreadsheet single column' => [13, 'X10:X13,4'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/TakeTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/TakeTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\NamedRange;
use PHPUnit\Framework\Attributes\DataProvider;
class TakeTest extends AllSetupTeardown
{
#[DataProvider('providerTake')]
public function testTake(mixed $expectedResult, string $formula): void
{
Calculation::setArrayReturnType(
Calculation::RETURN_ARRAY_AS_ARRAY
);
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->fromArray(
[
['a', 'b', 'c'],
['d', 'e', 'f'],
['g', 'h', 'i'],
['j', 'k', 'l'],
['m', 'n', 'o'],
['p', 'q', 'r'],
['s', 't', 'u'],
['v', 'w', 'x'],
['y', 'z', '#'],
],
null,
'B3',
true
);
$this->getSpreadsheet()->addNamedRange(
new NamedRange(
'definedname',
$sheet,
'$B$3:$D$11'
)
);
$sheet->setCellValue('F3', $formula);
$result = $sheet->getCell('F3')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
public static function providerTake(): array
{
return require 'tests/data/Calculation/LookupRef/TAKE.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/FilterTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/FilterTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Filter;
use PHPUnit\Framework\TestCase;
class FilterTest extends TestCase
{
public function testFilterByRow(): void
{
$criteria = [[true], [false], [false], [false], [true], [false], [false], [false], [false], [false], [false], [true], [false], [false], [false], [true]];
$expectedResult = [
['East', 'Tom', 'Apple', 6830],
['East', 'Fritz', 'Apple', 4394],
['South', 'Sal', 'Apple', 1310],
['South', 'Hector', 'Apple', 8144],
];
$result = Filter::filter($this->sampleDataForRow(), $criteria);
self::assertSame($expectedResult, $result);
}
public function testFilterByColumn(): void
{
$criteria = [[false, false, true, false, true, false, false, false, true, true]];
$expectedResult = [
['Betty', 'Charlotte', 'Oliver', 'Zoe'],
['B', 'B', 'B', 'B'],
[1, 2, 4, 8],
];
$result = Filter::filter($this->sampleDataForColumn(), $criteria);
self::assertSame($expectedResult, $result);
}
public function testFilterException(): void
{
$criteria = 'INVALID';
$result = Filter::filter($this->sampleDataForColumn(), $criteria);
self::assertSame(ExcelError::VALUE(), $result);
}
public function testFilterEmpty(): void
{
$criteria = [[false], [false], [false]];
$expectedResult = ExcelError::CALC();
$result = Filter::filter([[1], [2], [3]], $criteria);
self::assertSame($expectedResult, $result);
$expectedResult = 'Invalid Data';
$result = Filter::filter([[1], [2], [3]], $criteria, $expectedResult);
self::assertSame($expectedResult, $result);
}
/** @return array<array{string, string, string, int}> */
protected function sampleDataForRow(): array
{
return [
['East', 'Tom', 'Apple', 6830],
['West', 'Fred', 'Grape', 5619],
['North', 'Amy', 'Pear', 4565],
['South', 'Sal', 'Banana', 5323],
['East', 'Fritz', 'Apple', 4394],
['West', 'Sravan', 'Grape', 7195],
['North', 'Xi', 'Pear', 5231],
['South', 'Hector', 'Banana', 2427],
['East', 'Tom', 'Banana', 4213],
['West', 'Fred', 'Pear', 3239],
['North', 'Amy', 'Grape', 6420],
['South', 'Sal', 'Apple', 1310],
['East', 'Fritz', 'Banana', 6274],
['West', 'Sravan', 'Pear', 4894],
['North', 'Xi', 'Grape', 7580],
['South', 'Hector', 'Apple', 8144],
];
}
/** @return array<array<int|string>> */
protected function sampleDataForColumn(): array
{
return [
['Aiden', 'Andrew', 'Betty', 'Caden', 'Charlotte', 'Emma', 'Isabella', 'Mason', 'Oliver', 'Zoe'],
['A', 'C', 'B', 'A', 'B', 'C', 'A', 'A', 'B', 'B'],
[0, 4, 1, 2, 2, 0, 2, 4, 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/LookupRef/TorowTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/TorowTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\Attributes\DataProvider;
class TorowTest extends AllSetupTeardown
{
#[DataProvider('providerTorow')]
public function testTorow(mixed $expectedResult, mixed $ignore = 'omitted', mixed $byColumn = 'omitted'): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$this->setArrayAsArray();
if (is_string($ignore) && $ignore !== 'omitted') {
$ignore = '"' . $ignore . '"';
}
if (is_string($byColumn) && $byColumn !== 'omitted') {
$byColumn = '"' . $byColumn . '"';
}
$ignore = StringHelper::convertToString($ignore);
$byColumn = StringHelper::convertToString($byColumn, convertBool: true);
if ($ignore === 'omitted') {
$formula = '=TOROW(A1:D3)';
} elseif ($byColumn === 'omitted') {
$formula = "=TOROW(A1:D3,$ignore)";
} else {
$formula = "=TOROW(A1:D3,$ignore,$byColumn)";
}
$data = [
['a-one', 'b-one', 'c-one', 'd-one'],
[null, 'b-two', 'c-two', '=2/0'],
[' ', 'b-three', 'c-three', 'd-three'],
];
$sheet->fromArray($data, null, 'A1', true);
$sheet->setCellValue('A5', $formula);
$result = $sheet->getCell('A5')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
public static function providerTorow(): array
{
return [
'defaults' => [['a-one', 'b-one', 'c-one', 'd-one', 0, 'b-two', 'c-two', '#DIV/0!', ' ', 'b-three', 'c-three', 'd-three']],
'ignore=0' => [['a-one', 'b-one', 'c-one', 'd-one', 0, 'b-two', 'c-two', '#DIV/0!', ' ', 'b-three', 'c-three', 'd-three'], 0],
'ignore=1 supplied as 1.1' => [['a-one', 'b-one', 'c-one', 'd-one', 'b-two', 'c-two', '#DIV/0!', ' ', 'b-three', 'c-three', 'd-three'], 1.1],
'ignore=2' => [['a-one', 'b-one', 'c-one', 'd-one', 0, 'b-two', 'c-two', ' ', 'b-three', 'c-three', 'd-three'], 2],
'ignore=3' => [['a-one', 'b-one', 'c-one', 'd-one', 'b-two', 'c-two', ' ', 'b-three', 'c-three', 'd-three'], 3],
'ignore=-1 invalid' => ['#VALUE!', -1],
'ignore=string invalid' => ['#VALUE!', 'x'],
'by column' => [['a-one', 0, ' ', 'b-one', 'b-two', 'b-three', 'c-one', 'c-two', 'c-three', 'd-one', '#DIV/0!', 'd-three'], 0, true],
'by column using int rather than bool, ignore=1' => [['a-one', ' ', 'b-one', 'b-two', 'b-three', 'c-one', 'c-two', 'c-three', 'd-one', '#DIV/0!', 'd-three'], 1, -15],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/MatchTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/MatchTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PHPUnit\Framework\Attributes\DataProvider;
class MatchTest extends AllSetupTeardown
{
/** @param mixed[] $array */
#[DataProvider('providerMATCH')]
public function testMATCH(mixed $expectedResult, mixed $input, array $array, null|float|int|string $type = null): void
{
if (is_array($expectedResult)) {
$expectedResult = $expectedResult[0];
}
if ($expectedResult === 'incomplete') {
self::markTestIncomplete('Undefined behavior with different results in Excel and PhpSpreadsheet');
}
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$maxRow = count($array);
$formulaArray = '';
for ($row = 1; $row <= $maxRow; ++$row) {
$this->setCell("A$row", $array[$row - 1]);
$formulaArray = "A1:A$row";
}
$this->setCell('B1', $input);
if ($type === null) {
$formula = "=MATCH(B1,$formulaArray)";
} else {
$formula = "=MATCH(B1, $formulaArray, $type)";
}
$sheet->getCell('D1')->setValue($formula);
$result = $sheet->getCell('D1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
/** @param mixed[] $array */
#[DataProvider('providerMATCH')]
public function testMATCHLibre(mixed $expectedResult, mixed $input, array $array, null|float|int|string $type = null): void
{
$this->setOpenOffice();
if (is_array($expectedResult)) {
$expectedResult = $expectedResult[1];
}
if ($expectedResult === 'incomplete') {
self::markTestIncomplete('Undefined behavior with different results in Excel and PhpSpreadsheet');
}
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$maxRow = count($array);
$formulaArray = '';
for ($row = 1; $row <= $maxRow; ++$row) {
$this->setCell("A$row", $array[$row - 1]);
$formulaArray = "A1:A$row";
}
$this->setCell('B1', $input);
if ($type === null) {
$formula = "=MATCH(B1,$formulaArray)";
} else {
$formula = "=MATCH(B1, $formulaArray, $type)";
}
$sheet->getCell('D1')->setValue($formula);
$result = $sheet->getCell('D1')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
public static function providerMATCH(): array
{
return require 'tests/data/Calculation/LookupRef/MATCH.php';
}
#[DataProvider('providerMatchArray')]
public function testMatchArray(array $expectedResult, string $values, string $selections): void
{
$calculation = Calculation::getInstance();
$formula = "=MATCH({$values}, {$selections}, 0)";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
public static function providerMatchArray(): array
{
return [
'row vector' => [
[[2, 5, 3]],
'{"Orange", "Blue", "Yellow"}',
'{"Red", "Orange", "Yellow", "Green", "Blue"}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ExpandTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ExpandTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\NamedRange;
use PHPUnit\Framework\Attributes\DataProvider;
class ExpandTest extends AllSetupTeardown
{
#[DataProvider('providerExpand')]
public function testExpand(mixed $expectedResult, string $formula): void
{
Calculation::setArrayReturnType(
Calculation::RETURN_ARRAY_AS_ARRAY
);
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->fromArray(
[
['a', 'b', 'c'],
['d', 'e', 'f'],
],
null,
'B3',
true
);
$this->getSpreadsheet()->addNamedRange(
new NamedRange(
'definedname',
$sheet,
'$B$3:$D$11'
)
);
$sheet->setCellValue('F3', $formula);
$result = $sheet->getCell('F3')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
public static function providerExpand(): array
{
return require 'tests/data/Calculation/LookupRef/EXPAND.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/AddressTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/AddressTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class AddressTest extends TestCase
{
#[DataProvider('providerADDRESS')]
public function testADDRESS(mixed $expectedResult, mixed ...$args): void
{
$result = LookupRef\Address::cell(...$args);
self::assertEquals($expectedResult, $result);
}
public static function providerADDRESS(): array
{
return require 'tests/data/Calculation/LookupRef/ADDRESS.php';
}
#[DataProvider('providerAddressArray')]
public function testAddressArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=ADDRESS({$argument1}, {$argument2}, 4)";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
public static function providerAddressArray(): array
{
return [
'row/column vectors' => [
[['A1', 'B1', 'C1'], ['A2', 'B2', 'C2'], ['A3', 'B3', 'C3']],
'{1; 2; 3}',
'{1, 2, 3}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/IndirectTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/IndirectTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\NamedFormula;
use PhpOffice\PhpSpreadsheet\NamedRange;
use PhpOffice\PhpSpreadsheet\Reader\Xlsx as ReaderXlsx;
use PHPUnit\Framework\Attributes\DataProvider;
class IndirectTest extends AllSetupTeardown
{
#[DataProvider('providerINDIRECT')]
public function testINDIRECT(mixed $expectedResult, mixed $cellReference = 'omitted', mixed $a1 = 'omitted'): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue(100);
$sheet->getCell('A2')->setValue(200);
$sheet->getCell('A3')->setValue(300);
$sheet->getCell('A4')->setValue(400);
$sheet->getCell('A5')->setValue(500);
$sheet->setTitle('ThisSheet');
$sheet1 = $this->getSpreadsheet()->createSheet();
$sheet1->getCell('A1')->setValue(10);
$sheet1->getCell('A2')->setValue(20);
$sheet1->getCell('A3')->setValue(30);
$sheet1->getCell('A4')->setValue(40);
$sheet1->getCell('A5')->setValue(50);
$sheet1->getCell('B1')->setValue(1);
$sheet1->getCell('B2')->setValue(2);
$sheet1->getCell('B3')->setValue(3);
$sheet1->getCell('B4')->setValue(4);
$sheet1->getCell('B5')->setValue(5);
$sheet1->setTitle('OtherSheet');
$this->getSpreadsheet()->addNamedRange(new NamedRange('newnr', $sheet1, '$A$2:$A$4'));
$this->getSpreadsheet()->addNamedRange(new NamedRange('localname', $sheet1, '$B$2:$B$4', true));
$this->setCell('B1', $cellReference);
$this->setCell('B2', $a1);
if ($cellReference === 'omitted') {
$sheet->getCell('B3')->setValue('=SUM(INDIRECT())');
} elseif ($a1 === 'omitted') {
$sheet->getCell('B3')->setValue('=SUM(INDIRECT(B1))');
} else {
$sheet->getCell('B3')->setValue('=SUM(INDIRECT(B1, B2))');
}
$result = $sheet->getCell('B3')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
public static function providerINDIRECT(): array
{
return require 'tests/data/Calculation/LookupRef/INDIRECT.php';
}
public function testINDIRECTEurUsd(): void
{
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('EUR');
$sheet->getCell('A2')->setValue('USD');
$sheet->getCell('B1')->setValue(360);
$sheet->getCell('B2')->setValue(300);
$this->getSpreadsheet()->addNamedRange(new NamedRange('EUR', $sheet, '$B$1'));
$this->getSpreadsheet()->addNamedRange(new NamedRange('USD', $sheet, '$B$2'));
$this->setCell('E1', '=INDIRECT("USD")');
$result = $sheet->getCell('E1')->getCalculatedValue();
self::assertSame(300, $result);
}
public function testINDIRECTLeadingEquals(): void
{
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('EUR');
$sheet->getCell('A2')->setValue('USD');
$sheet->getCell('B1')->setValue(360);
$sheet->getCell('B2')->setValue(300);
$this->getSpreadsheet()->addNamedRange(new NamedRange('EUR', $sheet, '=$B$1'));
$this->getSpreadsheet()->addNamedRange(new NamedRange('USD', $sheet, '=$B$2'));
$this->setCell('E1', '=INDIRECT("USD")');
$result = $sheet->getCell('E1')->getCalculatedValue();
self::assertSame(300, $result);
}
public function testIndirectFile1(): void
{
$reader = new ReaderXlsx();
$file = 'tests/data/Calculation/LookupRef/IndirectDefinedName.xlsx';
$spreadsheet = $reader->load($file);
$sheet = $spreadsheet->getActiveSheet();
$result = $sheet->getCell('A5')->getCalculatedValue();
self::assertSame(80, $result);
$value = $sheet->getCell('A5')->getValue();
self::assertSame('=INDIRECT("CURRENCY_EUR")', $value);
}
public function testIndirectFile2(): void
{
$reader = new ReaderXlsx();
$file = 'tests/data/Calculation/LookupRef/IndirectFormulaSelection.xlsx';
$spreadsheet = $this->spreadsheet = $reader->load($file);
$sheet = $spreadsheet->getActiveSheet();
$result = $sheet->getCell('A5')->getCalculatedValue();
self::assertSame(100, $result);
$value = $sheet->getCell('A5')->getValue();
self::assertSame('=CURRENCY_SELECTOR', $value);
$formula = $spreadsheet->getNamedFormula('CURRENCY_SELECTOR');
if ($formula === null) {
self::fail('Expected named formula was not defined');
} else {
self::assertSame('INDIRECT("CURRENCY_"&Sheet1!$D$1)', $formula->getFormula());
}
}
public function testDeprecatedCall(): void
{
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('A2');
$sheet->getCell('A2')->setValue('This is it');
$result = \PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Indirect::INDIRECT('A2', true, $sheet->getCell('A1'));
$result = \PhpOffice\PhpSpreadsheet\Calculation\Functions::flattenSingleValue($result);
self::assertSame('This is it', $result);
}
#[DataProvider('providerRelative')]
public function testR1C1Relative(string|int|null $expectedResult, string $address): void
{
$this->setArrayAsValue();
$sheet = $this->getSheet();
$sheet->fromArray([
['a1', 'b1', 'c1'],
['a2', 'b2', 'c2'],
['a3', 'b3', 'c3'],
['a4', 'b4', 'c4'],
]);
$sheet->getCell('B2')->setValue('=INDIRECT("' . $address . '", false)');
self::assertSame($expectedResult, $sheet->getCell('B2')->getCalculatedValue());
}
public static function providerRelative(): array
{
return [
'same row with bracket next column' => ['c2', 'R[]C[+1]'],
'same row without bracket next column' => ['c2', 'RC[+1]'],
'same row without bracket next column no plus sign' => ['c2', 'RC[1]'],
'same row previous column' => ['a2', 'RC[-1]'],
'previous row previous column' => ['a1', 'R[-1]C[-1]'],
'previous row same column with bracket' => ['b1', 'R[-1]C[]'],
'previous row same column without bracket' => ['b1', 'R[-1]C'],
'previous row next column' => ['c1', 'R[-1]C[+1]'],
'next row no plus sign previous column' => ['a3', 'R[1]C[-1]'],
'next row previous column' => ['a3', 'R[+1]C[-1]'],
'next row same column' => ['b3', 'R[+1]C'],
'next row next column' => ['c3', 'R[+1]C[+1]'],
'two rows down same column' => ['b4', 'R[+2]C'],
'invalid row' => ['#REF!', 'R[-2]C'],
'invalid column' => ['#REF!', 'RC[-2]'],
'circular reference' => [0, 'RC'], // matches Excel's treatment
'absolute row absolute column' => ['c2', 'R2C3'],
'absolute row relative column' => ['a2', 'R2C[-1]'],
'relative row absolute column lowercase' => ['a2', 'rc1'],
'uninitialized cell' => [0, 'RC[+2]'], // Excel result is 0, PhpSpreadsheet was null
];
}
private static bool $definedFormulaWorking = false;
public function testAboveCell(): void
{
$spreadsheet = $this->getSpreadsheet();
$spreadsheet->addNamedFormula(
new NamedFormula('SumAbove', $spreadsheet->getActiveSheet(), '=SUM(INDIRECT(ADDRESS(1,COLUMN())):INDIRECT(ADDRESS(ROW()-1,COLUMN())))')
);
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue(100);
$sheet->getCell('A2')->setValue(200);
$sheet->getCell('A3')->setValue(300);
$sheet->getCell('A4')->setValue(400);
$sheet->getCell('A5')->setValue(500);
$sheet->getCell('A6')->setValue('=SUM(A$1:INDIRECT(ADDRESS(ROW()-1,COLUMN())))');
self::AssertSame(1500, $sheet->getCell('A6')->getCalculatedValue());
if (self::$definedFormulaWorking) {
$sheet->getCell('B1')->setValue(10);
$sheet->getCell('B2')->setValue(20);
$sheet->getCell('B3')->setValue(30);
$sheet->getCell('B4')->setValue(40);
$sheet->getCell('B5')->setValue('=SumAbove');
self::AssertSame(100, $sheet->getCell('B5')->getCalculatedValue());
} else {
self::markTestIncomplete('PhpSpreadsheet does not handle this correctly');
}
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/TransposeOnSpreadsheetTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/TransposeOnSpreadsheetTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\Attributes\DataProvider;
class TransposeOnSpreadsheetTest extends AllSetupTeardown
{
#[DataProvider('providerTRANSPOSE')]
public function testTRANSPOSE(mixed $expectedResult, mixed $matrix): void
{
$sheet = $this->getSheet();
$this->setArrayAsArray();
if (!is_array($matrix)) {
$matrix = [$matrix];
}
$sheet->fromArray($matrix, null, 'A1', true);
$highColumn = $sheet->getHighestDataColumn();
$highRow = $sheet->getHighestDataRow();
$newHighColumn = $highColumn;
StringHelper::stringIncrement($newHighColumn);
$sheet->getCell("{$newHighColumn}1")
->setValue("=TRANSPOSE(A1:$highColumn$highRow)");
self::assertSame($expectedResult, $sheet->getCell("{$newHighColumn}1")->getCalculatedValue());
}
public static function providerTRANSPOSE(): array
{
return require 'tests/data/Calculation/LookupRef/TRANSPOSE.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/RowsTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/RowsTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class RowsTest extends TestCase
{
/** @param null|mixed[]|string $arg */
#[DataProvider('providerROWS')]
public function testROWS(mixed $expectedResult, null|array|string $arg): void
{
$result = LookupRef\RowColumnInformation::ROWS($arg);
self::assertEquals($expectedResult, $result);
}
public static function providerROWS(): array
{
return require 'tests/data/Calculation/LookupRef/ROWS.php';
}
#[DataProvider('providerRowsArray')]
public function testRowsArray(int $expectedResult, string $argument): void
{
$calculation = Calculation::getInstance();
$formula = "=ROWS({$argument})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
public static function providerRowsArray(): array
{
return [
[
2,
'{1,2,3;4,5,6}',
],
[
1,
'{1,2,3,4,5}',
],
[
5,
'{1;2;3;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/LookupRef/ColumnOnSpreadsheetTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ColumnOnSpreadsheetTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\NamedRange;
use PHPUnit\Framework\Attributes\DataProvider;
class ColumnOnSpreadsheetTest extends AllSetupTeardown
{
#[DataProvider('providerCOLUMNonSpreadsheet')]
public function testColumnOnSpreadsheet(mixed $expectedResult, string $cellReference = 'omitted'): void
{
$this->mightHaveException($expectedResult);
$this->setArrayAsValue();
$sheet = $this->getSheet();
$this->getSpreadsheet()->addNamedRange(new NamedRange('namedrangex', $sheet, '$E$2:$E$6'));
$this->getSpreadsheet()->addNamedRange(new NamedRange('namedrangey', $sheet, '$F$2:$H$2'));
$this->getSpreadsheet()->addNamedRange(new NamedRange('namedrange3', $sheet, '$F$4:$H$4'));
$sheet1 = $this->getSpreadsheet()->createSheet();
$sheet1->setTitle('OtherSheet');
$this->getSpreadsheet()->addNamedRange(new NamedRange('localname', $sheet1, '$F$6:$H$6', true));
if ($cellReference === 'omitted') {
$sheet->getCell('B3')->setValue('=COLUMN()');
} else {
$sheet->getCell('B3')->setValue("=COLUMN($cellReference)");
}
$result = $sheet->getCell('B3')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
public static function providerCOLUMNonSpreadsheet(): array
{
return require 'tests/data/Calculation/LookupRef/COLUMNonSpreadsheet.php';
}
public function testCOLUMNLocalDefinedName(): void
{
$this->setArrayAsValue();
$sheet = $this->getSheet();
$sheet1 = $this->getSpreadsheet()->createSheet();
$sheet1->setTitle('OtherSheet');
$this->getSpreadsheet()->addNamedRange(new NamedRange('newnr', $sheet1, '$F$5:$H$5', true)); // defined locally, only usable on sheet1
$sheet1->getCell('B3')->setValue('=COLUMN(newnr)');
$result = $sheet1->getCell('B3')->getCalculatedValue();
self::assertSame(6, $result);
$sheet->getCell('B3')->setValue('=COLUMN(newnr)');
$result = $sheet->getCell('B3')->getCalculatedValue();
self::assertSame('#NAME?', $result);
}
public function testCOLUMNSheetWithApostrophe(): void
{
$this->setArrayAsValue();
$sheet = $this->getSheet();
$sheet1 = $this->getSpreadsheet()->createSheet();
$sheet1->setTitle("apo'strophe");
$this->getSpreadsheet()->addNamedRange(new NamedRange('newnr', $sheet1, '$F$5:$H$5', true)); // defined locally, only usable on sheet1
$sheet1->getCell('B3')->setValue('=COLUMN(newnr)');
$result = $sheet1->getCell('B3')->getCalculatedValue();
self::assertSame(6, $result);
$sheet->getCell('B3')->setValue('=COLUMN(newnr)');
$result = $sheet->getCell('B3')->getCalculatedValue();
self::assertSame('#NAME?', $result);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/IndirectMissingCellTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/IndirectMissingCellTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
class IndirectMissingCellTest extends AllSetupTeardown
{
public function testIssue4330(): void
{
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue(5); // used in INDIRECT
$sheet->getCell('A2')->setValue(1);
$sheet->getCell('B1')->setValue(2);
$sheet->getCell('B2')->setValue(4);
$sheet->getCell('B3')->setValue(6);
$sheet->getCell('B4')->setValue(8);
$sheet->getCell('B5')->setValue(10);
$sheet->getCell('B6')->setValue(12);
$sheet->getCell('C1')->setValue('=SUM(B1:INDIRECT("B"&A1))');
self::assertSame(
30,
$sheet->getCell('C1')->getCalculatedValue(),
'end cell initialized'
);
$sheet->getCell('D1')->setValue(30);
$sheet->getCell('D2')->setValue(60);
$sheet->getCell('D3')->setValue(90);
$sheet->getCell('D4')->setValue(120);
$sheet->getCell('E1')->setValue('=SUM(D1:INDIRECT("D"&A1))');
self::assertSame(
300,
$sheet->getCell('E1')->getCalculatedValue(),
'end cell not initialized'
);
//$sheet->getCell('F1')->setValue(30);
//$sheet->getCell('F2')->setValue(60);
$sheet->getCell('F3')->setValue(90);
$sheet->getCell('F4')->setValue(120);
$sheet->getCell('G1')->setValue(
'=SUM(INDIRECT("F"&A2&":F"&A1))'
);
self::assertSame(
210,
$sheet->getCell('G1')->getCalculatedValue(),
'range with uninitialized cells as INDIRECT argument'
);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/RowOnSpreadsheetTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/RowOnSpreadsheetTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\NamedRange;
use PHPUnit\Framework\Attributes\DataProvider;
class RowOnSpreadsheetTest extends AllSetupTeardown
{
#[DataProvider('providerROWonSpreadsheet')]
public function testRowOnSpreadsheet(mixed $expectedResult, string $cellReference = 'omitted'): void
{
$this->mightHaveException($expectedResult);
$this->setArrayAsValue();
$sheet = $this->getSheet();
$sheet->setTitle('ThisSheet');
$this->getSpreadsheet()->addNamedRange(new NamedRange('namedrangex', $sheet, '$E$2:$E$6'));
$this->getSpreadsheet()->addNamedRange(new NamedRange('namedrangey', $sheet, '$F$2:$H$2'));
$this->getSpreadsheet()->addNamedRange(new NamedRange('namedrange3', $sheet, '$F$4:$H$4'));
$this->getSpreadsheet()->addNamedRange(new NamedRange('namedrange5', $sheet, '$F$5:$H$5', true));
$sheet1 = $this->getSpreadsheet()->createSheet();
$sheet1->setTitle('OtherSheet');
$this->getSpreadsheet()->addNamedRange(new NamedRange('localname', $sheet1, '$F$6:$H$6', true));
if ($cellReference === 'omitted') {
$sheet->getCell('B3')->setValue('=ROW()');
} else {
$sheet->getCell('B3')->setValue("=ROW($cellReference)");
}
$result = $sheet->getCell('B3')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
public static function providerROWOnSpreadsheet(): array
{
return require 'tests/data/Calculation/LookupRef/ROWonSpreadsheet.php';
}
public function testINDIRECTLocalDefinedName(): void
{
$sheet = $this->getSheet();
$this->setArrayAsValue();
$sheet1 = $this->getSpreadsheet()->createSheet();
$sheet1->setTitle('OtherSheet');
$this->getSpreadsheet()->addNamedRange(new NamedRange('newnr', $sheet1, '$F$5:$H$5', true)); // defined locally, only usable on sheet1
$sheet1->getCell('B3')->setValue('=ROW(newnr)');
$result = $sheet1->getCell('B3')->getCalculatedValue();
self::assertSame(5, $result);
$sheet->getCell('B3')->setValue('=ROW(newnr)');
$result = $sheet->getCell('B3')->getCalculatedValue();
self::assertSame('#NAME?', $result);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/IndexTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/IndexTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Matrix;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class IndexTest extends TestCase
{
#[DataProvider('providerINDEX')]
public function testINDEX(mixed $expectedResult, mixed $matrix, mixed $rowNum = null, mixed $colNum = null): void
{
if ($rowNum === null) {
$result = Matrix::index($matrix);
} elseif ($colNum === null) {
$result = Matrix::index($matrix, $rowNum);
} else {
$result = Matrix::index($matrix, $rowNum, $colNum);
}
self::assertEquals($expectedResult, $result);
}
public static function providerINDEX(): array
{
return require 'tests/data/Calculation/LookupRef/INDEX.php';
}
#[DataProvider('providerIndexArray')]
public function testIndexArray(array $expectedResult, string $matrix, string $rows, string $columns): void
{
$calculation = Calculation::getInstance();
$formula = "=INDEX({$matrix}, {$rows}, {$columns})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
public static function providerIndexArray(): array
{
return [
'row/column vectors' => [
[[2, 3], [5, 6]],
'{1, 2, 3; 4, 5, 6; 7, 8, 9}',
'{1; 2}',
'{2, 3}',
],
'return row' => [
[1 => [4, 5, 6]],
'{1, 2, 3; 4, 5, 6; 7, 8, 9}',
'2',
'0',
],
'return column' => [
[[2], [5], [8]],
'{1, 2, 3; 4, 5, 6; 7, 8, 9}',
'0',
'2',
],
];
}
public function testPropagateDiv0(): void
{
// issue 3396 error was always being treated as #VALUE!
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue(0);
$sheet->getCell('A3')->setValue(1);
$sheet->getCell('B3')->setValue(1);
$sheet->getCell('C3')->setValue('=1/A1');
$sheet->getCell('D3')->setValue('=1/A1');
$sheet->getCell('E3')->setValue('xyz');
$sheet->getCell('A4')->setValue(false);
$sheet->getCell('B4')->setValue(true);
$sheet->getCell('C4')->setValue(true);
$sheet->getCell('D4')->setValue(false);
$sheet->getCell('E4')->setValue(false);
$sheet->getCell('A6')->setValue('=INDEX(A3:E3/A4:E4,1,1)');
$sheet->getCell('B6')->setValue('=INDEX(A3:E3/A4:E4,1,2)');
$sheet->getCell('C6')->setValue('=INDEX(A3:E3/A4:E4,1,3)');
$sheet->getCell('D6')->setValue('=INDEX(A3:E3/A4:E4,1,4)');
$sheet->getCell('E6')->setValue('=INDEX(A3:E3/A4:E4,1,5)');
self::assertSame('#DIV/0!', $sheet->getCell('A6')->getCalculatedValue());
self::assertSame(1, $sheet->getCell('B6')->getCalculatedValue());
self::assertSame('#DIV/0!', $sheet->getCell('C6')->getCalculatedValue());
self::assertSame('#DIV/0!', $sheet->getCell('D6')->getCalculatedValue());
self::assertSame('#VALUE!', $sheet->getCell('E6')->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/LookupRef/TocolTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/TocolTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\Attributes\DataProvider;
class TocolTest extends AllSetupTeardown
{
#[DataProvider('providerTocol')]
public function testTorow(mixed $expectedResult, mixed $ignore = 'omitted', mixed $byColumn = 'omitted'): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$this->setArrayAsArray();
if (is_string($ignore) && $ignore !== 'omitted') {
$ignore = '"' . $ignore . '"';
}
if (is_string($byColumn) && $byColumn !== 'omitted') {
$byColumn = '"' . $byColumn . '"';
}
$ignore = StringHelper::convertToString($ignore);
$byColumn = StringHelper::convertToString($byColumn, convertBool: true);
if ($ignore === 'omitted') {
$formula = '=TOCOL(A1:D3)';
} elseif ($byColumn === 'omitted') {
$formula = "=TOCOL(A1:D3,$ignore)";
} else {
$formula = "=TOCOL(A1:D3,$ignore,$byColumn)";
}
$data = [
['a-one', 'b-one', 'c-one', 'd-one'],
[null, 'b-two', 'c-two', '=2/0'],
[' ', 'b-three', 'c-three', 'd-three'],
];
$sheet->fromArray($data, null, 'A1', true);
$sheet->setCellValue('A5', $formula);
$result = $sheet->getCell('A5')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
public static function providerTocol(): array
{
return [
'defaults' => [[['a-one'], ['b-one'], ['c-one'], ['d-one'], [0], ['b-two'], ['c-two'], ['#DIV/0!'], [' '], ['b-three'], ['c-three'], ['d-three']]],
'ignore=0' => [[['a-one'], ['b-one'], ['c-one'], ['d-one'], [0], ['b-two'], ['c-two'], ['#DIV/0!'], [' '], ['b-three'], ['c-three'], ['d-three']], 0],
'ignore=1 supplied as 1.1' => [[['a-one'], ['b-one'], ['c-one'], ['d-one'], ['b-two'], ['c-two'], ['#DIV/0!'], [' '], ['b-three'], ['c-three'], ['d-three']], 1.1],
'ignore=2' => [[['a-one'], ['b-one'], ['c-one'], ['d-one'], [0], ['b-two'], ['c-two'], [' '], ['b-three'], ['c-three'], ['d-three']], 2],
'ignore=3' => [[['a-one'], ['b-one'], ['c-one'], ['d-one'], ['b-two'], ['c-two'], [' '], ['b-three'], ['c-three'], ['d-three']], 3],
'ignore=4 invalid' => ['#VALUE!', 4],
'ignore=string invalid' => ['#VALUE!', 'x'],
'by column' => [[['a-one'], [0], [' '], ['b-one'], ['b-two'], ['b-three'], ['c-one'], ['c-two'], ['c-three'], ['d-one'], ['#DIV/0!'], ['d-three']], 0, true],
'by column using float rather than bool, ignore=2' => [[['a-one'], [0], [' '], ['b-one'], ['b-two'], ['b-three'], ['c-one'], ['c-two'], ['c-three'], ['d-one'], ['d-three']], 2, 29.7],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/TransposeTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/TransposeTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PHPUnit\Framework\TestCase;
class TransposeTest extends TestCase
{
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerTRANSPOSE')]
public function testTRANSPOSE(mixed $expectedResult, mixed $matrix): void
{
$result = LookupRef\Matrix::transpose($matrix);
self::assertEquals($expectedResult, $result);
}
public static function providerTRANSPOSE(): array
{
return require 'tests/data/Calculation/LookupRef/TRANSPOSE.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ChooseRowsTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ChooseRowsTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\NamedRange;
use PHPUnit\Framework\Attributes\DataProvider;
class ChooseRowsTest extends AllSetupTeardown
{
#[DataProvider('providerChooseRows')]
public function testChooseRows(mixed $expectedResult, string $formula): void
{
Calculation::setArrayReturnType(
Calculation::RETURN_ARRAY_AS_ARRAY
);
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->fromArray(
[
['a', 'b', 'c'],
['d', 'e', 'f'],
['g', 'h', 'i'],
['j', 'k', 'l'],
['m', 'n', 'o'],
['p', 'q', 'r'],
['s', 't', 'u'],
['v', 'w', 'x'],
['y', 'z', '#'],
],
null,
'B3',
true
);
$this->getSpreadsheet()->addNamedRange(
new NamedRange(
'definedname',
$sheet,
'$B$3:$D$11'
)
);
$sheet->setCellValue('F3', $formula);
$result = $sheet->getCell('F3')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
public static function providerChooseRows(): array
{
return require 'tests/data/Calculation/LookupRef/CHOOSEROWS.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/FilterOnSpreadsheetTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/FilterOnSpreadsheetTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;
class FilterOnSpreadsheetTest extends TestCase
{
public function testFilterByRow(): void
{
$spreadsheet = new Spreadsheet();
Calculation::getInstance($spreadsheet)
->setInstanceArrayReturnType(
Calculation::RETURN_ARRAY_AS_ARRAY
);
$sheet = $spreadsheet->getActiveSheet();
$criteria = [[true], [false], [false], [false], [true], [false], [false], [false], [false], [false], [false], [true], [false], [false], [false], [true]];
$sheet->fromArray($criteria, null, 'A1', true);
$sheet->fromArray($this->sampleDataForRow(), null, 'C1', true);
$sheet->getCell('H1')->setValue('=FILTER(C1:F16, A1:A16)');
$expectedResult = [
['East', 'Tom', 'Apple', 6830],
['East', 'Fritz', 'Apple', 4394],
['South', 'Sal', 'Apple', 1310],
['South', 'Hector', 'Apple', 8144],
];
$result = $sheet->getCell('H1')->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public function testFilterByColumn(): void
{
$spreadsheet = new Spreadsheet();
Calculation::getInstance($spreadsheet)
->setInstanceArrayReturnType(
Calculation::RETURN_ARRAY_AS_ARRAY
);
$sheet = $spreadsheet->getActiveSheet();
$criteria = [[false, false, true, false, true, false, false, false, true, true]];
$sheet->fromArray($criteria, null, 'A1', true);
$sheet->fromArray($this->sampleDataForColumn(), null, 'A3', true);
$sheet->getCell('A8')->setValue('=FILTER(A3:J5, A1:J1)');
$expectedResult = [
['Betty', 'Charlotte', 'Oliver', 'Zoe'],
['B', 'B', 'B', 'B'],
[1, 2, 4, 8],
];
$result = $sheet->getCell('A8')->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public function testFilterInvalidMatchArray(): void
{
$spreadsheet = new Spreadsheet();
Calculation::getInstance($spreadsheet)
->setInstanceArrayReturnType(
Calculation::RETURN_ARRAY_AS_ARRAY
);
$sheet = $spreadsheet->getActiveSheet();
$sheet->fromArray($this->sampleDataForColumn(), null, 'A3', true);
$sheet->getCell('A12')->setValue('=FILTER(A3:J5, "INVALID")');
$expectedResult = ExcelError::VALUE();
$result = $sheet->getCell('A12')->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public function testFilterInvalidLookupArray(): void
{
$spreadsheet = new Spreadsheet();
Calculation::getInstance($spreadsheet)
->setInstanceArrayReturnType(
Calculation::RETURN_ARRAY_AS_ARRAY
);
$sheet = $spreadsheet->getActiveSheet();
$criteria = [[false, false, true, false, true, false, false, false, true, true]];
$sheet->fromArray($criteria, null, 'A1', true);
$sheet->fromArray($this->sampleDataForColumn(), null, 'A3', true);
$sheet->getCell('A14')->setValue('=FILTER("invalid", A1:J1)');
$expectedResult = ExcelError::VALUE();
$result = $sheet->getCell('A14')->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
public function testFilterEmpty(): void
{
$spreadsheet = new Spreadsheet();
Calculation::getInstance($spreadsheet)
->setInstanceArrayReturnType(
Calculation::RETURN_ARRAY_AS_ARRAY
);
$sheet = $spreadsheet->getActiveSheet();
$criteria = [[false, false, true, false, true, false, false, false, true, true]];
$sheet->fromArray($criteria, null, 'A1', true);
$sheet->fromArray($this->sampleDataForColumn(), null, 'A3', true);
$sheet->getCell('A16')->setValue('=FILTER(A3:B5, A1:B1)');
$expectedResult = ExcelError::CALC();
$result = $sheet->getCell('A16')->getCalculatedValue();
self::assertSame($expectedResult, $result);
$spreadsheet->disconnectWorksheets();
}
/** @return array<array{string, string, string, int}> */
protected function sampleDataForRow(): array
{
return [
['East', 'Tom', 'Apple', 6830],
['West', 'Fred', 'Grape', 5619],
['North', 'Amy', 'Pear', 4565],
['South', 'Sal', 'Banana', 5323],
['East', 'Fritz', 'Apple', 4394],
['West', 'Sravan', 'Grape', 7195],
['North', 'Xi', 'Pear', 5231],
['South', 'Hector', 'Banana', 2427],
['East', 'Tom', 'Banana', 4213],
['West', 'Fred', 'Pear', 3239],
['North', 'Amy', 'Grape', 6420],
['South', 'Sal', 'Apple', 1310],
['East', 'Fritz', 'Banana', 6274],
['West', 'Sravan', 'Pear', 4894],
['North', 'Xi', 'Grape', 7580],
['South', 'Hector', 'Apple', 8144],
];
}
/** @return array<array<int|string>> */
protected function sampleDataForColumn(): array
{
return [
['Aiden', 'Andrew', 'Betty', 'Caden', 'Charlotte', 'Emma', 'Isabella', 'Mason', 'Oliver', 'Zoe'],
['A', 'C', 'B', 'A', 'B', 'C', 'A', 'A', 'B', 'B'],
[0, 4, 1, 2, 2, 0, 2, 4, 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/LookupRef/HStackTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/HStackTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
/**
* Many of these tests are derived from
* https://exceljet.net/functions/hstack-function.
*/
class HStackTest extends AllSetupTeardown
{
public static function testHstack1(): void
{
$spreadsheet = new Spreadsheet();
Calculation::getInstance($spreadsheet)
->setInstanceArrayReturnType(
Calculation::RETURN_ARRAY_AS_ARRAY
);
$sheet = $spreadsheet->getActiveSheet();
$b4tof14 = [
['A', null, 'B', null, 'C'],
[12, null, 7, null, 12],
[9, null, 13, null, 10],
[10, null, 5, null, 11],
[11, null, 13, null, 6],
[8, null, 12, null, 7],
[12, null, 11, null, 15],
[9, null, 10, null, 6],
[10, null, 15, null, 5],
[11, null, 9, null, 14],
[6, null, 13, null, 11],
];
$sheet->fromArray($b4tof14, null, 'B4', true);
$sheet->setCellValue('H4', '=HSTACK(B4:B14,D4:D14,F4:F14)');
$expected = [
['A', 'B', 'C'],
[12, 7, 12],
[9, 13, 10],
[10, 5, 11],
[11, 13, 6],
[8, 12, 7],
[12, 11, 15],
[9, 10, 6],
[10, 15, 5],
[11, 9, 14],
[6, 13, 11],
];
self::assertSame($expected, $sheet->getCell('H4')->getCalculatedValue());
$sheet->setCellValue('K4', '=HSTACK(B4:B14,D4:D12,F4:F14)');
$expected = [
['A', 'B', 'C'],
[12, 7, 12],
[9, 13, 10],
[10, 5, 11],
[11, 13, 6],
[8, 12, 7],
[12, 11, 15],
[9, 10, 6],
[10, 15, 5],
[11, '#N/A', 14],
[6, '#N/A', 11],
];
self::assertSame($expected, $sheet->getCell('K4')->getCalculatedValue(), 'one short column');
$sheet->setCellValue('R4', '=IFERROR(HSTACK(B4:B14,D4:D12,F4:F14),"")');
$expected = [
['A', 'B', 'C'],
[12, 7, 12],
[9, 13, 10],
[10, 5, 11],
[11, 13, 6],
[8, 12, 7],
[12, 11, 15],
[9, 10, 6],
[10, 15, 5],
[11, '', 14],
[6, '', 11],
];
self::assertSame($expected, $sheet->getCell('R4')->getCalculatedValue(), 'one short column with null string instead of N/A');
$sheet->setCellValue('N4', '=HSTACK(B5,H6:J6)');
$expected = [
[12, 9, 13, 10],
];
self::assertSame($expected, $sheet->getCell('N4')->getCalculatedValue(), 'one single-cell arg');
$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/LookupRef/SortByTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/SortByTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Sort;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class SortByTest extends TestCase
{
public function testSortOnScalar(): void
{
$value = 'NON-ARRAY';
$result = Sort::sortBy($value, [[$value]]);
self::assertSame([[$value]], $result);
}
#[DataProvider('providerSortWithScalarArgumentErrorReturns')]
public function testSortByWithArgumentErrorReturns(mixed $sortIndex, mixed $sortOrder = 1): void
{
$value = [[1, 2], [3, 4], [5, 6]];
$result = Sort::sortBy($value, $sortIndex, $sortOrder);
self::assertSame(ExcelError::VALUE(), $result);
}
public static function providerSortWithScalarArgumentErrorReturns(): array
{
return [
'Non-array sortIndex' => ['A', 1],
'Mismatched sortIndex count' => [[1, 2, 3, 4], 1],
'Non-numeric sortOrder' => [[1, 2, 3], 'A'],
'Invalid negative sortOrder' => [[1, 2, 3], -2],
'Zero sortOrder' => [[1, 2, 3], 0],
'Invalid positive sortOrder' => [[1, 2, 3], 2],
];
}
/** @param mixed[] $matrix */
#[DataProvider('providerSortByRow')]
public function testSortByRow(array $expectedResult, array $matrix, mixed ...$args): void
{
$result = Sort::sortBy($matrix, ...$args);
self::assertSame($expectedResult, $result);
}
public static function providerSortByRow(): array
{
return [
'Simple sort by age' => [
[
['Fritz', 19],
['Xi', 19],
['Amy', 22],
['Srivan', 39],
['Tom', 52],
['Fred', 65],
['Hector', 66],
['Sal', 73],
],
self::sampleDataForSimpleSort(),
array_column(self::sampleDataForSimpleSort(), 1),
],
'Simple sort by name' => [
[
['Amy', 22],
['Fred', 65],
['Fritz', 19],
['Hector', 66],
['Sal', 73],
['Srivan', 39],
['Tom', 52],
['Xi', 19],
],
self::sampleDataForSimpleSort(),
array_column(self::sampleDataForSimpleSort(), 0),
],
'Row vector' => [
[
['Amy', 22],
['Fred', 65],
['Fritz', 19],
['Hector', 66],
['Sal', 73],
['Srivan', 39],
['Tom', 52],
['Xi', 19],
],
self::sampleDataForSimpleSort(),
['Tom', 'Fred', 'Amy', 'Sal', 'Fritz', 'Srivan', 'Xi', 'Hector'],
],
'Column vector' => [
[
['Amy', 22],
['Fred', 65],
['Fritz', 19],
['Hector', 66],
['Sal', 73],
['Srivan', 39],
['Tom', 52],
['Xi', 19],
],
self::sampleDataForSimpleSort(),
[['Tom'], ['Fred'], ['Amy'], ['Sal'], ['Fritz'], ['Srivan'], ['Xi'], ['Hector']],
],
'Sort by region asc, name asc' => [
[
['East', 'Fritz', 19],
['East', 'Tom', 52],
['North', 'Amy', 22],
['North', 'Xi', 19],
['South', 'Hector', 66],
['South', 'Sal', 73],
['West', 'Fred', 65],
['West', 'Srivan', 39],
],
self::sampleDataForMultiSort(),
array_column(self::sampleDataForMultiSort(), 0),
Sort::ORDER_ASCENDING,
array_column(self::sampleDataForMultiSort(), 1),
],
'Sort by region asc, age desc' => [
[
['East', 'Tom', 52],
['East', 'Fritz', 19],
['North', 'Amy', 22],
['North', 'Xi', 19],
['South', 'Sal', 73],
['South', 'Hector', 66],
['West', 'Fred', 65],
['West', 'Srivan', 39],
],
self::sampleDataForMultiSort(),
array_column(self::sampleDataForMultiSort(), 0),
Sort::ORDER_ASCENDING,
array_column(self::sampleDataForMultiSort(), 2),
Sort::ORDER_DESCENDING,
],
];
}
/** @return array<array{string, int}> */
private static function sampleDataForSimpleSort(): array
{
return [
['Tom', 52],
['Fred', 65],
['Amy', 22],
['Sal', 73],
['Fritz', 19],
['Srivan', 39],
['Xi', 19],
['Hector', 66],
];
}
/** @return array<array{string, string, int}> */
private static function sampleDataForMultiSort(): array
{
return [
['North', 'Amy', 22],
['West', 'Fred', 65],
['East', 'Fritz', 19],
['South', 'Hector', 66],
['South', 'Sal', 73],
['West', 'Srivan', 39],
['East', 'Tom', 52],
['North', 'Xi', 19],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ColumnsOnSpreadsheetTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/ColumnsOnSpreadsheetTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\NamedRange;
class ColumnsOnSpreadsheetTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCOLUMNSonSpreadsheet')]
public function testColumnsOnSpreadsheet(mixed $expectedResult, string $cellReference = 'omitted'): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$sheet->setTitle('ThisSheet');
$this->getSpreadsheet()->addNamedRange(new NamedRange('namedrangex', $sheet, '$E$2:$E$6'));
$this->getSpreadsheet()->addNamedRange(new NamedRange('namedrangey', $sheet, '$F$2:$H$2'));
$this->getSpreadsheet()->addNamedRange(new NamedRange('namedrange3', $sheet, '$F$4:$H$4'));
$this->getSpreadsheet()->addNamedRange(new NamedRange('namedrange5', $sheet, '$F$5:$I$5', true));
$sheet1 = $this->getSpreadsheet()->createSheet();
$sheet1->setTitle('OtherSheet');
$this->getSpreadsheet()->addNamedRange(new NamedRange('localname', $sheet1, '$F$6:$H$6', true));
if ($cellReference === 'omitted') {
$sheet->getCell('B3')->setValue('=COLUMNS()');
} else {
$sheet->getCell('B3')->setValue("=COLUMNS($cellReference)");
}
$result = $sheet->getCell('B3')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
public static function providerCOLUMNSonSpreadsheet(): array
{
return require 'tests/data/Calculation/LookupRef/COLUMNSonSpreadsheet.php';
}
public function testCOLUMNSLocalDefinedName(): void
{
$sheet = $this->getSheet();
$sheet1 = $this->getSpreadsheet()->createSheet();
$sheet1->setTitle('OtherSheet');
$this->getSpreadsheet()->addNamedRange(new NamedRange('newnr', $sheet1, '$F$5:$H$5', true)); // defined locally, only usable on sheet1
$sheet1->getCell('B3')->setValue('=COLUMNS(newnr)');
$result = $sheet1->getCell('B3')->getCalculatedValue();
self::assertSame(3, $result);
$sheet->getCell('B3')->setValue('=COLUMNS(newnr)');
$result = $sheet->getCell('B3')->getCalculatedValue();
self::assertSame('#NAME?', $result);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/AddressInternationalTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/AddressInternationalTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Settings;
class AddressInternationalTest extends AllSetupTeardown
{
private string $locale;
protected function setUp(): void
{
parent::setUp();
$this->locale = Settings::getLocale();
}
protected function tearDown(): void
{
Settings::setLocale($this->locale);
// CompatibilityMode is restored in parent
parent::tearDown();
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerInternational')]
public function testR1C1International(string $locale, string $r, string $c): void
{
if ($locale !== '') {
Settings::setLocale($locale);
}
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=LEFT(ADDRESS(1,1,1,0),1)');
$sheet->getCell('A2')->setValue('=MID(ADDRESS(1,1,1,0),3,1)');
self::assertSame($r, $sheet->getCell('A1')->getCalculatedValue());
self::assertSame($c, $sheet->getCell('A2')->getCalculatedValue());
}
public static function providerInternational(): array
{
return [
'Default' => ['', 'R', 'C'],
'English' => ['en', 'R', 'C'],
'French' => ['fr', 'L', 'C'],
'German' => ['de', 'Z', 'S'],
'Made-up' => ['xx', 'R', 'C'],
'Spanish' => ['es', 'F', 'C'],
'Bulgarian' => ['bg', 'R', 'C'],
'Czech' => ['cs', 'R', 'C'], // maybe should be R/S
'Polish' => ['pl', 'R', 'C'], // maybe should be W/K
'Turkish' => ['tr', 'R', 'C'],
];
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerCompatibility')]
public function testCompatibilityInternational(string $compatibilityMode, string $r, string $c): void
{
Functions::setCompatibilityMode($compatibilityMode);
Settings::setLocale('de');
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue('=LEFT(ADDRESS(1,1,1,0),1)');
$sheet->getCell('A2')->setValue('=MID(ADDRESS(1,1,1,0),3,1)');
self::assertSame($r, $sheet->getCell('A1')->getCalculatedValue());
self::assertSame($c, $sheet->getCell('A2')->getCalculatedValue());
}
public static function providerCompatibility(): array
{
return [
[Functions::COMPATIBILITY_EXCEL, 'Z', 'S'],
[Functions::COMPATIBILITY_OPENOFFICE, 'R', 'C'],
[Functions::COMPATIBILITY_GNUMERIC, 'R', 'C'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/RowTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/RowTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PHPUnit\Framework\Attributes\DataProvider;
class RowTest extends AllSetupTeardown
{
/** @param null|mixed[][]|string $cellReference */
#[DataProvider('providerROW')]
public function testROW(mixed $expectedResult, null|array|string $cellReference = null): void
{
$result = LookupRef\RowColumnInformation::ROW($cellReference);
self::assertSame($expectedResult, $result);
}
public static function providerROW(): array
{
return require 'tests/data/Calculation/LookupRef/ROW.php';
}
public function testROWwithNull(): void
{
$sheet = $this->getSheet();
$sheet->getCell('C4')->setValue('=ROW()');
self::assertSame(4, $sheet->getCell('C4')->getCalculatedValue());
$sheet->getCell('D2')->setValue('=ROW(C13)');
self::assertSame(13, $sheet->getCell('D2')->getCalculatedValue());
// Sheetnames don't have to exist
$sheet->getCell('D3')->setValue('=ROW(Sheet17!E15)');
self::assertSame(15, $sheet->getCell('D3')->getCalculatedValue());
$sheet->getCell('D4')->setValue("=ROW('Worksheet #5'!X500)");
self::assertSame(500, $sheet->getCell('D4')->getCalculatedValue());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/SortByBetterTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/SortByBetterTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Sort;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class SortByBetterTest extends TestCase
{
private Spreadsheet $spreadsheet;
private int $maxRow;
private string $maxCol;
private string $range;
protected function tearDown(): void
{
$this->spreadsheet->disconnectWorksheets();
unset($this->spreadsheet);
}
/** @param mixed[] $values */
public function getSheet(array $values): Worksheet
{
$this->spreadsheet = new Spreadsheet();
$this->spreadsheet->returnArrayAsArray();
$sheet = $this->spreadsheet->getActiveSheet();
$sheet->fromArray($values);
$this->maxRow = $sheet->getHighestDataRow();
$this->maxCol = $sheet->getHighestDataColumn();
$this->range = "A1:{$this->maxCol}{$this->maxRow}";
return $sheet;
}
public function testSortOnScalar(): void
{
$value = 'NON-ARRAY';
$byArray = 'ARRAY';
$sheet = $this->getSheet([$value, $byArray]);
$sheet->getCell('Z1')->setValue('=SORTBY(A1, B1:B1, 1)');
$sheet->getCell('Z2')->setValue('=SORTBY(A1, B1, 1)');
$sheet->getCell('Z3')->setValue('=SORTBY(A1, B1, "A")');
$result = $sheet->getCell('Z1')->getCalculatedValue();
self::assertSame([[$value]], $result);
$result = $sheet->getCell('Z2')->getCalculatedValue();
self::assertSame([[$value]], $result);
$result = $sheet->getCell('Z3')->getCalculatedValue();
self::assertSame(ExcelError::VALUE(), $result);
}
#[DataProvider('providerSortWithScalarArgumentErrorReturns')]
public function testSortByWithArgumentErrorReturns(string $byArray, int|string $sortOrder = 1): void
{
$value = [[1, 2], [3, 4], [5, 6]];
$sheet = $this->getSheet($value);
$formula = "=SORTBY({$this->range}, $byArray, $sortOrder)";
$sheet->getCell('Z1')->setValue($formula);
$result = $sheet->getCell('Z1')->getCalculatedValue();
self::assertSame(ExcelError::VALUE(), $result);
}
public static function providerSortWithScalarArgumentErrorReturns(): array
{
return [
'Non-array sortIndex' => ['A', 1],
'Mismatched sortIndex count' => ['{1, 2, 3, 4}', 1],
'Non-numeric sortOrder' => ['{1, 2, 3}', '"A"'],
'Invalid negative sortOrder' => ['{1, 2, 3}', -2],
'Zero sortOrder' => ['{1, 2, 3}', 0],
'Invalid positive sortOrder' => ['{1, 2, 3}', 2],
];
}
/**
* @param mixed[] $matrix
*/
#[DataProvider('providerSortByRow')]
public function testSortByRow(array $expectedResult, array $matrix, string $byArray, ?int $sortOrder = null, ?string $byArray2 = null, ?int $sortOrder2 = null): void
{
$sheet = $this->getSheet($matrix);
$sheet->fromArray([['B'], ['D'], ['A'], ['C'], ['H'], ['G'], ['F'], ['E']], null, 'G1', true);
$sheet->fromArray([[true], [false], [true], [false], [true], [false], [true], [false]], null, 'H1', true);
$formula = "=SORTBY({$this->range}, $byArray";
if ($sortOrder !== null) {
$formula .= ", $sortOrder";
if ($byArray2 !== null) {
$formula .= ", $byArray2";
if ($sortOrder2 !== null) {
$formula .= ", $sortOrder2";
}
}
}
$formula .= ')';
$sheet->getCell('Z1')->setValue($formula);
$result = $sheet->getCell('Z1')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
public static function providerSortByRow(): array
{
return [
'Simple sort by age' => [
[
['Fritz', 19],
['Xi', 19],
['Amy', 22],
['Srivan', 39],
['Tom', 52],
['Fred', 65],
['Hector', 66],
['Sal', 73],
],
self::sampleDataForSimpleSort(),
'B1:B8',
1,
],
'Simple sort by name' => [
[
['Amy', 22],
['Fred', 65],
['Fritz', 19],
['Hector', 66],
['Sal', 73],
['Srivan', 39],
['Tom', 52],
['Xi', 19],
],
self::sampleDataForSimpleSort(),
'A1:A8',
],
'More realistic example of when to use SORTBY vs SORT' => [
[
['Amy', 22],
['Tom', 52],
['Sal', 73],
['Fred', 65],
['Hector', 66],
['Xi', 19],
['Srivan', 39],
['Fritz', 19],
],
self::sampleDataForSimpleSort(),
'G1:G8',
],
'Boolean sort indexes' => [
[
['Fred', 65],
['Sal', 73],
['Srivan', 39],
['Hector', 66],
['Tom', 52],
['Amy', 22],
['Fritz', 19],
['Xi', 19],
],
self::sampleDataForSimpleSort(),
'H1:H8',
],
'Simple sort by name descending' => [
[
['Xi', 19],
['Tom', 52],
['Srivan', 39],
['Sal', 73],
['Hector', 66],
['Fritz', 19],
['Fred', 65],
['Amy', 22],
],
self::sampleDataForSimpleSort(),
'A1:A8',
-1,
],
'Row vector (using Dritz instead of Fritz)' => [
[
['Amy', 22],
['Fritz', 19],
['Fred', 65],
['Hector', 66],
['Sal', 73],
['Srivan', 39],
['Tom', 52],
['Xi', 19],
],
self::sampleDataForSimpleSort(),
'{"Tom";"Fred";"Amy";"Sal";"Dritz";"Srivan";"Xi";"Hector"}',
],
'Sort by region asc, name asc' => [
[
['East', 'Fritz', 19],
['East', 'Tom', 52],
['North', 'Amy', 22],
['North', 'Xi', 19],
['South', 'Hector', 66],
['South', 'Sal', 73],
['West', 'Fred', 65],
['West', 'Srivan', 39],
],
self::sampleDataForMultiSort(),
'A1:A8',
Sort::ORDER_ASCENDING,
'B1:B8',
],
'Sort by region asc, age desc' => [
[
['East', 'Tom', 52],
['East', 'Fritz', 19],
['North', 'Amy', 22],
['North', 'Xi', 19],
['South', 'Sal', 73],
['South', 'Hector', 66],
['West', 'Fred', 65],
['West', 'Srivan', 39],
],
self::sampleDataForMultiSort(),
'A1:A8',
Sort::ORDER_ASCENDING,
'C1:C8',
Sort::ORDER_DESCENDING,
],
];
}
/** @return array<array{string, int}> */
private static function sampleDataForSimpleSort(): array
{
return [
['Tom', 52],
['Fred', 65],
['Amy', 22],
['Sal', 73],
['Fritz', 19],
['Srivan', 39],
['Xi', 19],
['Hector', 66],
];
}
/** @return array<array{string, string, int}> */
private static function sampleDataForMultiSort(): array
{
return [
['North', 'Amy', 22],
['West', 'Fred', 65],
['East', 'Fritz', 19],
['South', 'Hector', 66],
['South', 'Sal', 73],
['West', 'Srivan', 39],
['East', 'Tom', 52],
['North', 'Xi', 19],
];
}
public function testSortByColumn(): void
{
$matrix = [
['Tom', 'Fred', 'Amy', 'Sal', 'Fritz', 'Srivan', 'Xi', 'Hector'],
[52, 65, 22, 73, 19, 39, 19, 66],
];
$sheet = $this->getSheet($matrix);
$formula = "=SORTBY({$this->range}, A1:H1)";
$expectedResult = [
['Amy', 'Fred', 'Fritz', 'Hector', 'Sal', 'Srivan', 'Tom', 'Xi'],
[22, 65, 19, 66, 73, 39, 52, 19],
];
$sheet->getCell('Z1')->setValue($formula);
$result = $sheet->getCell('Z1')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/HLookupTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/HLookupTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Cell\Coordinate;
use PhpOffice\PhpSpreadsheet\NamedRange;
use PHPUnit\Framework\Attributes\DataProvider;
class HLookupTest extends AllSetupTeardown
{
/** @param mixed[] $values */
#[DataProvider('providerHLOOKUP')]
public function testHLOOKUP(mixed $expectedResult, mixed $lookup, array $values, mixed $rowIndex, ?bool $rangeLookup = null): void
{
$this->setArrayAsValue();
$sheet = $this->getSheet();
$maxRow = 0;
$maxCol = 0;
$maxColLetter = 'A';
$row = 0;
foreach ($values as $rowValues) {
++$row;
++$maxRow;
$col = 0;
if (!is_array($rowValues)) {
$rowValues = [$rowValues];
}
foreach ($rowValues as $cellValue) {
++$col;
$colLetter = Coordinate::stringFromColumnIndex($col);
if ($col > $maxCol) {
$maxCol = $col;
$maxColLetter = $colLetter;
}
if ($cellValue !== null) {
$sheet->getCell("$colLetter$row")->setValue($cellValue);
}
}
}
$boolArg = self::parseRangeLookup($rangeLookup);
$sheet->getCell('ZZ8')->setValue($lookup);
if (is_array($rowIndex)) {
$sheet->fromArray($rowIndex, null, 'ZZ10', true);
$indexarg = 'ZZ10:ZZ' . (string) (9 + count($rowIndex));
} else {
$sheet->getCell('ZZ10')->setValue($rowIndex);
$indexarg = 'ZZ10';
}
$sheet->getCell('ZZ1')->setValue("=HLOOKUP(ZZ8, A1:$maxColLetter$maxRow, $indexarg$boolArg)");
self::assertEquals($expectedResult, $sheet->getCell('ZZ1')->getCalculatedValue());
}
private static function parseRangeLookup(?bool $rangeLookup): string
{
if ($rangeLookup === null) {
return '';
}
return $rangeLookup ? ', true' : ', false';
}
public static function providerHLOOKUP(): array
{
return require 'tests/data/Calculation/LookupRef/HLOOKUP.php';
}
#[DataProvider('providerHLookupNamedRange')]
public function testHLookupNamedRange(string $expectedResult, string $cellAddress): void
{
$lookupData = [
['Rating', 1, 2, 3, 4],
['Level', 'Poor', 'Average', 'Good', 'Excellent'],
];
$formData = [
['Category', 'Rating', 'Level'],
['Service', 2, '=HLOOKUP(C5,Lookup_Table,2,FALSE)'],
['Quality', 3, '=HLOOKUP(C6,Lookup_Table,2,FALSE)'],
['Value', 4, '=HLOOKUP(C7,Lookup_Table,2,FALSE)'],
['Cleanliness', 3, '=HLOOKUP(C8,Lookup_Table,2,FALSE)'],
];
$worksheet = $this->getSheet();
$worksheet->fromArray($lookupData, null, 'F4');
$worksheet->fromArray($formData, null, 'B4');
$this->getSpreadsheet()->addNamedRange(new NamedRange('Lookup_Table', $worksheet, '=$G$4:$J$5'));
$result = $worksheet->getCell($cellAddress)->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public static function providerHLookupNamedRange(): array
{
return [
['Average', 'D5'],
['Good', 'D6'],
['Excellent', 'D7'],
['Good', 'D8'],
];
}
#[DataProvider('providerHLookupArray')]
public function testHLookupArray(array $expectedResult, string $values, string $database, string $index): void
{
$calculation = Calculation::getInstance();
$formula = "=HLOOKUP({$values}, {$database}, {$index}, false)";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
public static function providerHLookupArray(): array
{
return [
'row vector #1' => [
[[4, 9]],
'{"Axles", "Bolts"}',
'{"Axles", "Bearings", "Bolts"; 4, 4, 9; 5, 7, 10; 6, 8, 11}',
'2',
],
'row vector #2' => [
[[5, 7]],
'{"Axles", "Bearings"}',
'{"Axles", "Bearings", "Bolts"; 4, 4, 9; 5, 7, 10; 6, 8, 11}',
'3',
],
'row/column vectors' => [
[[4, 9], [5, 10]],
'{"Axles", "Bolts"}',
'{"Axles", "Bearings", "Bolts"; 4, 4, 9; 5, 7, 10; 6, 8, 11}',
'{2; 3}',
],
'issue 3561' => [
[[8, 9, 8]],
'6',
'{1,6,11;2,7,12;3,8,13;4,9,14;5,10,15}',
'{3,4,3}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/OffsetTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/OffsetTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PhpOffice\PhpSpreadsheet\NamedRange;
use PHPUnit\Framework\Attributes\DataProvider;
class OffsetTest extends AllSetupTeardown
{
#[DataProvider('providerOFFSET')]
public function testOFFSET(mixed $expectedResult, null|string $cellReference = null): void
{
$result = LookupRef\Offset::OFFSET($cellReference);
self::assertSame($expectedResult, $result);
}
public static function providerOFFSET(): array
{
return require 'tests/data/Calculation/LookupRef/OFFSET.php';
}
public function testOffsetSpreadsheet(): void
{
$sheet = $this->getSheet();
$sheet->getCell('B6')->setValue(4);
$sheet->getCell('B7')->setValue(8);
$sheet->getCell('B8')->setValue(3);
$sheet->getCell('D6')->setValue(10);
$sheet->getCell('D7')->setValue(3);
$sheet->getCell('D8')->setValue(6);
$sheet->getCell('A1')->setValue('=OFFSET(D3,3,-2,1,1)');
self::assertSame(4, $sheet->getCell('A1')->getCalculatedValue());
$sheet->getCell('A2')->setValue('=SUM(OFFSET(D3:F5,3,-2, 3, 3))');
self::assertSame(34, $sheet->getCell('A2')->getCalculatedValue());
$sheet->getCell('A3')->setValue('=OFFSET(D3, -3, -3)');
self::assertSame('#REF!', $sheet->getCell('A3')->getCalculatedValue());
$sheet->getCell('C1')->setValue(5);
$sheet->getCell('A4')->setValue('=OFFSET(C1, 0, 0, 0, 0)');
self::assertSame('#REF!', $sheet->getCell('A4')->getCalculatedValue());
$sheet->getCell('A5')->setValue('=OFFSET(C1, 0, 0)');
self::assertSame(5, $sheet->getCell('A5')->getCalculatedValue());
}
public function testOffsetNamedRange(): void
{
$workSheet = $this->getSheet();
$workSheet->setCellValue('A1', 1);
$workSheet->setCellValue('A2', 2);
$this->getSpreadsheet()->addNamedRange(new NamedRange('demo', $workSheet, '=$A$1'));
$workSheet->setCellValue('B1', '=demo');
$workSheet->setCellValue('B2', '=OFFSET(demo, 1, 0)');
self::assertSame(2, $workSheet->getCell('B2')->getCalculatedValue());
}
public function testOffsetNamedRangeApostropheSheet(): void
{
$workSheet = $this->getSheet();
$workSheet->setTitle("apo'strophe");
$workSheet->setCellValue('A1', 1);
$workSheet->setCellValue('A2', 2);
$this->getSpreadsheet()->addNamedRange(new NamedRange('demo', $workSheet, '=$A$1'));
$workSheet->setCellValue('B1', '=demo');
$workSheet->setCellValue('B2', '=OFFSET(demo, 1, 0)');
self::assertSame(2, $workSheet->getCell('B2')->getCalculatedValue());
}
public function testOffsetMultiCellNamedRange(): void
{
$sheet = $this->getSheet();
$sheet->setCellValue('D13', 'Hello');
$this->getSpreadsheet()
->addNamedRange(new NamedRange('CELLAREA', $sheet, '$B$6:$F$22'));
$sheet->setCellValue('D1', '=OFFSET(CELLAREA,7,2,1,1)');
self::assertSame('Hello', $sheet->getCell('D1')->getCalculatedValue());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/FormulaTextTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/FormulaTextTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Formula;
/**
* Class FormulaTextTest.
*/
class FormulaTextTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerFormulaText')]
public function testFormulaText(string $expectedResult, mixed $value): void
{
$sheet = $this->getSheet();
$reference = 'A1';
if ($value !== null) {
$sheet->getCell($reference)->setValue($value);
}
$sheet->getCell('D1')->setValue("=FORMULATEXT($reference)");
$result = $sheet->getCell('D1')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
public static function providerFormulaText(): array
{
return require 'tests/data/Calculation/LookupRef/FORMULATEXT.php';
}
public function testNoCell(): void
{
self::assertSame('#REF!', Formula::text('B5'));
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/UniqueTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/UniqueTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class UniqueTest extends TestCase
{
/** @param mixed[] $lookupRef */
#[DataProvider('uniqueTestProvider')]
public function testUnique(array $expectedResult, array $lookupRef, bool $byColumn = false, bool $exactlyOnce = false): void
{
$result = LookupRef\Unique::unique($lookupRef, $byColumn, $exactlyOnce);
self::assertSame($expectedResult, $result);
}
public function testUniqueException(): void
{
$rowLookupData = [
['Andrew', 'Brown'],
['Betty', 'Johnson'],
['Betty', 'Johnson'],
['Andrew', 'Brown'],
['David', 'White'],
['Andrew', 'Brown'],
['David', 'White'],
];
$columnLookupData = [
['PHP', 'Rocks', 'php', 'rocks'],
];
$result = LookupRef\Unique::unique($rowLookupData, false, true);
self::assertSame(ExcelError::CALC(), $result);
$result = LookupRef\Unique::unique($columnLookupData, true, true);
self::assertSame(ExcelError::CALC(), $result);
}
public function testUniqueWithScalar(): void
{
$lookupData = 123;
$result = LookupRef\Unique::unique($lookupData);
self::assertSame($lookupData, $result);
}
public static function uniqueTestProvider(): array
{
return [
[
[['Red'], ['Green'], ['Blue'], ['Orange']],
[
['Red'],
['Green'],
['Green'],
['Blue'],
['Blue'],
['Orange'],
['Green'],
['Blue'],
['Red'],
],
],
[
[['Red'], ['Green'], ['Blue'], ['Orange']],
[
['Red'],
['Green'],
['GrEEn'],
['Blue'],
['BLUE'],
['Orange'],
['GReeN'],
['blue'],
['RED'],
],
],
[
['Orange'],
[
['Red'],
['Green'],
['Green'],
['Blue'],
['Blue'],
['Orange'],
['Green'],
['Blue'],
['Red'],
],
false,
true,
],
[
['Andrew', 'Betty', 'Robert', 'David'],
[['Andrew', 'Betty', 'Robert', 'Andrew', 'Betty', 'Robert', 'David', 'Andrew']],
true,
],
[
['David'],
[['Andrew', 'Betty', 'Robert', 'Andrew', 'Betty', 'Robert', 'David', 'Andrew']],
true,
true,
],
[
[1, 1, 2, 2, 3],
[[1, 1, 2, 2, 3]],
],
[
[1, 2, 3],
[[1, 1, 2, 2, 3]],
true,
],
[
[
[1, 1, 2, 3],
[1, 2, 2, 3],
],
[
[1, 1, 2, 2, 3],
[1, 2, 2, 2, 3],
],
true,
],
[
[
['Andrew', 'Brown'],
['Betty', 'Johnson'],
['David', 'White'],
],
[
['Andrew', 'Brown'],
['Betty', 'Johnson'],
['Betty', 'Johnson'],
['Andrew', 'Brown'],
['David', 'White'],
['Andrew', 'Brown'],
['David', 'White'],
],
],
[
[[1.2], [2.1], [2.2], [3], ['3'], [8.7]],
[
[1.2],
[1.2],
[2.1],
[2.2],
[3.0],
[3],
['3'],
[8.7],
],
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/SortBetterTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/SortBetterTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Information\ExcelError;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef\Sort;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
class SortBetterTest extends TestCase
{
private Spreadsheet $spreadsheet;
private int $maxRow;
private string $maxCol;
private string $range;
protected function tearDown(): void
{
$this->spreadsheet->disconnectWorksheets();
unset($this->spreadsheet);
}
/** @param mixed[] $values */
public function getSheet(array $values): Worksheet
{
$this->spreadsheet = new Spreadsheet();
$this->spreadsheet->returnArrayAsArray();
$sheet = $this->spreadsheet->getActiveSheet();
$sheet->fromArray($values);
$this->maxRow = $sheet->getHighestDataRow();
$this->maxCol = $sheet->getHighestDataColumn();
$this->range = "A1:{$this->maxCol}{$this->maxRow}";
return $sheet;
}
public function testSortOnScalar(): void
{
$value = 'NON-ARRAY';
$sheet = $this->getSheet([$value]);
$sheet->getCell('Z1')->setValue('=SORT(A1, 1, -1)');
$sheet->getCell('Z2')->setValue('=SORT(A1:A1, 1, -1)');
$sheet->getCell('Z3')->setValue('=SORT(A1, "A", -1)');
$result = $sheet->getCell('Z1')->getCalculatedValue();
self::assertSame([[$value]], $result);
$result = $sheet->getCell('Z2')->getCalculatedValue();
self::assertSame([[$value]], $result);
$result = $sheet->getCell('Z3')->getCalculatedValue();
self::assertSame(ExcelError::VALUE(), $result);
}
#[DataProvider('providerSortWithScalarArgumentErrorReturns')]
public function testSortWithScalarArgumentErrorReturns(int|string $sortIndex, int|string $sortOrder = 1): void
{
$value = [[1, 2], [3, 4], [5, 6]];
$sheet = $this->getSheet($value);
$formula = "=SORT({$this->range}, $sortIndex, $sortOrder)";
$sheet->getCell('Z1')->setValue($formula);
$result = $sheet->getCell('Z1')->getCalculatedValue();
self::assertSame(ExcelError::VALUE(), $result);
}
public static function providerSortWithScalarArgumentErrorReturns(): array
{
return [
'Negative sortIndex' => [-1, -1],
'Non-numeric sortIndex' => ['"A"', -1],
'Zero sortIndex' => [0, -1],
'Too high sortIndex' => [3, -1],
'Non-numeric sortOrder' => [1, '"A"'],
'Invalid negative sortOrder' => [1, -2],
'Zero sortOrder' => [1, 0],
'Invalid positive sortOrder' => [1, 2],
'Too many sortOrders (scalar and array)' => [1, '{-1, 1}'],
'Too many sortOrders (both array)' => ['{1, 2}', '{1, 2, 3}'],
'Zero positive sortIndex in vector' => ['{0, 1}'],
'Too high sortIndex in vector' => ['{1, 3}'],
'Invalid sortOrder in vector' => ['{1, 2}', '{1, -2}'],
];
}
/**
* @param mixed[] $expectedResult
* @param mixed[] $matrix
*/
#[DataProvider('providerSortByRow')]
public function testSortByRow(array $expectedResult, array $matrix, int $sortIndex, int $sortOrder = Sort::ORDER_ASCENDING): void
{
$sheet = $this->getSheet($matrix);
$formula = "=SORT({$this->range}, $sortIndex, $sortOrder)";
$sheet->getCell('Z1')->setValue($formula);
$result = $sheet->getCell('Z1')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
/** @return mixed[] */
public static function providerSortByRow(): array
{
return [
[
[[142], [378], [404], [445], [483], [622], [650], [691], [783], [961]],
self::sampleDataForRow(),
1,
],
[
[[961], [783], [691], [650], [622], [483], [445], [404], [378], [142]],
self::sampleDataForRow(),
1,
Sort::ORDER_DESCENDING,
],
[
[['Peaches', 25], ['Cherries', 29], ['Grapes', 31], ['Lemons', 34], ['Oranges', 36], ['Apples', 38], ['Pears', 40]],
[['Apples', 38], ['Cherries', 29], ['Grapes', 31], ['Lemons', 34], ['Oranges', 36], ['Peaches', 25], ['Pears', 40]],
2,
],
];
}
/**
* @param mixed[] $expectedResult
* @param mixed[] $matrix
*/
#[DataProvider('providerSortByRowMultiLevel')]
public function testSortByRowMultiLevel(array $expectedResult, array $matrix, string $sortIndex, int $sortOrder = Sort::ORDER_ASCENDING): void
{
$sheet = $this->getSheet($matrix);
$formula = "=SORT({$this->range}, $sortIndex, $sortOrder)";
$sheet->getCell('Z1')->setValue($formula);
$result = $sheet->getCell('Z1')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
public static function providerSortByRowMultiLevel(): array
{
return [
[
[
['East', 'Grapes', 31],
['East', 'Lemons', 36],
['North', 'Cherries', 29],
['North', 'Grapes', 27],
['North', 'Peaches', 25],
['South', 'Apples', 38],
['South', 'Cherries', 28],
['South', 'Oranges', 36],
['South', 'Pears', 40],
['West', 'Apples', 30],
['West', 'Lemons', 34],
['West', 'Oranges', 25],
],
self::sampleDataForMultiRow(),
'{1, 2}',
],
[
[
['East', 'Grapes', 31],
['East', 'Lemons', 36],
['North', 'Peaches', 25],
['North', 'Grapes', 27],
['North', 'Cherries', 29],
['South', 'Cherries', 28],
['South', 'Oranges', 36],
['South', 'Apples', 38],
['South', 'Pears', 40],
['West', 'Oranges', 25],
['West', 'Apples', 30],
['West', 'Lemons', 34],
],
self::sampleDataForMultiRow(),
'{1, 3}',
],
[
[
['West', 'Apples', 30],
['South', 'Apples', 38],
['South', 'Cherries', 28],
['North', 'Cherries', 29],
['North', 'Grapes', 27],
['East', 'Grapes', 31],
['West', 'Lemons', 34],
['East', 'Lemons', 36],
['West', 'Oranges', 25],
['South', 'Oranges', 36],
['North', 'Peaches', 25],
['South', 'Pears', 40],
],
self::sampleDataForMultiRow(),
'{2, 3}',
],
];
}
/**
* @param mixed[] $expectedResult
* @param mixed[] $matrix
*/
#[DataProvider('providerSortByColumn')]
public function testSortByColumn(array $expectedResult, array $matrix, int $sortIndex, int $sortOrder): void
{
$sheet = $this->getSheet($matrix);
$formula = "=SORT({$this->range}, $sortIndex, $sortOrder, TRUE)";
$sheet->getCell('Z1')->setValue($formula);
$result = $sheet->getCell('Z1')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
public static function providerSortByColumn(): array
{
return [
[
[[142, 378, 404, 445, 483, 622, 650, 691, 783, 961]],
self::sampleDataForColumn(),
1,
Sort::ORDER_ASCENDING,
],
[
[[961, 783, 691, 650, 622, 483, 445, 404, 378, 142]],
self::sampleDataForColumn(),
1,
Sort::ORDER_DESCENDING,
],
];
}
/** @return array<int[]> */
public static function sampleDataForRow(): array
{
return [
[622], [961], [691], [445], [378], [483], [650], [783], [142], [404],
];
}
/** @return array<array{string, string, int}> */
public static function sampleDataForMultiRow(): array
{
return [
['South', 'Pears', 40],
['South', 'Apples', 38],
['South', 'Oranges', 36],
['East', 'Lemons', 36],
['West', 'Lemons', 34],
['East', 'Grapes', 31],
['West', 'Apples', 30],
['North', 'Cherries', 29],
['South', 'Cherries', 28],
['North', 'Grapes', 27],
['North', 'Peaches', 25],
['West', 'Oranges', 25],
];
}
/** @return array<int[]> */
public static function sampleDataForColumn(): array
{
return [
[622, 961, 691, 445, 378, 483, 650, 783, 142, 404],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/VStackTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/LookupRef/VStackTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Shared\Date;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Table;
/**
* Many of these tests are derived from
* https://exceljet.net/functions/vstack-function.
*/
class VStackTest extends AllSetupTeardown
{
public static function testVstack1(): void
{
$spreadsheet = new Spreadsheet();
Calculation::getInstance($spreadsheet)
->setInstanceArrayReturnType(
Calculation::RETURN_ARRAY_AS_ARRAY
);
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('B2', 'Array1');
$sheet->setCellValue('B3', 'Red');
$sheet->setCellValue('B4', 'Blue');
$sheet->setCellValue('B5', 'Green');
$sheet->setCellValue('B7', 'Array2');
$sheet->setCellValue('B8', 'Green');
$sheet->setCellValue('B9', 'Red');
$sheet->setCellValue('D2', 'Result');
$sheet->setCellValue('D3', '=VSTACK(B3:B5,B8:B9)');
$expected = [
['Red'],
['Blue'],
['Green'],
['Green'],
['Red'],
];
self::assertSame($expected, $sheet->getCell('D3')->getCalculatedValue());
$sheet->setCellValue('F2', '=VSTACK(B2,B8:B9)');
$expected = [
['Array1'],
['Green'],
['Red'],
];
self::assertSame($expected, $sheet->getCell('F2')->getCalculatedValue(), 'one single-cell argument');
$spreadsheet->disconnectWorksheets();
}
public static function testVstack2(): void
{
$spreadsheet = new Spreadsheet();
Calculation::getInstance($spreadsheet)
->setInstanceArrayReturnType(
Calculation::RETURN_ARRAY_AS_ARRAY
);
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('B3', 'Red');
$sheet->setCellValue('B4', 'Blue');
$sheet->setCellValue('B5', 'Green');
$sheet->setCellValue('B6', 'Blue');
$sheet->setCellValue('B7', 'Red');
$sheet->setCellValue('C3', 12);
$sheet->setCellValue('C4', 9);
$sheet->setCellValue('C5', 10);
$sheet->setCellValue('C5', 10);
$sheet->setCellValue('C6', 11);
$sheet->setCellValue('C7', 8);
$sheet->setCellValue('E3', '=VSTACK({"Color","Qty"},B3:C7)');
$expected = [
['Color', 'Qty'],
['Red', 12],
['Blue', 9],
['Green', 10],
['Blue', 11],
['Red', 8],
];
self::assertSame($expected, $sheet->getCell('E3')->getCalculatedValue());
$sheet->setCellValue('A1', 'Purple');
$sheet->setCellValue('A2', 'Orange');
$sheet->setCellValue('H3', '=VSTACK({"Color","Qty"},A1:A2,B3:C7)');
$expected = [
['Color', 'Qty'],
['Purple', '#N/A'],
['Orange', '#N/A'],
['Red', 12],
['Blue', 9],
['Green', 10],
['Blue', 11],
['Red', 8],
];
self::assertSame($expected, $sheet->getCell('H3')->getCalculatedValue());
$spreadsheet->disconnectWorksheets();
}
/**
* Excel has a problem here.
* If it reads VSTACK(Table1, Table2) without square
* brackets after Table1/2, it calculates the result as #NAME?.
* You can then just edit the formula without making
* any changes, and it will calculate it correctly,
* but it will add in the brackets when saving.
* This seems pretty buggy to me.
* PhpSpreadsheet will handle the formula with or without
* the brackets, but you should specify them to avoid
* problems with Excel.
*/
public static function testTables(): void
{
$spreadsheet = new Spreadsheet();
Calculation::getInstance($spreadsheet)
->setInstanceArrayReturnType(
Calculation::RETURN_ARRAY_AS_ARRAY
);
$sheet = $spreadsheet->getActiveSheet();
$data = [
['Date', 'Color', 'Qty'],
[Date::stringToExcel('2021-04-03'), 'Red', 12],
[Date::stringToExcel('2021-04-07'), 'Blue', 9],
[Date::stringToExcel('2021-04-11'), 'Green', 10],
[Date::stringToExcel('2021-04-15'), 'Blue', 11],
[Date::stringToExcel('2021-04-20'), 'Red', 8],
];
$sheet->fromArray($data, null, 'B4', true);
$table = new Table('B4:D9', 'Table1');
$sheet->addTable($table);
$data = [
['Date', 'Color', 'Qty'],
[Date::stringToExcel('2021-05-05'), 'Red', 12],
[Date::stringToExcel('2021-05-12'), 'Blue', 9],
[Date::stringToExcel('2021-05-18'), 'Green', 10],
[Date::stringToExcel('2021-05-21'), 'Blue', 11],
[Date::stringToExcel('2021-05-28'), 'Green', 6],
];
$sheet->fromArray($data, null, 'B11', true);
$table = new Table('B11:D16', 'Table2');
$sheet->addTable($table);
$sheet->setCellValue('G4', 'Date');
$sheet->setCellValue('H4', 'Color');
$sheet->setCellValue('I4', 'Qty');
$sheet->setCellValue('G5', '=VSTACK(Table1[],Table2[])');
$sheet->getCell('G5')->getCalculatedValue();
$sheet->getStyle('B4:B16')
->getNumberFormat()
->setFormatCode('d-mmm');
$sheet->getStyle('G5:G14')
->getNumberFormat()
->setFormatCode('d-mmm');
$expected = [
['3-Apr', 'Red', '12'],
['7-Apr', 'Blue', '9'],
['11-Apr', 'Green', '10'],
['15-Apr', 'Blue', '11'],
['20-Apr', 'Red', '8'],
['5-May', 'Red', '12'],
['12-May', 'Blue', '9'],
['18-May', 'Green', '10'],
['21-May', 'Blue', '11'],
['28-May', 'Green', '6'],
];
$actual = $sheet->rangeToArray('G5:I14', null, true, true);
self::assertSame($expected, $actual);
$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/PermutTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/PermutTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class PermutTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerPERMUT')]
public function testPERMUT(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('PERMUT', $expectedResult, ...$args);
}
public static function providerPERMUT(): array
{
return require 'tests/data/Calculation/Statistical/PERMUT.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerPermutArray')]
public function testPermutArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=PERMUT({$argument1},{$argument2})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerPermutArray(): array
{
return [
'first argument row vector' => [
[[336, 60]],
'{8, 5}',
'3',
],
'first argument column vector' => [
[[336], [60]],
'{8; 5}',
'3',
],
'first argument matrix' => [
[[336, 60], [6, 210]],
'{8, 5; 3, 7}',
'3',
],
'second argument row vector' => [
[[1716, 1235520]],
'13',
'{3, 6}',
],
'second argument column vector' => [
[[1716], [1235520]],
'13',
'{3; 6}',
],
'second argument matrix' => [
[[1716, 1235520], [17160, 51891840]],
'13',
'{3, 6; 4, 8}',
],
'A row and a column vector' => [
[
[95040, 11880, 1320, 132],
[30240, 5040, 720, 90],
[6720, 1680, 336, 56],
[720, 360, 120, 30],
],
'{12; 10; 8; 6}',
'{5, 4, 3, 2}',
],
'Two row vectors' => [
[[95040, 5040, 336, 30]],
'{12, 10, 8, 6}',
'{5, 4, 3, 2}',
],
'Two column vectors' => [
[[95040], [5040], [336], [30]],
'{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/PercentileTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/PercentileTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class PercentileTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerPERCENTILE')]
public function testPERCENTILE(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('PERCENTILE', $expectedResult, ...$args);
}
public static function providerPERCENTILE(): array
{
return require 'tests/data/Calculation/Statistical/PERCENTILE.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/CountIfsTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/CountIfsTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
// TODO There are some commented out cases which don't return correct value
class CountIfsTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCOUNTIFS')]
public function testCOUNTIFS(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseNoBracket('COUNTIFS', $expectedResult, ...$args);
}
public static function providerCOUNTIFS(): array
{
return require 'tests/data/Calculation/Statistical/COUNTIFS.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/BinomDistTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/BinomDistTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class BinomDistTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerBINOMDIST')]
public function testBINOMDIST(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('BINOMDIST', $expectedResult, ...$args);
}
public static function providerBINOMDIST(): array
{
return require 'tests/data/Calculation/Statistical/BINOMDIST.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerBinomDistArray')]
public function testBinomDistArray(
array $expectedResult,
string $values,
string $trials,
string $probabilities
): void {
$calculation = Calculation::getInstance();
$formula = "=BINOMDIST({$values}, {$trials}, {$probabilities}, false)";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerBinomDistArray(): array
{
return [
'row/column vectors' => [
[[0.17303466796875, 0.01153564453125], [0.258103609085083, 0.1032414436340332]],
'{3, 5}',
'{7; 12}',
'0.25',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/WeibullTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/WeibullTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class WeibullTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerWEIBULL')]
public function testWEIBULL(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('WEIBULL', $expectedResult, ...$args);
}
public static function providerWEIBULL(): array
{
return require 'tests/data/Calculation/Statistical/WEIBULL.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerWeibullArray')]
public function testWeibullArray(array $expectedResult, string $values, string $alpha, string $beta): void
{
$calculation = Calculation::getInstance();
$formula = "=WEIBULL({$values}, {$alpha}, {$beta}, false)";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerWeibullArray(): array
{
return [
'row/column vectors' => [
[
[0.18393972058572117, 0.36787944117144233, 0.9196986029286058],
[0.15163266492815836, 0.19470019576785122, 0.07572134644346439],
[0.13406400920712788, 0.1363430062345938, 0.0253391936076857],
],
'2',
'{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/AllSetupTeardown.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/AllSetupTeardown.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
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\Shared\StringHelper;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
use PHPUnit\Framework\TestCase;
use Stringable;
class AllSetupTeardown extends TestCase
{
private string $compatibilityMode;
private ?Spreadsheet $spreadsheet = null;
private ?Worksheet $sheet = null;
protected string $returnArrayAs;
protected function setUp(): void
{
$this->compatibilityMode = Functions::getCompatibilityMode();
$this->returnArrayAs = '';
}
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;
}
/**
* Excel handles text/logical/empty cells differently when
* passed directly as arguments as opposed to cell references or arrays.
* This function will test both approaches.
*/
protected function runTestCases(string $functionName, mixed $expectedResult, mixed ...$args): void
{
if (is_array($expectedResult)) {
$this->runTestCaseReference($functionName, $expectedResult[0], ...$args);
$this->runTestCaseDirect($functionName, $expectedResult[1], ...$args);
} else {
$this->runTestCaseReference($functionName, $expectedResult, ...$args);
$this->runTestCaseDirect($functionName, $expectedResult, ...$args);
}
}
/**
* Excel handles text/logical/empty cells differently when
* passed directly as arguments as opposed to cell references or arrays.
* This functions tests passing as arrays.
*/
protected function runTestCaseReference(string $functionName, mixed $expectedResult, mixed ...$args): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
if ($this->returnArrayAs !== '') {
$calculation = Calculation::getInstance($this->spreadsheet);
$calculation->setInstanceArrayReturnType(
$this->returnArrayAs
);
}
$formula = "=$functionName(";
$comma = '';
$row = 0;
foreach ($args as $arg) {
++$row;
if (is_array($arg)) {
$arrayArg = '{';
$arrayComma = '';
foreach ($arg as $arrayItem) {
$arrayArg .= $arrayComma;
if ($arrayItem !== null && !is_scalar($arrayItem) && !($arrayItem instanceof Stringable)) {
self::fail('non-stringable item');
}
$arrayArg .= $this->convertToString($arrayItem);
$arrayComma = ';';
}
$arrayArg .= '}';
$formula .= "$comma$arrayArg";
$comma = ',';
} else {
$cellId = "A$row";
$formula .= "$comma$cellId";
$comma = ',';
$this->setCell($cellId, $arg);
}
}
$formula .= ')';
$this->setCell('B1', $formula);
self::assertEqualsWithDelta($expectedResult, $sheet->getCell('B1')->getCalculatedValue(), 1.0e-8, 'arguments supplied as references');
}
/**
* Excel handles text/logical/empty cells differently when
* passed directly as arguments as opposed to cell references or arrays.
* This functions tests passing as direct arguments.
*/
protected function runTestCaseDirect(string $functionName, mixed $expectedResult, mixed ...$args): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$formula = "=$functionName(";
$comma = '';
foreach ($args as $arg) {
if (is_array($arg)) {
foreach ($arg as $arrayItem) {
$formula .= $comma;
$comma = ',';
if ($arrayItem !== null && !is_scalar($arrayItem) && !($arrayItem instanceof Stringable)) {
self::fail('non-stringable item');
}
$formula .= $this->convertToString($arrayItem);
}
} else {
$formula .= $comma;
$comma = ',';
/** @var string */
$argx = $arg;
$formula .= $this->convertToString($argx);
}
}
$formula .= ')';
$this->setCell('B2', $formula);
self::assertEqualsWithDelta($expectedResult, $sheet->getCell('B2')->getCalculatedValue(), 1.0e-8, 'arguments supplied directly');
}
/**
* Excel seems to reject bracket notation for literal arrays
* for some functions.
*/
protected function runTestCaseNoBracket(string $functionName, mixed $expectedResult, mixed ...$args): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$formula = "=$functionName(";
$comma = '';
$row = 0;
foreach ($args as $arg) {
++$row;
if (is_array($arg)) {
$col = 'A';
$arrayRange = '';
foreach ($arg as $arrayItem) {
$cellId = "$col$row";
$arrayRange = "A$row:$cellId";
$this->setCell($cellId, $arrayItem);
StringHelper::stringIncrement($col);
}
$formula .= "$comma$arrayRange";
$comma = ',';
} else {
$cellId = "A$row";
$formula .= "$comma$cellId";
$comma = ',';
if (is_string($arg) && str_starts_with($arg, '=')) {
$sheet->getCell($cellId)->setValueExplicit($arg, DataType::TYPE_STRING);
} else {
$this->setCell($cellId, $arg);
}
}
}
$formula .= ')';
$this->setCell('Z99', $formula);
self::assertEqualsWithDelta($expectedResult, $sheet->getCell('Z99')->getCalculatedValue(), 1.0e-8, 'arguments supplied as ranges');
}
private function convertToString(null|bool|float|int|string|Stringable $arg): string
{
if (is_string($arg)) {
return '"' . $arg . '"';
}
if (is_bool($arg)) {
return $arg ? 'TRUE' : 'FALSE';
}
return (string) $arg;
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/InterceptTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/InterceptTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class InterceptTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerINTERCEPT')]
public function testINTERCEPT(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseNoBracket('INTERCEPT', $expectedResult, ...$args);
}
public static function providerINTERCEPT(): array
{
return require 'tests/data/Calculation/Statistical/INTERCEPT.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/LogInvTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/LogInvTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class LogInvTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerLOGINV')]
public function testLOGINV(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('LOGINV', $expectedResult, ...$args);
}
public static function providerLOGINV(): array
{
return require 'tests/data/Calculation/Statistical/LOGINV.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerLogInvArray')]
public function testLogInvArray(array $expectedResult, string $probabilities, string $mean, string $stdDev): void
{
$calculation = Calculation::getInstance();
$formula = "=LOGINV({$probabilities}, {$mean}, {$stdDev})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerLogInvArray(): array
{
return [
'row/column vectors' => [
[[54.598150033144236, 403.4287934927351]],
'0.5',
'{4, 6}',
'7',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/PercentRankTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/PercentRankTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class PercentRankTest extends AllSetupTeardown
{
/**
* @param mixed[] $valueSet
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerPERCENTRANK')]
public function testPERCENTRANK(mixed $expectedResult, mixed $valueSet, mixed $value, mixed $digits = null): void
{
if ($digits === null) {
$this->runTestCaseReference('PERCENTRANK', $expectedResult, $valueSet, $value);
} else {
$this->runTestCaseReference('PERCENTRANK', $expectedResult, $valueSet, $value, $digits);
}
}
public static function providerPERCENTRANK(): array
{
return require 'tests/data/Calculation/Statistical/PERCENTRANK.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/LogNormDist2Test.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/LogNormDist2Test.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class LogNormDist2Test extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerLOGNORMDIST2')]
public function testLOGNORMDIST2(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('LOGNORM.DIST', $expectedResult, ...$args);
}
public static function providerLOGNORMDIST2(): array
{
return require 'tests/data/Calculation/Statistical/LOGNORMDIST2.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerLogNormDist2Array')]
public function testLogNormDist2Array(array $expectedResult, string $values, string $mean, string $stdDev): void
{
$calculation = Calculation::getInstance();
$formula = "=LOGNORM.DIST({$values}, {$mean}, {$stdDev}, true)";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerLogNormDist2Array(): array
{
return [
'row/column vectors' => [
[
[0.20185593420695913, 0.34805905738890675, 0.47717995703671096],
[0.06641711479920787, 0.24102205723753728, 0.45897407661978173],
[8.579368431449463E-5, 0.03941233670471267, 0.398378394299419],
],
'12',
'{10, 6, 3}',
'{9; 5; 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/PoissonTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/PoissonTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class PoissonTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerPOISSON')]
public function testPOISSON(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('POISSON', $expectedResult, ...$args);
}
public static function providerPOISSON(): array
{
return require 'tests/data/Calculation/Statistical/POISSON.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerPoissonArray')]
public function testPoissonArray(array $expectedResult, string $values, string $mean): void
{
$calculation = Calculation::getInstance();
$formula = "=POISSON({$values}, {$mean}, false)";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerPoissonArray(): array
{
return [
'row/column vectors' => [
[
[0.4749316557209494, 0.41547307344655265, 0.028388126533408903],
[0.3081373033023279, 0.3299417281086086, 0.0867439330307142],
[0.14758417287196898, 0.19139299302082188, 0.1804470443154836],
],
'{0.125, 0.5, 3}',
'{0.7; 1.2; 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/TrimMeanTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/TrimMeanTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PHPUnit\Framework\Attributes\DataProvider;
class TrimMeanTest extends AllSetupTeardown
{
/** @param mixed[] $args */
#[DataProvider('providerTRIMMEAN')]
public function testTRIMMEAN(mixed $expectedResult, array $args, mixed $percentage): void
{
$this->runTestCaseReference('TRIMMEAN', $expectedResult, $args, $percentage);
}
public static function providerTRIMMEAN(): array
{
return require 'tests/data/Calculation/Statistical/TRIMMEAN.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/GaussTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GaussTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class GaussTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerGAUSS')]
public function testGAUSS(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('GAUSS', $expectedResult, ...$args);
}
public static function providerGAUSS(): array
{
return require 'tests/data/Calculation/Statistical/GAUSS.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerGaussArray')]
public function testGaussArray(array $expectedResult, string $values): void
{
$calculation = Calculation::getInstance();
$formula = "=GAUSS({$values})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerGaussArray(): array
{
return [
'matrix' => [
[
[-0.4331927987311418, -0.28814460141660325, 0.07925970943910299],
[0.27337264762313174, 0.39435022633314465, 0.5],
],
'{-1.5, -0.8, 0.2; 0.75, 1.25, 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/TDotInvDot2TTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/TDotInvDot2TTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PHPUnit\Framework\Attributes\DataProvider;
// Note that TINV and T.INV.2T should return same results,
// so this member just borrows the TINV data.
class TDotInvDot2TTest extends AllSetupTeardown
{
#[DataProvider('providerTINV')]
public function testTdotINV(mixed $expectedResult, mixed $probability, mixed $degrees): void
{
$this->runTestCaseReference('T.INV.2T', $expectedResult, $probability, $degrees);
}
public static function providerTINV(): array
{
return require 'tests/data/Calculation/Statistical/TINV.php';
}
#[DataProvider('providerTInvArray')]
public function testTInvArray(array $expectedResult, string $values, string $degrees): void
{
$calculation = Calculation::getInstance();
$formula = "=T.INV.2T({$values}, {$degrees})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-9);
}
public static function providerTInvArray(): array
{
return [
'row vector' => [
[
[0.612800788, 0.5023133547575189, 0.4713169827948964],
],
'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/StDevATest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/StDevATest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class StDevATest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerSTDEVA')]
public function testSTDEVA(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('STDEVA', $expectedResult, ...$args);
}
public static function providerSTDEVA(): array
{
return require 'tests/data/Calculation/Statistical/STDEVA.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerOdsSTDEVA')]
public function testOdsSTDEVA(mixed $expectedResult, mixed ...$args): void
{
$this->setOpenOffice();
$this->runTestCaseReference('STDEVA', $expectedResult, ...$args);
}
public static function providerOdsSTDEVA(): array
{
return require 'tests/data/Calculation/Statistical/STDEVA_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/DevSqTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/DevSqTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class DevSqTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerDEVSQ')]
public function testDEVSQ(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('DEVSQ', $expectedResult, ...$args);
}
public static function providerDEVSQ(): array
{
return require 'tests/data/Calculation/Statistical/DEVSQ.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/StandardizeTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/StandardizeTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class StandardizeTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerSTANDARDIZE')]
public function testSTANDARDIZE(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('STANDARDIZE', $expectedResult, ...$args);
}
public static function providerSTANDARDIZE(): array
{
return require 'tests/data/Calculation/Statistical/STANDARDIZE.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerStandardizeArray')]
public function testStandardizeArray(array $expectedResult, string $argument1, string $argument2, string $argument3): void
{
$calculation = Calculation::getInstance();
$formula = "=STANDARDIZE({$argument1}, {$argument2}, {$argument3})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerStandardizeArray(): array
{
return [
'row vector' => [[[-1.6666666666666667, -4.6666666666666667, -7.333333333333333, -10, -11.333333333333334]], '{12.5, 8, 4, 0, -2}', '15', '1.5'],
'column vector' => [[[0.25], [0.0], [-1.0]], '{5.5; 5; 3}', '5.0', '2.0'],
'matrix' => [[[0.25, -1.0], [-1.75, -2.75]], '{5.5, 3; 1.5, -0.5}', '5.0', '2.0'],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/AverageIfsTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/AverageIfsTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException;
class AverageIfsTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerAVERAGEIFS')]
public function testAVERAGEIFS(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseNoBracket('AVERAGEIFS', $expectedResult, ...$args);
}
public static function providerAVERAGEIFS(): array
{
return require 'tests/data/Calculation/Statistical/AVERAGEIFS.php';
}
// For example, A1=75, A2=94, A3=86:
// =AVERAGEIFS(A1:A3,A1:A3,">80") gives an answer, but
// =AVERAGEIFS({75;94;86},{75;94;86},">80") does not.
public function testOutliers(): void
{
$sheet = $this->getSheet();
$this->setCell('A1', 75);
$this->setCell('A2', 94);
$this->setCell('A3', 86);
$sheet->getCell('C1')->setValue('=AVERAGEIFS(A1:A3,A1:A3,">80")');
self::assertSame(90, $sheet->getCell('C1')->getCalculatedValue(), 'first and second args are range');
$sheet->getCell('C2')->setValue('=AVERAGEIFS({75;94;86},A1:A3,">80")');
try {
$sheet->getCell('C2')->getCalculatedValue();
self::fail('Should receive exception for literal array arg');
} catch (CalcException $e) {
self::assertStringContainsString('Must specify range of cells', $e->getMessage(), 'first arg is array literal');
}
$sheet->getCell('C3')->setValue('=AVERAGEIFS(A1:A3,{75;94;86},">80")');
try {
$sheet->getCell('C3')->getCalculatedValue();
self::fail('Should receive exception for literal array arg');
} catch (CalcException $e) {
self::assertStringContainsString('Must specify range of cells', $e->getMessage(), 'second arg is array literal');
}
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GrowthTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GrowthTest.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 GrowthTest extends TestCase
{
/**
* @param mixed[] $yValues
* @param mixed[] $xValues
* @param null|mixed[] $newValues
*/
#[DataProvider('providerGROWTH')]
public function testGROWTH(mixed $expectedResult, array $yValues, array $xValues, ?array $newValues = null, ?bool $const = null): void
{
if ($newValues === null) {
$result = Statistical\Trends::GROWTH($yValues, $xValues);
} elseif ($const === null) {
$result = Statistical\Trends::GROWTH($yValues, $xValues, $newValues);
} else {
$result = Statistical\Trends::GROWTH($yValues, $xValues, $newValues, $const);
}
self::assertEqualsWithDelta($expectedResult, $result[0], 1E-12);
}
public static function providerGROWTH(): array
{
return require 'tests/data/Calculation/Statistical/GROWTH.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/ConfidenceTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/ConfidenceTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class ConfidenceTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCONFIDENCE')]
public function testCONFIDENCE(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('CONFIDENCE', $expectedResult, ...$args);
}
public static function providerCONFIDENCE(): array
{
return require 'tests/data/Calculation/Statistical/CONFIDENCE.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerConfidenceArray')]
public function testConfidenceArray(array $expectedResult, string $alpha, string $stdDev, string $size): void
{
$calculation = Calculation::getInstance();
$formula = "=CONFIDENCE({$alpha}, {$stdDev}, {$size})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerConfidenceArray(): array
{
return [
'row/column vectors' => [
[
[0.33261691811208144, 0.6929519127335031, 1.3859038254670062],
[0.2351956783344234, 0.48999099653004874, 0.9799819930600975],
],
'0.05',
'{1.2, 2.5, 5}',
'{50; 100}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/TdotDistTrueTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/TdotDistTrueTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PHPUnit\Framework\Attributes\DataProvider;
class TdotDistTrueTest extends AllSetupTeardown
{
#[DataProvider('providerTdotDistTrue')]
public function testTdotDistTrue(mixed $expectedResult, mixed $value, mixed $degrees): void
{
$this->runTestCaseReference('T.DIST', $expectedResult, $value, $degrees, true);
}
public static function providerTdotDistTrue(): array
{
return require 'tests/data/Calculation/Statistical/tDotDistTrue.php';
}
#[DataProvider('providerTdotDistArray')]
public function testTdotDistArray(array $expectedResult, string $values, string $degrees): void
{
$calculation = Calculation::getInstance();
$formula = "=T.DIST({$values}, {$degrees}, true)";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-6);
}
public static function providerTdotDistArray(): array
{
return [
'row/column vectors' => [
[
[0.852416, 0.930337, 0.959742],
],
'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/TDistTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/TDistTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class TDistTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerTDIST')]
public function testTDIST(mixed $expectedResult, mixed $value, mixed $degrees, mixed $tails): void
{
$this->runTestCaseReference('TDIST', $expectedResult, $value, $degrees, $tails);
}
public static function providerTDIST(): array
{
return require 'tests/data/Calculation/Statistical/TDIST.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerTDistArray')]
public function testTDistArray(array $expectedResult, string $values, string $degrees, string $tails): void
{
$calculation = Calculation::getInstance();
$formula = "=TDIST({$values}, {$degrees}, {$tails})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-6);
}
public static function providerTDistArray(): array
{
return [
'row/column vectors' => [
[
[0.147584, 0.06966298427942164, 0.040258118978631297],
[0.295167, 0.13932596855884327, 0.08051623795726259],
],
'2',
'{1.5, 3.5, 8}',
'{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/Statistical/SkewTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/SkewTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PHPUnit\Framework\Attributes\DataProvider;
class SkewTest extends AllSetupTeardown
{
/** @param mixed[] $args */
#[DataProvider('providerSKEW')]
public function testSKEW(mixed $expectedResult, array $args): void
{
$this->returnArrayAs = Calculation::RETURN_ARRAY_AS_VALUE;
$this->runTestCaseReference('SKEW', $expectedResult, ...$args);
}
public static function providerSKEW(): array
{
return require 'tests/data/Calculation/Statistical/SKEW.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/LargeTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/LargeTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class LargeTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerLARGE')]
public function testLARGE(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('LARGE', $expectedResult, ...$args);
}
public static function providerLARGE(): array
{
return require 'tests/data/Calculation/Statistical/LARGE.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/ZTestTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/ZTestTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class ZTestTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerZTEST')]
public function testZTEST(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('ZTEST', $expectedResult, ...$args);
}
public static function providerZTEST(): array
{
return require 'tests/data/Calculation/Statistical/ZTEST.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerZTestArray')]
public function testZTestArray(array $expectedResult, string $dataSet, string $m0): void
{
$calculation = Calculation::getInstance();
$formula = "=ZTEST({$dataSet}, {$m0})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerZTestArray(): array
{
return [
'row vector' => [
[
[0.09057419685136381, 0.4516213175273426, 0.8630433891295299],
],
'{3, 6, 7, 8, 6, 5, 4, 2, 1, 9}',
'{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/VarTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/VarTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class VarTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerVAR')]
public function testVAR(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('VAR', $expectedResult, ...$args);
}
public static function providerVAR(): array
{
return require 'tests/data/Calculation/Statistical/VAR.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerOdsVAR')]
public function testOdsVAR(mixed $expectedResult, mixed ...$args): void
{
$this->setOpenOffice();
$this->runTestCases('VAR', $expectedResult, ...$args);
}
public static function providerOdsVAR(): array
{
return require 'tests/data/Calculation/Statistical/VAR_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/ChiDistRightTailTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/ChiDistRightTailTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class ChiDistRightTailTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCHIDIST')]
public function testCHIDIST(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('CHISQ.DIST.RT', $expectedResult, ...$args);
}
public static function providerCHIDIST(): array
{
return require 'tests/data/Calculation/Statistical/CHIDISTRightTail.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerChiDistRightTailArray')]
public function testChiDistRightTailArray(array $expectedResult, string $values, string $degrees): void
{
$calculation = Calculation::getInstance();
$formula = "=CHISQ.DIST.RT({$values}, {$degrees})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerChiDistRightTailArray(): array
{
return [
'row/column vectors' => [
[
[0.8850022316431506, 0.6599632296942824, 0.33259390259930777],
[0.9955440192247521, 0.9579789618046938, 0.7851303870304048],
],
'{3, 5, 8}',
'{7; 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/GammaLnTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GammaLnTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class GammaLnTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerGAMMALN')]
public function testGAMMALN(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('GAMMALN', $expectedResult, ...$args);
}
public static function providerGAMMALN(): array
{
return require 'tests/data/Calculation/Statistical/GAMMALN.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerGammaLnArray')]
public function testGammaLnArray(array $expectedResult, string $values): void
{
$calculation = Calculation::getInstance();
$formula = "=GAMMALN({$values})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerGammaLnArray(): array
{
return [
'matrix' => [
[['#NUM!', 1.5240638224308496], [0.20328095143131059, 2.8813232759012433]],
'{-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/TrendTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/TrendTest.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 TrendTest extends TestCase
{
/**
* @param mixed[] $yValues
* @param mixed[] $xValues
* @param null|mixed[] $newValues
*/
#[DataProvider('providerGROWTH')]
public function testTREND(mixed $expectedResult, array $yValues, array $xValues, ?array $newValues = null, ?bool $const = null): void
{
if ($newValues === null) {
$result = Statistical\Trends::TREND($yValues, $xValues);
} elseif ($const === null) {
$result = Statistical\Trends::TREND($yValues, $xValues, $newValues);
} else {
$result = Statistical\Trends::TREND($yValues, $xValues, $newValues, $const);
}
self::assertEqualsWithDelta($expectedResult, $result[0], 1E-12);
}
public static function providerGROWTH(): array
{
return require 'tests/data/Calculation/Statistical/TREND.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/AverageIfTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/AverageIfTest.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 AverageIfTest extends AllSetupTeardown
{
#[DataProvider('providerAVERAGEIF')]
public function testAVERAGEIF(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseNoBracket('AVERAGEIF', $expectedResult, ...$args);
}
public static function providerAVERAGEIF(): array
{
return require 'tests/data/Calculation/Statistical/AVERAGEIF.php';
}
public function testOutliers(): void
{
$sheet = $this->getSheet();
$sheet->getCell('C1')->setValue(5);
$sheet->getCell('A1')->setValue('=AVERAGEIF(5,"<32")');
try {
$sheet->getCell('A1')->getCalculatedValue();
self::fail('Should receive exception for non-array arg');
} catch (CalcException $e) {
self::assertStringContainsString('Must specify range of cells', $e->getMessage());
}
$sheet->getCell('A2')->setValue('=AVERAGEIF({5},"<32")');
try {
$sheet->getCell('A2')->getCalculatedValue();
self::fail('Should receive exception for literal array arg');
} catch (CalcException $e) {
self::assertStringContainsString('Must specify range of cells', $e->getMessage());
}
$sheet->getCell('A3')->setValue('=AVERAGEIF(C1:C1,"<32")');
self::assertSame(5, $sheet->getCell('A3')->getCalculatedValue(), 'first arg is single cell');
$sheet->getCell('A4')->setValue('=AVERAGEIF(#REF!,1)');
self::assertSame('#REF!', $sheet->getCell('A4')->getCalculatedValue());
$sheet->getCell('A5')->setValue('=AVERAGEIF(D1:D4, 1, #REF!)');
self::assertSame('#REF!', $sheet->getCell('A5')->getCalculatedValue());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/NormSDistTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/NormSDistTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class NormSDistTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerNORMSDIST')]
public function testNORMSDIST(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('NORMSDIST', $expectedResult, ...$args);
}
public static function providerNORMSDIST(): array
{
return require 'tests/data/Calculation/Statistical/NORMSDIST.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerNormSDistArray')]
public function testNormSDistArray(array $expectedResult, string $values): void
{
$calculation = Calculation::getInstance();
$formula = "=NORMSDIST({$values})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerNormSDistArray(): 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/RsqTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/RsqTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class RsqTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerRSQ')]
public function testRSQ(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseNoBracket('RSQ', $expectedResult, ...$args);
}
public static function providerRSQ(): array
{
return require 'tests/data/Calculation/Statistical/RSQ.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/TDist2TTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/TDist2TTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PHPUnit\Framework\Attributes\DataProvider;
class TDist2TTest extends AllSetupTeardown
{
#[DataProvider('providerTDIST2T')]
public function testTDIST2T(mixed $expectedResult, mixed $value, mixed $degrees): void
{
$this->runTestCaseReference('T.DIST.2T', $expectedResult, $value, $degrees);
}
public static function providerTDIST2T(): array
{
return require 'tests/data/Calculation/Statistical/TDIST2T.php';
}
#[DataProvider('providerTDistArray')]
public function testTDist2TArray(array $expectedResult, string $values, string $degrees): void
{
$calculation = Calculation::getInstance();
$formula = "=T.DIST.2T({$values}, {$degrees})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-6);
}
public static function providerTDistArray(): array
{
return [
'row/column vectors' => [
[
[0.295167, 0.13932596855884327, 0.08051623795726259],
],
'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/AverageATest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/AverageATest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class AverageATest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerAVERAGEA')]
public function testAVERAGEA(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('AVERAGEA', $expectedResult, ...$args);
}
public static function providerAVERAGEA(): array
{
return require 'tests/data/Calculation/Statistical/AVERAGEA.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/ChiInvRightTailTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/ChiInvRightTailTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class ChiInvRightTailTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCHIINV')]
public function testCHIINV(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('CHISQ.INV.RT', $expectedResult, ...$args);
}
public static function providerCHIINV(): array
{
return require 'tests/data/Calculation/Statistical/CHIINVRightTail.php';
}
public function invVersusDistTest(): void
{
$expectedResult = 8.383430828608;
$probability = 0.3;
$degrees = 7;
$calculation = Calculation::getInstance();
$formula = "=CHISQ.INV.RT($probability, $degrees)";
/** @var float|int|string */
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-8);
$formula = "=CHISQ.DIST.RT($result, $degrees)";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($probability, $result, 1.0e-8);
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerChiInvRightTailArray')]
public function testChiInvRightTailArray(array $expectedResult, string $probabilities, string $degrees): void
{
$calculation = Calculation::getInstance();
$formula = "=CHISQ.INV.RT({$probabilities}, {$degrees})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerChiInvRightTailArray(): array
{
return [
'row/column vectors' => [
[
[7.8061229155968075, 6.345811195521517, 100.0],
[13.266097125199911, 11.34032237742413, 24.388802783239434],
],
'{0.35, 0.5, 0.018}',
'{7; 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/LogNormDistTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/LogNormDistTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class LogNormDistTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerLOGNORMDIST')]
public function testLOGNORMDIST(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('LOGNORMDIST', $expectedResult, ...$args);
}
public static function providerLOGNORMDIST(): array
{
return require 'tests/data/Calculation/Statistical/LOGNORMDIST.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerLogNormDistArray')]
public function testLogNormDistArray(array $expectedResult, string $values, string $mean, string $stdDev): void
{
$calculation = Calculation::getInstance();
$formula = "=LOGNORMDIST({$values}, {$mean}, {$stdDev})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerLogNormDistArray(): array
{
return [
'row/column vectors' => [
[
[0.20185593420695913, 0.34805905738890675, 0.47717995703671096],
[0.06641711479920787, 0.24102205723753728, 0.45897407661978173],
[8.579368431449463E-5, 0.03941233670471267, 0.398378394299419],
],
'12',
'{10, 6, 3}',
'{9; 5; 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/TinvTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/TinvTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class TinvTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerTINV')]
public function testTINV(mixed $expectedResult, mixed $probability, mixed $degrees): void
{
$this->runTestCaseReference('TINV', $expectedResult, $probability, $degrees);
}
public static function providerTINV(): array
{
return require 'tests/data/Calculation/Statistical/TINV.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerTInvArray')]
public function testTInvArray(array $expectedResult, string $values, string $degrees): void
{
$calculation = Calculation::getInstance();
$formula = "=TINV({$values}, {$degrees})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-9);
}
public static function providerTInvArray(): array
{
return [
'row vector' => [
[
[0.612800788, 0.5023133547575189, 0.4713169827948964],
],
'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/TDistRTTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/TDistRTTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PHPUnit\Framework\Attributes\DataProvider;
class TDistRTTest extends AllSetupTeardown
{
#[DataProvider('providerTDISTRT')]
public function testTDISTRT(mixed $expectedResult, mixed $value, mixed $degrees): void
{
$this->runTestCaseReference('T.DIST.RT', $expectedResult, $value, $degrees);
}
public static function providerTDISTRT(): array
{
return require 'tests/data/Calculation/Statistical/TDISTRT.php';
}
#[DataProvider('providerTDistRTArray')]
public function testTDistRTArray(array $expectedResult, string $values, string $degrees): void
{
$calculation = Calculation::getInstance();
$formula = "=T.DIST.RT({$values}, {$degrees})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-6);
}
public static function providerTDistRTArray(): array
{
return [
'row/column vectors' => [
[
[0.147584, 0.06966298427942164, 0.040258118978631297],
],
'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/CountATest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/CountATest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
class CountATest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCOUNTA')]
public function testCOUNTA(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('COUNTA', $expectedResult, ...$args);
}
public static function providerCOUNTA(): array
{
return require 'tests/data/Calculation/Statistical/COUNTA.php';
}
public function testNull(): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', '=COUNTA(B1,B2,B3,B4)');
$sheet->setCellValue('A2', '=COUNTA(B1,,B3,B4)');
$sheet->setCellValue('A3', '=COUNTA(B1,B2,B3,B4)');
self::assertSame(0, $sheet->getCell('A1')->getCalculatedValue(), 'empty cells not counted');
self::assertSame(1, $sheet->getCell('A2')->getCalculatedValue(), 'null argument is counted');
self::assertSame(0, $sheet->getCell('A3')->getCalculatedValue(), 'empty cells still not counted');
$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/CovarTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/CovarTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class CovarTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCOVAR')]
public function testCOVAR(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseNoBracket('COVAR', $expectedResult, ...$args);
}
public static function providerCOVAR(): array
{
return require 'tests/data/Calculation/Statistical/COVAR.php';
}
public function testMultipleRows(): void
{
$sheet = $this->getSheet();
$sheet->fromArray([
[1, 2],
[3, 4],
[5, 6],
[7, 8],
]);
$sheet->getCell('Z99')->setValue('=COVAR(A1:B2,A3:B4)');
self::assertSame(1.25, $sheet->getCell('Z99')->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/BinomInvTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/BinomInvTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class BinomInvTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerBINOMINV')]
public function testBINOMINV(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('BINOM.INV', $expectedResult, ...$args);
}
public static function providerBINOMINV(): array
{
return require 'tests/data/Calculation/Statistical/BINOMINV.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerBinomInvArray')]
public function testBinomInvArray(
array $expectedResult,
string $trials,
string $probabilities,
string $alphas
): void {
$calculation = Calculation::getInstance();
$formula = "=BINOM.INV({$trials}, {$probabilities}, {$alphas})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerBinomInvArray(): array
{
return [
'row/column vectors' => [
[[32, 53], [25, 44]],
'100',
'{0.3, 0.5}',
'{0.7; 0.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/LogEstTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/LogEstTest.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 LogEstTest extends TestCase
{
/**
* @param mixed[] $yValues
* @param mixed[] $xValues
*/
#[DataProvider('providerLOGEST')]
public function testLOGEST(array $expectedResult, array $yValues, array $xValues, mixed $const, mixed $stats): void
{
$result = Statistical\Trends::LOGEST($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 providerLOGEST(): array
{
return require 'tests/data/Calculation/Statistical/LOGEST.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/NormInvTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/NormInvTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class NormInvTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerNORMINV')]
public function testNORMINV(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('NORMINV', $expectedResult, ...$args);
}
public static function providerNORMINV(): array
{
return require 'tests/data/Calculation/Statistical/NORMINV.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerNormInvArray')]
public function testNormInvArray(array $expectedResult, string $probabilities, string $mean, string $stdDev): void
{
$calculation = Calculation::getInstance();
$formula = "=NORMINV({$probabilities}, {$mean}, {$stdDev})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerNormInvArray(): array
{
return [
'row/column vectors' => [
[
[2.651020499553155, 4.651020499553155],
[1.9765307493297324, 3.9765307493297324],
[-0.7214282515639576, 1.2785717484360424],
],
'0.25',
'{4, 6}',
'{2; 3; 7}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/HypGeomDistTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/HypGeomDistTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class HypGeomDistTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerHYPGEOMDIST')]
public function testHYPGEOMDIST(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('HYPGEOMDIST', $expectedResult, ...$args);
}
public static function providerHYPGEOMDIST(): array
{
return require 'tests/data/Calculation/Statistical/HYPGEOMDIST.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerHypGeomDistArray')]
public function testHypGeomDistArray(
array $expectedResult,
string $sampleSuccesses,
string $sampleNumber,
string $populationSuccesses,
string $populationNumber
): void {
$calculation = Calculation::getInstance();
$formula = "=HYPGEOMDIST({$sampleSuccesses}, {$sampleNumber}, {$populationSuccesses}, {$populationNumber})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerHypGeomDistArray(): array
{
return [
'row/column vectors' => [
[
[0.03230668326324188, 0.11602444697599835, 2.7420710766783583E-5],
[0.00015615400269340616, 0.1000501002971324, 0.02508542192762165],
[7.763976978296478E-9, 0.0013573140575961775, 0.17007598410538344],
],
'{5, 11, 18}',
'32',
'{28; 42; 57}',
'100',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/CountBlankTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/CountBlankTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException;
class CountBlankTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCOUNTBLANK')]
public function testCOUNTBLANK(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseNoBracket('COUNTBLANK', $expectedResult, ...$args);
}
public static function providerCOUNTBLANK(): array
{
return require 'tests/data/Calculation/Statistical/COUNTBLANK.php';
}
public function testOutliers(): void
{
$sheet = $this->getSheet();
$sheet->getCell('C1')->setValue(1);
$sheet->getCell('C2')->setValue(2);
$sheet->getCell('C4')->setValue(4);
$sheet->getCell('A1')->setValue('=COUNTBLANK(5)');
try {
$sheet->getCell('A1')->getCalculatedValue();
self::fail('Should receive exception for non-array arg');
} catch (CalcException $e) {
self::assertStringContainsString('Must specify range of cells', $e->getMessage());
}
$sheet->getCell('A2')->setValue('=COUNTBLANK({1;2;4})');
try {
$sheet->getCell('A1')->getCalculatedValue();
self::fail('Should receive exception for inline array arg');
} catch (CalcException $e) {
self::assertStringContainsString('Must specify range of cells', $e->getMessage());
}
$sheet->getCell('A3')->setValue('=COUNTBLANK(C1:C1)');
self::assertSame(0, $sheet->getCell('A3')->getCalculatedValue(), 'arg is single non-blank cell');
$sheet->getCell('A4')->setValue('=COUNTBLANK(D2:D2)');
self::assertSame(1, $sheet->getCell('A4')->getCalculatedValue(), 'arg is single null cell');
$sheet->getCell('A5')->setValue('=COUNTBLANK(D3:D4)');
self::assertSame(2, $sheet->getCell('A5')->getCalculatedValue(), 'arg is two cells both null');
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/StDevPATest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/StDevPATest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class StDevPATest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerSTDEVPA')]
public function testSTDEVPA(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('STDEVPA', $expectedResult, ...$args);
}
public static function providerSTDEVPA(): array
{
return require 'tests/data/Calculation/Statistical/STDEVPA.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerOdsSTDEVPA')]
public function testOdsSTDEVPA(mixed $expectedResult, mixed ...$args): void
{
$this->setOpenOffice();
$this->runTestCaseReference('STDEVPA', $expectedResult, ...$args);
}
public static function providerOdsSTDEVPA(): array
{
return require 'tests/data/Calculation/Statistical/STDEVPA_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/VarPTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/VarPTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class VarPTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerVARP')]
public function testVARP(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('VARP', $expectedResult, ...$args);
}
public static function providerVARP(): array
{
return require 'tests/data/Calculation/Statistical/VARP.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerOdsVARP')]
public function testOdsVARP(mixed $expectedResult, mixed ...$args): void
{
$this->setOpenOffice();
$this->runTestCases('VARP', $expectedResult, ...$args);
}
public static function providerOdsVARP(): array
{
return require 'tests/data/Calculation/Statistical/VARP_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/MaxTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/MaxTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class MaxTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerMAX')]
public function testMAX(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('MAX', $expectedResult, ...$args);
}
public static function providerMAX(): array
{
return require 'tests/data/Calculation/Statistical/MAX.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/CountTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/CountTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class CountTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerBasicCOUNT')]
public function testBasicCOUNT(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseNoBracket('COUNT', $expectedResult, ...$args);
}
public static function providerBasicCOUNT(): array
{
return require 'tests/data/Calculation/Statistical/BasicCOUNT.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerExcelCOUNT')]
public function testExcelCOUNT(mixed $expectedResult, mixed ...$args): void
{
if (is_array($args[0])) {
$this->runTestCaseNoBracket('COUNT', $expectedResult, ...$args);
} else {
$this->runTestCaseDirect('COUNT', $expectedResult, ...$args);
}
}
public static function providerExcelCOUNT(): array
{
return require 'tests/data/Calculation/Statistical/ExcelCOUNT.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerOpenOfficeCOUNT')]
public function testOpenOfficeCOUNT(mixed $expectedResult, mixed ...$args): void
{
$this->setOpenOffice();
if (is_array($args[0])) {
$this->runTestCaseNoBracket('COUNT', $expectedResult, ...$args);
} else {
$this->runTestCaseDirect('COUNT', $expectedResult, ...$args);
}
}
public static function providerOpenOfficeCOUNT(): array
{
return require 'tests/data/Calculation/Statistical/OpenOfficeCOUNT.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerGnumericCOUNT')]
public function testGnumericCOUNT(mixed $expectedResult, mixed ...$args): void
{
$this->setGnumeric();
$this->runTestCaseNoBracket('COUNT', $expectedResult, ...$args);
}
public static function providerGnumericCOUNT(): array
{
return require 'tests/data/Calculation/Statistical/GnumericCOUNT.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/GammaInvTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/GammaInvTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class GammaInvTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerGAMMAINV')]
public function testGAMMAINV(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('GAMMA.INV', $expectedResult, ...$args);
}
public static function providerGAMMAINV(): array
{
return require 'tests/data/Calculation/Statistical/GAMMAINV.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerGammaInvArray')]
public function testGammaInvArray(array $expectedResult, string $values, string $alpha, string $beta): void
{
$calculation = Calculation::getInstance();
$formula = "=GAMMA.INV({$values}, {$alpha}, {$beta})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerGammaInvArray(): array
{
return [
'row/column vectors' => [
[
[2.772588722239782, 5.38526905777939, 12.548861396889375],
[5.545177444479563, 10.77053811555878, 25.09772279377875],
[6.931471805599453, 13.463172644448473, 31.372153492223436],
],
'0.75',
'{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/MaxIfsTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/MaxIfsTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class MaxIfsTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerMAXIFS')]
public function testMAXIFS(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseNoBracket('MAXIFS', $expectedResult, ...$args);
}
public static function providerMAXIFS(): array
{
return require 'tests/data/Calculation/Statistical/MAXIFS.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/ChiDistLeftTailTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/ChiDistLeftTailTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class ChiDistLeftTailTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCHIDIST')]
public function testCHIDIST(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('CHISQ.DIST', $expectedResult, ...$args);
}
public static function providerCHIDIST(): array
{
return require 'tests/data/Calculation/Statistical/CHIDISTLeftTail.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerChiDistLeftTailArray')]
public function testChiDistLeftTailArray(array $expectedResult, string $values, string $degrees): void
{
$calculation = Calculation::getInstance();
$formula = "=CHISQ.DIST({$values}, {$degrees}, false)";
/** @var float|int|string */
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerChiDistLeftTailArray(): array
{
return [
'row/column vectors' => [
[
[0.0925081978822616, 0.12204152134938745, 0.0881791375107928],
[0.007059977723446427, 0.03340047144527138, 0.07814672592526599],
],
'{3, 5, 8}',
'{7; 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/ChiInvLeftTailTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/ChiInvLeftTailTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class ChiInvLeftTailTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerCHIINV')]
public function testCHIINV(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('CHISQ.INV', $expectedResult, ...$args);
}
public static function providerCHIINV(): array
{
return require 'tests/data/Calculation/Statistical/CHIINVLeftTail.php';
}
public function invVersusDistTest(): void
{
$expectedResult = 4.671330448981;
$probability = 0.3;
$degrees = 7;
$calculation = Calculation::getInstance();
$formula = "=CHISQ.INV($probability, $degrees)";
/** @var float|int|string */
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-8);
$formula = "=CHISQ.DIST($result, $degrees)";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($probability, $result, 1.0e-8);
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerChiInvLeftTailArray')]
public function testChiInvLeftTailArray(array $expectedResult, string $probabilities, string $degrees): void
{
$calculation = Calculation::getInstance();
$formula = "=CHISQ.INV({$probabilities}, {$degrees})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerChiInvLeftTailArray(): array
{
return [
'row/column vectors' => [
[
[5.0816470296362795, 6.345811195521517, 1.508898337422818],
[9.61151737996991, 11.34032237742413, 4.0773397083341045],
],
'{0.35, 0.5, 0.018}',
'{7; 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/NegBinomDistTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/NegBinomDistTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class NegBinomDistTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerNEGBINOMDIST')]
public function testNEGBINOMDIST(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('NEGBINOMDIST', $expectedResult, ...$args);
}
public static function providerNEGBINOMDIST(): array
{
return require 'tests/data/Calculation/Statistical/NEGBINOMDIST.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerNegBinomDistArray')]
public function testNegBinomDistArray(
array $expectedResult,
string $failures,
string $successes,
string $probabilities
): void {
$calculation = Calculation::getInstance();
$formula = "=NEGBINOMDIST({$failures}, {$successes}, {$probabilities})";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerNegBinomDistArray(): array
{
return [
'row/column vectors' => [
[[0.07508468627929688, 0.04301726818084717], [0.04503981303423643, 0.05629976629279554]],
'{7; 12}',
'{3, 5}',
'0.25',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/VarPATest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/VarPATest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class VarPATest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerVARPA')]
public function testVARPA(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('VARPA', $expectedResult, ...$args);
}
public static function providerVARPA(): array
{
return require 'tests/data/Calculation/Statistical/VARPA.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerOdsVARPA')]
public function testOdsVARPA(mixed $expectedResult, mixed ...$args): void
{
$this->setOpenOffice();
$this->runTestCases('VARPA', $expectedResult, ...$args);
}
public static function providerOdsVARPA(): array
{
return require 'tests/data/Calculation/Statistical/VARPA_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/StDevTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/StDevTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class StDevTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerSTDEV')]
public function testSTDEV(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseReference('STDEV', $expectedResult, ...$args);
}
public static function providerSTDEV(): array
{
return require 'tests/data/Calculation/Statistical/STDEV.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerOdsSTDEV')]
public function testOdsSTDEV(mixed $expectedResult, mixed ...$args): void
{
$this->setOpenOffice();
$this->runTestCaseReference('STDEV', $expectedResult, ...$args);
}
public static function providerOdsSTDEV(): array
{
return require 'tests/data/Calculation/Statistical/STDEV_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/VarATest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/VarATest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class VarATest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerVARA')]
public function testVARA(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('VARA', $expectedResult, ...$args);
}
public static function providerVARA(): array
{
return require 'tests/data/Calculation/Statistical/VARA.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerOdsVARA')]
public function testOdsVARA(mixed $expectedResult, mixed ...$args): void
{
$this->setOpenOffice();
$this->runTestCases('VARA', $expectedResult, ...$args);
}
public static function providerOdsVARA(): array
{
return require 'tests/data/Calculation/Statistical/VARA_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/NormDistTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/NormDistTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class NormDistTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerNORMDIST')]
public function testNORMDIST(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('NORMDIST', $expectedResult, ...$args);
}
public static function providerNORMDIST(): array
{
return require 'tests/data/Calculation/Statistical/NORMDIST.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerNormDistArray')]
public function testNormDistArray(array $expectedResult, string $values, string $mean, string $stdDev): void
{
$calculation = Calculation::getInstance();
$formula = "=NORMDIST({$values}, {$mean}, {$stdDev}, false)";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerNormDistArray(): array
{
return [
'row/column vectors' => [
[
[0.04324582990797181, 0.03549422283581691, 0.026885636057682592],
[0.07365402806066465, 0.038837210996642585, 0.015790031660178828],
[0.12098536225957167, 0.0022159242059690033, 7.991870553452737E-6],
],
'12',
'{10, 6, 3}',
'{9; 5; 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/AveDevTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/AveDevTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class AveDevTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerAVEDEV')]
public function testAVEDEV(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('AVEDEV', $expectedResult, ...$args);
}
public static function providerAVEDEV(): array
{
return require 'tests/data/Calculation/Statistical/AVEDEV.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/ModeTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/ModeTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;
class ModeTest extends TestCase
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerMODE')]
public function testMODE(mixed $expectedResult, string $str): void
{
$workbook = new Spreadsheet();
$sheet = $workbook->getActiveSheet();
$row = 1;
$sheet->setCellValue("B$row", "=MODE($str)");
$sheet->setCellValue("C$row", "=MODE.SNGL($str)");
self::assertEquals($expectedResult, $sheet->getCell("B$row")->getCalculatedValue());
self::assertEquals($expectedResult, $sheet->getCell("C$row")->getCalculatedValue());
}
public static function providerMODE(): array
{
return require 'tests/data/Calculation/Statistical/MODE.php';
}
public function testMODENoArgs(): void
{
$this->expectException(\PhpOffice\PhpSpreadsheet\Calculation\Exception::class);
$workbook = new Spreadsheet();
$sheet = $workbook->getActiveSheet();
$sheet->setCellValue('B1', '=MODE()');
self::assertEquals('#N/A', $sheet->getCell('B1')->getCalculatedValue());
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/ExponDistTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/ExponDistTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class ExponDistTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerEXPONDIST')]
public function testEXPONDIST(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCases('EXPONDIST', $expectedResult, ...$args);
}
public static function providerEXPONDIST(): array
{
return require 'tests/data/Calculation/Statistical/EXPONDIST.php';
}
#[\PHPUnit\Framework\Attributes\DataProvider('providerExponDistArray')]
public function testExponDistArray(array $expectedResult, string $values, string $lambdas): void
{
$calculation = Calculation::getInstance();
$formula = "=EXPONDIST({$values}, {$lambdas}, false)";
$result = $calculation->calculateFormula($formula);
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
}
public static function providerExponDistArray(): array
{
return [
'row/column vectors' => [
[
[1.646434908282079, 0.6693904804452895, 0.2721538598682374],
[1.353352832366127, 0.06737946999085467, 0.003354626279025118],
],
'{0.2, 0.5, 0.8}',
'{3; 10}',
],
];
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
PHPOffice/PhpSpreadsheet | https://github.com/PHPOffice/PhpSpreadsheet/blob/e33834b4ea2a02088becbb41fb8954d915b46b12/tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/SlopeTest.php | tests/PhpSpreadsheetTests/Calculation/Functions/Statistical/SlopeTest.php | <?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
class SlopeTest extends AllSetupTeardown
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerSLOPE')]
public function testSLOPE(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCaseNoBracket('SLOPE', $expectedResult, ...$args);
}
public static function providerSLOPE(): array
{
return require 'tests/data/Calculation/Statistical/SLOPE.php';
}
}
| php | MIT | e33834b4ea2a02088becbb41fb8954d915b46b12 | 2026-01-04T15:02:44.305364Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.