mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-01 13:08:50 +00:00
d647fe7ee7
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.
82 lines
4.4 KiB
PHP
82 lines
4.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
|
|
|
|
use PhpOffice\PhpSpreadsheet\Spreadsheet;
|
|
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
|
|
use PHPUnit\Framework\TestCase;
|
|
|
|
class RowColumnReferenceTest extends TestCase
|
|
{
|
|
protected Spreadsheet $spreadSheet;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
$this->spreadSheet = new Spreadsheet();
|
|
|
|
$dataSheet = new Worksheet($this->spreadSheet, 'data sheet');
|
|
$this->spreadSheet->addSheet($dataSheet, 0);
|
|
$dataSheet->setCellValue('B1', 1.1);
|
|
$dataSheet->setCellValue('B2', 2.2);
|
|
$dataSheet->setCellValue('B3', 4.4);
|
|
$dataSheet->setCellValue('C3', 8.8);
|
|
$dataSheet->setCellValue('D3', 16.16);
|
|
|
|
$calcSheet = new Worksheet($this->spreadSheet, 'summary sheet');
|
|
$this->spreadSheet->addSheet($calcSheet, 1);
|
|
$calcSheet->setCellValue('B1', 2.2);
|
|
$calcSheet->setCellValue('B2', 4.4);
|
|
$calcSheet->setCellValue('B3', 8.8);
|
|
$calcSheet->setCellValue('C3', 16.16);
|
|
$calcSheet->setCellValue('D3', 32.32);
|
|
|
|
$this->spreadSheet->setActiveSheetIndexByName('summary sheet');
|
|
}
|
|
|
|
#[\PHPUnit\Framework\Attributes\DataProvider('providerCurrentWorksheetFormulae')]
|
|
public function testCurrentWorksheet(string $formula, float $expectedResult): void
|
|
{
|
|
$worksheet = $this->spreadSheet->getActiveSheet();
|
|
|
|
$worksheet->setCellValue('A1', $formula);
|
|
|
|
$result = $worksheet->getCell('A1')->getCalculatedValue();
|
|
self::assertEqualsWithDelta($expectedResult, $result, 1.0e-12);
|
|
}
|
|
|
|
public static function providerCurrentWorksheetFormulae(): array
|
|
{
|
|
return [
|
|
'relative range in active worksheet' => ['=SUM(B1:B3)', 15.4],
|
|
'range with absolute columns in active worksheet' => ['=SUM($B1:$B3)', 15.4],
|
|
'range with absolute rows in active worksheet' => ['=SUM(B$1:B$3)', 15.4],
|
|
'range with absolute columns and rows in active worksheet' => ['=SUM($B$1:$B$3)', 15.4],
|
|
'another relative range in active worksheet' => ['=SUM(B3:D3)', 57.28],
|
|
'relative column range in active worksheet' => ['=SUM(B:B)', 15.4],
|
|
'absolute column range in active worksheet' => ['=SUM($B:$B)', 15.4],
|
|
'relative row range in active worksheet' => ['=SUM(3:3)', 57.28],
|
|
'absolute row range in active worksheet' => ['=SUM($3:$3)', 57.28],
|
|
'relative range in specified active worksheet' => ['=SUM(\'summary sheet\'!B1:B3)', 15.4],
|
|
'range with absolute columns in specified active worksheet' => ['=SUM(\'summary sheet\'!$B1:$B3)', 15.4],
|
|
'range with absolute rows in specified active worksheet' => ['=SUM(\'summary sheet\'!B$1:B$3)', 15.4],
|
|
'range with absolute columns and rows in specified active worksheet' => ['=SUM(\'summary sheet\'!$B$1:$B$3)', 15.4],
|
|
'another relative range in specified active worksheet' => ['=SUM(\'summary sheet\'!B3:D3)', 57.28],
|
|
'relative column range in specified active worksheet' => ['=SUM(\'summary sheet\'!B:B)', 15.4],
|
|
'absolute column range in specified active worksheet' => ['=SUM(\'summary sheet\'!$B:$B)', 15.4],
|
|
'relative row range in specified active worksheet' => ['=SUM(\'summary sheet\'!3:3)', 57.28],
|
|
'absolute row range in specified active worksheet' => ['=SUM(\'summary sheet\'!$3:$3)', 57.28],
|
|
'relative range in specified other worksheet' => ['=SUM(\'data sheet\'!B1:B3)', 7.7],
|
|
'range with absolute columns in specified other worksheet' => ['=SUM(\'data sheet\'!$B1:$B3)', 7.7],
|
|
'range with absolute rows in specified other worksheet' => ['=SUM(\'data sheet\'!B$1:B$3)', 7.7],
|
|
'range with absolute columns and rows in specified other worksheet' => ['=SUM(\'data sheet\'!$B$1:$B$3)', 7.7],
|
|
'another relative range in specified other worksheet' => ['=SUM(\'data sheet\'!B3:D3)', 29.36],
|
|
'relative column range in specified other worksheet' => ['=SUM(\'data sheet\'!B:B)', 7.7],
|
|
'absolute column range in specified other worksheet' => ['=SUM(\'data sheet\'!$B:$B)', 7.7],
|
|
'relative row range in specified other worksheet' => ['=SUM(\'data sheet\'!3:3)', 29.36],
|
|
'absolute row range in specified other worksheet' => ['=SUM(\'data sheet\'!$3:$3)', 29.36],
|
|
];
|
|
}
|
|
}
|