Files
Adrien Crivelli ec4098c8fd Strict mode for all tests
While we might never be able to have 100% of our code strict, we can at
the very least do it for all of our tests. This ensures that our tests
are using our API with the types as intended by the test author, and not
silently be cast to what our API requires.
2023-09-07 17:44:56 +08:00

52 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcException;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;
class CyclicTest extends TestCase
{
public function testCyclicReference(): void
{
// Issue 3169
$spreadsheet = new Spreadsheet();
$table_data = [
['abc', 'def', 'ghi'],
['1', '4', '=B3+A3'],
['=SUM(A2:C2)', '2', '=A2+B2'],
];
// Don't allow cyclic references.
Calculation::getInstance($spreadsheet)->cyclicFormulaCount = 0;
$worksheet = $spreadsheet->getActiveSheet();
$worksheet->fromArray($table_data, '');
try {
$result = $worksheet->getCell('C2')->getCalculatedValue();
} catch (CalcException $e) {
$result = $e->getMessage();
}
self::assertSame(
'Worksheet!C2 -> Worksheet!A3 -> Worksheet!C2 -> Cyclic Reference in Formula',
$result
);
try {
$result = $worksheet->getCell('A3')->getCalculatedValue();
} catch (CalcException $e) {
$result = $e->getMessage();
}
self::assertSame(
'Worksheet!A3 -> Worksheet!C2 -> Worksheet!A3 -> Cyclic Reference in Formula',
$result
);
$spreadsheet->disconnectWorksheets();
}
}