Files
oleibman 70b4ecd4d3 Use calculateFormula Rather Than _calculateFormulaValue in Tests
They aren't quite interchangeable. Both are used in the test suite, with no indication of why one or the other. I think we'd be best off being consistent. Based on the names, I think `_calculateFormulaValue` was intended as a private, or at least internal, method, so favor `calculateFormula`. I do not intend to rename or re-categorize `_calculateFormulaValue`, just remove its usage when it isn't clearly warranted.
2025-11-13 20:48:46 -08:00

52 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PHPUnit\Framework\Attributes\DataProvider;
class TTest extends AllSetupTeardown
{
/** @param mixed[] $expectedResult */
#[DataProvider('providerT')]
public function testT(mixed $expectedResult, mixed $value = 'no arguments'): void
{
$this->mightHaveException($expectedResult);
if ($value === 'no arguments') {
$this->setCell('H1', '=T()');
} else {
$this->setCell('A1', $value);
$this->setCell('H1', '=T(A1)');
}
$result = $this->getSheet()->getCell('H1')->getCalculatedValue();
self::assertSame($expectedResult, $result);
}
public static function providerT(): array
{
return require 'tests/data/Calculation/TextData/T.php';
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerTArray')]
public function testTArray(array $expectedResult, string $argument): void
{
$calculation = Calculation::getInstance();
$formula = "=T({$argument})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
public static function providerTArray(): array
{
return [
'row vector #1' => [[['PHP', '', 'PHP8']], '{"PHP", 99, "PHP8"}'],
'column vector #1' => [[[''], ['PHP'], ['']], '{12; "PHP"; 1.2}'],
'matrix #1' => [[['TRUE', 'FALSE'], ['', '']], '{"TRUE", "FALSE"; TRUE, FALSE}'],
];
}
}