Skip to content

Commit e580f10

Browse files
author
Mark Baker
authored
Unit test some basic arra-formula chaining (#2599)
1 parent 03993bc commit e580f10

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
4+
5+
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
6+
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class ArrayFormulaTest extends TestCase
10+
{
11+
/**
12+
* @var string
13+
*/
14+
private $compatibilityMode;
15+
16+
/**
17+
* @var string
18+
*/
19+
private $locale;
20+
21+
protected function setUp(): void
22+
{
23+
$this->compatibilityMode = Functions::getCompatibilityMode();
24+
$calculation = Calculation::getInstance();
25+
$this->locale = $calculation->getLocale();
26+
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
27+
}
28+
29+
protected function tearDown(): void
30+
{
31+
Functions::setCompatibilityMode($this->compatibilityMode);
32+
$calculation = Calculation::getInstance();
33+
$calculation->setLocale($this->locale);
34+
}
35+
36+
/**
37+
* @dataProvider providerArrayFormulae
38+
*
39+
* @param mixed $expectedResult
40+
*/
41+
public function testArrayFormula(string $formula, $expectedResult): void
42+
{
43+
$result = Calculation::getInstance()->_calculateFormulaValue($formula);
44+
self::assertEquals($expectedResult, $result);
45+
}
46+
47+
public function providerArrayFormulae(): array
48+
{
49+
return [
50+
[
51+
'=MAX(ABS({-3, 4, -2; 6, -3, -12}))',
52+
12,
53+
],
54+
[
55+
'=SUM(SEQUENCE(3,3,0,1))',
56+
36,
57+
],
58+
];
59+
}
60+
}

0 commit comments

Comments
 (0)