Files
PhpSpreadsheet/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/ValueTest.php
T
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

88 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
class ValueTest extends AllSetupTeardown
{
/**
* @var string
*/
private $currencyCode;
/**
* @var string
*/
private $decimalSeparator;
/**
* @var string
*/
private $thousandsSeparator;
protected function setUp(): void
{
parent::setUp();
$this->currencyCode = StringHelper::getCurrencyCode();
$this->decimalSeparator = StringHelper::getDecimalSeparator();
$this->thousandsSeparator = StringHelper::getThousandsSeparator();
}
protected function tearDown(): void
{
parent::tearDown();
StringHelper::setCurrencyCode($this->currencyCode);
StringHelper::setDecimalSeparator($this->decimalSeparator);
StringHelper::setThousandsSeparator($this->thousandsSeparator);
}
/**
* @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';
}
/**
* @dataProvider providerValueArray
*/
public function testValueArray(array $expectedResult, string $argument): void
{
$calculation = Calculation::getInstance();
$formula = "=VALUE({$argument})";
$result = $calculation->_calculateFormulaValue($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"}'],
];
}
}