Files
PhpSpreadsheet/tests/PhpSpreadsheetTests/DocumentGeneratorTest.php
T
oleibman 2c9e2e2b43 Spill Operator
Spill operator now works both as trailing `#` and ARRAYANCHOR function. `#` is converted to ARRAYANCHOR when writing. I do not think it is important to convert the other way when reading.

Documentation updates have started, but are a work in progress.

SINGLE function is implemented. I believe it works correctly when referring to a cell, but not when referring to a cell range. No attempt is yet made to convert leading `@` to and from SINGLE; I haven't figured out how to do so without interfering with `@` in structured references.

ISREF has problems. At least one of its tests was wrong, and many of those that were right were so accidentally. The code is changed, quite kludgily, so that almost all the tests are now deliberately correct. One very complicated test is incorrect; for now, I will skip it, and will open an issue when this PR is merged.
2024-06-20 00:43:03 -07:00

190 lines
7.4 KiB
PHP

<?php
declare(strict_types=1);
namespace PhpOffice\PhpSpreadsheetTests;
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
use PhpOffice\PhpSpreadsheet\Calculation\Category as Cat;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\Logical\Operations;
use PhpOffice\PhpSpreadsheetInfra\DocumentGenerator;
use PHPUnit\Framework\TestCase;
use UnexpectedValueException;
class DocumentGeneratorTest extends TestCase
{
private static bool $succeededByName = false;
private static bool $succeededByCategory = false;
/**
* @dataProvider providerGenerateFunctionListByName
*/
public function testGenerateFunctionListByName(array $phpSpreadsheetFunctions, string $expected): void
{
self::assertEquals($expected, DocumentGenerator::generateFunctionListByName($phpSpreadsheetFunctions));
self::$succeededByName = true;
}
/**
* @dataProvider providerGenerateFunctionListByCategory
*/
public function testGenerateFunctionListByCategory(array $phpSpreadsheetFunctions, string $expected): void
{
self::assertEquals($expected, DocumentGenerator::generateFunctionListByCategory($phpSpreadsheetFunctions));
self::$succeededByCategory = true;
}
public static function providerGenerateFunctionListByName(): array
{
return [
[
[
'ABS' => ['category' => Cat::CATEGORY_MATH_AND_TRIG, 'functionCall' => 'abs'],
'AND' => ['category' => Cat::CATEGORY_LOGICAL, 'functionCall' => [Operations::class, 'logicalAnd']],
'IFS' => ['category' => Cat::CATEGORY_LOGICAL, 'functionCall' => [Functions::class, 'DUMMY']],
],
<<<'EXPECTED'
# Function list by name
## A
Excel Function | Category | PhpSpreadsheet Function
-------------------------|--------------------------------|--------------------------------------
ABS | CATEGORY_MATH_AND_TRIG | abs
AND | CATEGORY_LOGICAL | \PhpOffice\PhpSpreadsheet\Calculation\Logical\Operations::logicalAnd
## I
Excel Function | Category | PhpSpreadsheet Function
-------------------------|--------------------------------|--------------------------------------
IFS | CATEGORY_LOGICAL | **Not yet Implemented**
EXPECTED
],
];
}
public static function providerGenerateFunctionListByCategory(): array
{
return [
[
[
'ABS' => ['category' => Cat::CATEGORY_MATH_AND_TRIG, 'functionCall' => 'abs'],
'AND' => ['category' => Cat::CATEGORY_LOGICAL, 'functionCall' => [Operations::class, 'logicalAnd']],
'IFS' => ['category' => Cat::CATEGORY_LOGICAL, 'functionCall' => [Functions::class, 'DUMMY']],
],
<<<'EXPECTED'
# Function list by category
## CATEGORY_CUBE
Excel Function | PhpSpreadsheet Function
-------------------------|--------------------------------------
## CATEGORY_DATABASE
Excel Function | PhpSpreadsheet Function
-------------------------|--------------------------------------
## CATEGORY_DATE_AND_TIME
Excel Function | PhpSpreadsheet Function
-------------------------|--------------------------------------
## CATEGORY_ENGINEERING
Excel Function | PhpSpreadsheet Function
-------------------------|--------------------------------------
## CATEGORY_FINANCIAL
Excel Function | PhpSpreadsheet Function
-------------------------|--------------------------------------
## CATEGORY_INFORMATION
Excel Function | PhpSpreadsheet Function
-------------------------|--------------------------------------
## CATEGORY_LOGICAL
Excel Function | PhpSpreadsheet Function
-------------------------|--------------------------------------
AND | \PhpOffice\PhpSpreadsheet\Calculation\Logical\Operations::logicalAnd
IFS | **Not yet Implemented**
## CATEGORY_LOOKUP_AND_REFERENCE
Excel Function | PhpSpreadsheet Function
-------------------------|--------------------------------------
## CATEGORY_MATH_AND_TRIG
Excel Function | PhpSpreadsheet Function
-------------------------|--------------------------------------
ABS | abs
## CATEGORY_STATISTICAL
Excel Function | PhpSpreadsheet Function
-------------------------|--------------------------------------
## CATEGORY_TEXT_AND_DATA
Excel Function | PhpSpreadsheet Function
-------------------------|--------------------------------------
## CATEGORY_WEB
Excel Function | PhpSpreadsheet Function
-------------------------|--------------------------------------
## CATEGORY_UNCATEGORISED
Excel Function | PhpSpreadsheet Function
-------------------------|--------------------------------------
## CATEGORY_MICROSOFT_INTERNAL
Excel Function | PhpSpreadsheet Function
-------------------------|--------------------------------------
EXPECTED
],
];
}
public function testGenerateFunctionBadArray(): void
{
$this->expectException(UnexpectedValueException::class);
$phpSpreadsheetFunctions = [
'ABS' => ['category' => Cat::CATEGORY_MATH_AND_TRIG, 'functionCall' => 1],
];
DocumentGenerator::generateFunctionListByName($phpSpreadsheetFunctions);
}
public function testGenerateDocuments(): void
{
if (!self::$succeededByName || !self::$succeededByCategory) {
self::markTestSkipped('Not run because prior test failed');
}
$directory = 'docs/references/';
self::assertNotEmpty($directory);
$phpSpreadsheetFunctions = Calculation::getFunctions();
ksort($phpSpreadsheetFunctions);
self::assertNotFalse(file_put_contents(
$directory . 'function-list-by-category.md',
DocumentGenerator::generateFunctionListByCategory($phpSpreadsheetFunctions)
));
self::assertNotFalse(file_put_contents(
$directory . 'function-list-by-name.md',
DocumentGenerator::generateFunctionListByName($phpSpreadsheetFunctions)
));
}
}