mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-05 23:18:49 +00:00
3697352e28
* Fix Unintential Deprecated Calls in Tests - LOGICAL I think it's best to install these before PR #3166. There are no changes to source code, only to doc-blocks and to test members which continue to inadvertently use calls to deprecated functions. * Change Unit Tests to Run in Spreadsheet Context They had been run as direct calls, which is not how most users would use them. Making this change exposed some minor coding errors - SWITCH needs to flatten its arguments, and IFERROR and IFNA were not handling a null testValue in the same manner as Excel.
64 lines
1.6 KiB
PHP
64 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
|
|
|
|
class SwitchTest extends AllSetupTeardown
|
|
{
|
|
/**
|
|
* @dataProvider providerSwitch
|
|
*
|
|
* @param mixed $expectedResult
|
|
*/
|
|
public function testSWITCH($expectedResult, ...$args): void
|
|
{
|
|
$this->runTestCase('SWITCH', $expectedResult, ...$args);
|
|
}
|
|
|
|
public function providerSwitch(): array
|
|
{
|
|
return require 'tests/data/Calculation/Logical/SWITCH.php';
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerSwitchArray
|
|
*
|
|
* @param mixed $expression
|
|
* @param mixed $value1
|
|
* @param mixed $value2
|
|
*/
|
|
public function testIfsArray(array $expectedResult, $expression, $value1, string $result1, $value2, string $result2, string $default): void
|
|
{
|
|
$calculation = Calculation::getInstance();
|
|
|
|
$formula = "=SWITCH($expression, $value1, {" . "$result1}, $value2, {" . "$result2}, {" . "$default})";
|
|
$result = $calculation->_calculateFormulaValue($formula);
|
|
self::assertEquals($expectedResult, $result);
|
|
}
|
|
|
|
public function providerSwitchArray(): array
|
|
{
|
|
return [
|
|
'Array return' => [
|
|
[[4, 5, 6]],
|
|
2,
|
|
1,
|
|
'1, 2, 3',
|
|
2,
|
|
'4, 5, 6',
|
|
'7, 8, 9',
|
|
],
|
|
'Array return default' => [
|
|
[[7, 8, 9]],
|
|
3,
|
|
1,
|
|
'1, 2, 3',
|
|
2,
|
|
'4, 5, 6',
|
|
'7, 8, 9',
|
|
],
|
|
];
|
|
}
|
|
}
|