Files
oleibman d647fe7ee7 Use Php Attributes Rather than Annotations for PhpUnit
With PhpUnit 10 came the ability to use Php attributes rather than doc-block annotations for things like "data provider". PhpUnit 11 deprecates the use of annotations, and PhpUnit 12 will not not permit their use. Since PhpUnit 11 requires Php8.2+, we cannot adopt it as long as we support Php8.1, which will continue to be the case for some time. However, there is no penalty for early adoption.

Php-cs-fixer can use:
```
'php_unit_attributes' => ['keep_annotations' => false],
```
This allows us to run `composer fix` to automate all the needed changes. No manual changes were needed for any of the test members.

With this change, PhpUnit 9 can no longer be used with the test suite. File composer.json is updated to reflect that reality, and phpunit9.xml.dist, which has been supplied in case anyone needed to use PhpUnit 9, is no longer required, and is thus deleted. For now, PhpUnit 11 is not being added as a possibility.

No source code is changed in this PR.
2024-11-23 20:56:26 -08:00

61 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalcExp;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PHPUnit\Framework\TestCase;
class MissingArgumentsTest extends TestCase
{
#[\PHPUnit\Framework\Attributes\DataProvider('providerMissingArguments')]
public function testMissingArguments(mixed $expected, string $formula): void
{
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->getCell('A1')->setValue($formula);
$sheet->getCell('B1')->setValue(1);
try {
self::assertSame($expected, $sheet->getCell('A1')->getCalculatedValue());
} catch (CalcExp $e) {
self::assertSame('exception', $expected);
}
$spreadsheet->disconnectWorksheets();
}
public static function providerMissingArguments(): array
{
return [
'argument missing at end' => [0, '=min(3,2,)'],
'argument missing at beginning' => [0, '=mina(,3,2)'],
'argument missing in middle' => [0, '=min(3,,2)'],
'missing argument is not result' => [-2, '=min(3,-2,)'],
'max with missing argument' => [0, '=max(-3,-2,)'],
'maxa with missing argument' => [0, '=maxa(-3,-2,)'],
'max with null cell' => [-2, '=max(-3,-2,Z1)'],
'min with null cell' => [2, '=min(3,2,Z1)'],
'product ignores null argument' => [6.0, '=product(3,2,)'],
'embedded function' => [5, '=sum(3,2,min(3,2,))'],
'unaffected embedded function' => [8, '=sum(3,2,max(3,2,))'],
'if true missing at end' => [0, '=if(b1=1,min(3,2,),product(3,2,))'],
'if false missing at end' => [6.0, '=if(b1=2,min(3,2,),product(3,2,))'],
'if true missing in middle' => [0, '=if(b1=1,min(3,,2),product(3,,2))'],
'if false missing in middle' => [6.0, '=if(b1=2,min(3,,2),product(3,,2))'],
'if true missing at beginning' => [0, '=if(b1=1,min(,3,2),product(,3,2))'],
'if false missing at beginning' => [6.0, '=if(b1=2,min(,3,2),product(,3,2))'],
'if true nothing missing' => [2, '=if(b1=1,min(3,2),product(3,2))'],
'if false nothing missing' => [6.0, '=if(b1=2,min(3,2),product(3,2))'],
'if true empty arg' => [0, '=if(b1=1,)'],
'if true omitted args' => ['exception', '=if(b1=1)'],
'if true missing arg' => [0, '=if(b1=1,,6)'],
'if false missing arg' => [0, '=if(b1=2,6,)'],
'if false omitted arg' => [false, '=if(b1=2,6)'],
'multiple ifs and omissions' => [0, '=IF(0<9,,IF(0=0,,1))'],
];
}
}