mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-24 15:08:33 +00:00
ec4098c8fd
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.
59 lines
1.9 KiB
PHP
59 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
|
|
|
class TextJoinTest extends AllSetupTeardown
|
|
{
|
|
/**
|
|
* @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';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerTextjoinArray
|
|
*/
|
|
public function testTextjoinArray(array $expectedResult, string $delimiter, string $blanks, string $texts): void
|
|
{
|
|
$calculation = Calculation::getInstance();
|
|
|
|
$formula = "=TEXTJOIN({$delimiter}, {$blanks}, {$texts})";
|
|
$result = $calculation->_calculateFormulaValue($formula);
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
|
|
}
|
|
|
|
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"'],
|
|
];
|
|
}
|
|
}
|