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

57 lines
1.7 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests\Functional;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
class SelectedCellsTest extends AbstractFunctional
{
public static function providerFormats(): array
{
return [
['Xls'],
];
}
/**
* Test load file with correct selected cells.
*/
#[\PHPUnit\Framework\Attributes\DataProvider('providerFormats')]
public function testSelectedCells(string $format): void
{
$spreadsheet = new Spreadsheet();
$spreadsheet->setActiveSheetIndex(0)
->setTitle('Test1')
->setCellValue('D1', 1)
->setCellValue('D2', 2)
->setCellValue('D3', 3)
->setCellValue('D4', 4)
->setCellValue('D5', '=SUM(D1:D4)')
->setSelectedCell('B2');
$spreadsheet->createSheet(1);
$spreadsheet->setActiveSheetIndex(1)
->setTitle('Test2')
->setCellValue('D1', 4)
->setCellValue('E1', 3)
->setCellValue('F1', 2)
->setCellValue('G1', 1)
->setCellValue('H1', '=SUM(D1:G4)')
->setSelectedCells('A1:B2');
$reloadedSpreadsheet = $this->writeAndReload($spreadsheet, $format);
// Original object.
self::assertSame('B2', $spreadsheet->setActiveSheetIndex(0)->getSelectedCells());
self::assertSame('A1:B2', $spreadsheet->setActiveSheetIndex(1)->getSelectedCells());
// Saved and reloaded file.
self::assertSame('B2', $reloadedSpreadsheet->setActiveSheetIndex(0)->getSelectedCells());
self::assertSame('A1:B2', $reloadedSpreadsheet->setActiveSheetIndex(1)->getSelectedCells());
}
}