mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-02 13:41:21 +00:00
3dcdbcac3e
Its use is already causes an issue with Phpstan. It uses interfaces marked as internal by Phpunit, and it will not work with Phpunit 12. It is more complicated than needed. This PR corrects all these problems. It also corrects a handful of other problems that will show up with Phpunit 12. Only tests are changed - no source code.
53 lines
1.7 KiB
PHP
53 lines
1.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
|
|
|
|
class IrrTest extends AllSetupTeardown
|
|
{
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providerIRR')]
|
|
public function testIRR(mixed $expectedResult, mixed $values = null, mixed $guess = null): void
|
|
{
|
|
$this->mightHaveException($expectedResult);
|
|
$sheet = $this->getSheet();
|
|
$formula = '=IRR(';
|
|
if ($values !== null) {
|
|
if (is_array($values)) {
|
|
$row = 0;
|
|
foreach ($values as $value) {
|
|
if (is_array($value)) {
|
|
foreach ($value as $arrayValue) {
|
|
++$row;
|
|
$sheet->getCell("A$row")->setValue($arrayValue);
|
|
}
|
|
} else {
|
|
++$row;
|
|
$sheet->getCell("A$row")->setValue($value);
|
|
}
|
|
}
|
|
$formula .= "A1:A$row";
|
|
} else {
|
|
$sheet->getCell('A1')->setValue($values);
|
|
$formula .= 'A1';
|
|
}
|
|
}
|
|
if ($guess !== null) {
|
|
$formula .= ',' . StringHelper::convertToString($guess);
|
|
}
|
|
$formula .= ')';
|
|
$sheet->getCell('D1')->setValue($formula);
|
|
$result = $sheet->getCell('D1')->getCalculatedValue();
|
|
$this->adjustResult($result, $expectedResult);
|
|
|
|
self::assertEqualsWithDelta($expectedResult, $result, 0.1E-8);
|
|
}
|
|
|
|
public static function providerIRR(): array
|
|
{
|
|
return require 'tests/data/Calculation/Financial/IRR.php';
|
|
}
|
|
}
|