mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-27 10:30:02 +00:00
d27b6a672a
Scrutinizer had previously suggested annotations for 3 LookupRef tests, but it no longer accepts its own annotation for those cases. This PR cleans them up. ColumnsTest and RowsTest are extremely straightforward. IndexTest is a bit more complicated, but only because, unlike the other two, it had no test which executed in the context of a spreadsheet. And, when I added those, I discovered a couple of bugs. INDEX always requires at least 2 parameters (row# is always required), but its entry in the function table specified 1-4 parameters, now changed to 2-4. And, omitting col# is not handled the same way as specifying 0 for col#, though the code had treated them identically. (The same would have been true for row# but, because it is now required, ...)
40 lines
1.3 KiB
PHP
40 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
|
|
|
|
class IndexOnSpreadsheetTest extends AllSetupTeardown
|
|
{
|
|
/**
|
|
* @dataProvider providerINDEXonSpreadsheet
|
|
*
|
|
* @param mixed $expectedResult
|
|
* @param null|int|string $rowNum
|
|
* @param null|int|string $colNum
|
|
*/
|
|
public function testIndexOnSpreadsheet($expectedResult, array $matrix, $rowNum = null, $colNum = null): void
|
|
{
|
|
$this->mightHaveException($expectedResult);
|
|
$sheet = $this->getSheet();
|
|
$sheet->fromArray($matrix);
|
|
$maxRow = $sheet->getHighestRow();
|
|
$maxColumn = $sheet->getHighestColumn();
|
|
$formulaArray = "A1:$maxColumn$maxRow";
|
|
if ($rowNum === null) {
|
|
$formula = "=INDEX($formulaArray)";
|
|
} elseif ($colNum === null) {
|
|
$formula = "=INDEX($formulaArray, $rowNum)";
|
|
} else {
|
|
$formula = "=INDEX($formulaArray, $rowNum, $colNum)";
|
|
}
|
|
$sheet->getCell('ZZ98')->setValue('x');
|
|
$sheet->getCell('ZZ99')->setValue($formula);
|
|
$result = $sheet->getCell('ZZ99')->getCalculatedValue();
|
|
self::assertEquals($expectedResult, $result);
|
|
}
|
|
|
|
public function providerINDEXonSpreadsheet(): array
|
|
{
|
|
return require 'tests/data/Calculation/LookupRef/INDEXonSpreadsheet.php';
|
|
}
|
|
}
|