Files
PhpSpreadsheet/tests/PhpSpreadsheetTests/Calculation/Functions/Logical/SwitchTest.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

60 lines
1.6 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class SwitchTest extends AllSetupTeardown
{
/**
* @dataProvider providerSwitch
*/
public function testSWITCH(mixed $expectedResult, mixed ...$args): void
{
$this->runTestCase('SWITCH', $expectedResult, ...$args);
}
public static function providerSwitch(): array
{
return require 'tests/data/Calculation/Logical/SWITCH.php';
}
/**
* @dataProvider providerSwitchArray
*/
public function testIfsArray(array $expectedResult, mixed $expression, mixed $value1, string $result1, mixed $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 static 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',
],
];
}
}