Files
PhpSpreadsheet/tests/PhpSpreadsheetTests/Calculation/Functions/Financial/XirrTest.php
T
Mark Baker 5d309e982c Extract remaining Excel function unit tests into separate test classes for each function (#1817)
* Extract remaining Financial function unit tests into separate test classes for each function

This makes it easier to manage unit tests if they are individual files rather than all in a single file

It also provides a stepping stone toward making it easier to test Excel functions when Excel errors no longer return a string, but an actual Excel exception that can be handled more cleanly
2021-01-31 15:09:56 +01:00

41 lines
1.1 KiB
PHP

<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase;
class XirrTest extends TestCase
{
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerXIRR
*
* @param mixed $expectedResult
* @param mixed $message
*/
public function testXIRR($expectedResult, $message, ...$args): void
{
$result = Financial::XIRR(...$args);
if (is_numeric($result) && is_numeric($expectedResult)) {
if ($expectedResult != 0) {
$frac = $result / $expectedResult;
if ($frac > 0.999999 && $frac < 1.000001) {
$result = $expectedResult;
}
}
}
self::assertEquals($expectedResult, $result, $message);
}
public function providerXIRR()
{
return require 'tests/data/Calculation/Financial/XIRR.php';
}
}