Files
oleibman 3697352e28 Fix Unintential Deprecated Calls in Tests - LOGICAL (#3178)
* 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.
2022-11-23 07:49:28 -08:00

52 lines
1.3 KiB
PHP

<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Logical;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
class IfErrorTest extends AllSetupTeardown
{
/**
* @dataProvider providerIFERROR
*
* @param mixed $expectedResult
*/
public function testIFERROR($expectedResult, ...$args): void
{
$this->runTestCase('IFERROR', $expectedResult, ...$args);
}
public function providerIFERROR(): array
{
return require 'tests/data/Calculation/Logical/IFERROR.php';
}
/**
* @dataProvider providerIfErrorArray
*/
public function testIfErrorArray(array $expectedResult, string $argument1, string $argument2): void
{
$calculation = Calculation::getInstance();
$formula = "=IFERROR({$argument1}, {$argument2})";
$result = $calculation->_calculateFormulaValue($formula);
self::assertEquals($expectedResult, $result);
}
public function providerIfErrorArray(): array
{
return [
'vector' => [
[[2.5, 6]],
'{5/2, 5/0}',
'MAX(ABS({-2,4,-6}))',
],
'return value' => [
[[2.5, [[2, 3, 4]]]],
'{5/2, 5/0}',
'{2,3,4}',
],
];
}
}