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

58 lines
1.9 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PHPUnit\Framework\Attributes\DataProvider;
class TextJoinTest extends AllSetupTeardown
{
/** @param mixed[] $args */
#[DataProvider('providerTEXTJOIN')]
public function testTEXTJOIN(mixed $expectedResult, array $args): void
{
$this->mightHaveException($expectedResult);
$sheet = $this->getSheet();
$b1Formula = '=TEXTJOIN(';
$comma = '';
$row = 0;
foreach ($args as $arg) {
++$row;
$this->setCell("A$row", $arg);
$b1Formula .= $comma . "A$row";
$comma = ',';
}
$b1Formula .= ')';
$this->setCell('B1', $b1Formula);
$result = $sheet->getCell('B1')->getCalculatedValue();
self::assertEquals($expectedResult, $result);
}
public static function providerTEXTJOIN(): array
{
return require 'tests/data/Calculation/TextData/TEXTJOIN.php';
}
/** @param mixed[] $expectedResult */
#[DataProvider('providerTextjoinArray')]
public function testTextjoinArray(array $expectedResult, string $delimiter, string $blanks, string $texts): void
{
$calculation = Calculation::getInstance();
$formula = "=TEXTJOIN({$delimiter}, {$blanks}, {$texts})";
$result = $calculation->calculateFormula($formula);
self::assertSame($expectedResult, $result);
}
public static function providerTextjoinArray(): array
{
return [
'row vector #1' => [[['AB,CD,EF', 'AB;CD;EF']], '{",", ";"}', 'FALSE', '"AB", "CD", "EF"'],
'column vector #1' => [[['AB--CD--EF'], ['AB|CD|EF']], '{"--"; "|"}', 'FALSE', '"AB", "CD", "EF"'],
'matrix #1' => [[['AB,CD,EF', 'AB;CD;EF'], ['AB-CD-EF', 'AB|CD|EF']], '{",", ";"; "-", "|"}', 'FALSE', '"AB", "CD", "EF"'],
];
}
}