mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-03 14:10:27 +00:00
70b4ecd4d3
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.
63 lines
1.9 KiB
PHP
63 lines
1.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
|
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
|
|
class ValueTest extends AllSetupTeardown
|
|
{
|
|
protected function tearDown(): void
|
|
{
|
|
parent::tearDown();
|
|
StringHelper::setCurrencyCode(null);
|
|
StringHelper::setDecimalSeparator(null);
|
|
StringHelper::setThousandsSeparator(null);
|
|
}
|
|
|
|
#[DataProvider('providerVALUE')]
|
|
public function testVALUE(mixed $expectedResult, mixed $value = 'omitted'): void
|
|
{
|
|
StringHelper::setDecimalSeparator('.');
|
|
StringHelper::setThousandsSeparator(' ');
|
|
StringHelper::setCurrencyCode('$');
|
|
|
|
$this->mightHaveException($expectedResult);
|
|
$sheet = $this->getSheet();
|
|
if ($value === 'omitted') {
|
|
$sheet->getCell('B1')->setValue('=VALUE()');
|
|
} else {
|
|
$this->setCell('A1', $value);
|
|
$sheet->getCell('B1')->setValue('=VALUE(A1)');
|
|
}
|
|
$result = $sheet->getCell('B1')->getCalculatedValue();
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1E-8);
|
|
}
|
|
|
|
public static function providerVALUE(): array
|
|
{
|
|
return require 'tests/data/Calculation/TextData/VALUE.php';
|
|
}
|
|
|
|
/** @param mixed[] $expectedResult */
|
|
#[DataProvider('providerValueArray')]
|
|
public function testValueArray(array $expectedResult, string $argument): void
|
|
{
|
|
$calculation = Calculation::getInstance();
|
|
|
|
$formula = "=VALUE({$argument})";
|
|
$result = $calculation->calculateFormula($formula);
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-14);
|
|
}
|
|
|
|
public static function providerValueArray(): array
|
|
{
|
|
return [
|
|
'row vector' => [[[44604, -1234.567]], '{"12-Feb-2022", "$ -1,234.567"}'],
|
|
];
|
|
}
|
|
}
|