mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-22 16:19:19 +00:00
0cd725d000
* Automate Function-by-Name and Function-by-Category Docs Examining whether it is possible to analyze the 2 Php scripts in the bin directory even though they lack a .php extension, I found that the docs generated by `generate-document` had not been updated in over a year even though support for a number of functions (e.g. ARRAYTOTEXT) had long ago been implemented. The files generated by the other script `generate-locales` are automatically generated as part of the unit test suite, and I can't see any reason not to do the same for `generate-document`. It isn't totally clear that the 2 scripts in bin are needed any more now that each has an equivalent in the unit test suite. For now, I'm keeping them, and allowing them to be analyzed by phpcs, php-cs-fixer, and phpstan. * Reflection Not Required Remove it from bin scripts and DocumentGeneratorTest. * Better Html/Css Display for Function Lists * Redesign Features Cross Reference Doc It was inaccurate, and pretty much impossible to read in entirety. This version should be easier to read, and to correct. That's important, because there are almost certainly new inaccuracies in this version. * Add Html to Features Cross-Reference Readers
185 lines
7.2 KiB
PHP
185 lines
7.2 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;
|
|
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' => [Logical::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::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' => [Logical::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::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
|
|
-------------------------|--------------------------------------
|
|
|
|
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)
|
|
));
|
|
}
|
|
}
|