mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-30 12:07:56 +00:00
40911aa104
Many problems with Dependabot this month. Phpstan introduced a lot of new "errors". These are now fixed or annotated. I combined this with a change to require comments for `phpstan-ignore`. These won't always be useful, but I think requiring them makes sense. Tcpdf is more of a non-update. Our composer.json specified `^6.5`. For some reason, Dependabot decided it was okay to change that to `^6.5||^7.0`, which seems presumptuous. (One of the triggers was probably the elimination of Php8.1, since the new product requires 8.2+.) Tcpdf is nominally deprecated, replaced by tc-lib-pdf. Tcpdf 7 passes control to the new product. However, the upgrade is not straightforward. The user needs to supply font files which were formerly distributed with the product, and a code change to define a (shudder) global constant is required. Consequently, Dependabot's upgrade failed its unit tests. While I may evaluate what might be needed at some point in the future, for now I am just updating composer.json to reject Tcpdf 7+.
204 lines
8.4 KiB
PHP
204 lines
8.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\Attributes\DataProvider;
|
|
use PHPUnit\Framework\TestCase;
|
|
use UnexpectedValueException;
|
|
|
|
class DocumentGeneratorTest extends TestCase
|
|
{
|
|
private static bool $succeededByName = false;
|
|
|
|
private static bool $succeededByCategory = false;
|
|
|
|
/** @param array<string, array{category: string, functionCall: array<string>|string, argumentCount: string, passCellReference?: bool, passByReference?: array<bool>, custom?: bool}> $phpSpreadsheetFunctions */
|
|
#[DataProvider('providerGenerateFunctionListByName')]
|
|
public function testGenerateFunctionListByName(array $phpSpreadsheetFunctions, string $expected): void
|
|
{
|
|
self::assertEquals($expected, DocumentGenerator::generateFunctionListByName($phpSpreadsheetFunctions));
|
|
self::$succeededByName = true;
|
|
}
|
|
|
|
/** @param array<string, array{category: string, functionCall: array<string>|string, argumentCount: string, passCellReference?: bool, passByReference?: array<bool>, custom?: bool}> $phpSpreadsheetFunctions */
|
|
#[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', 'argumentCount' => '1'],
|
|
'AND' => ['category' => Cat::CATEGORY_LOGICAL, 'functionCall' => [Operations::class, 'logicalAnd'], 'argumentCount' => '2'],
|
|
'IFS' => ['category' => Cat::CATEGORY_LOGICAL, 'functionCall' => [Functions::class, 'DUMMY'], 'argumentCount' => '3'],
|
|
],
|
|
<<<'EXPECTED'
|
|
# Function list by name
|
|
|
|
A more compact list can be found [here](./function-list-by-name-compact.md)
|
|
|
|
|
|
## 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', 'argumentCount' => '1'],
|
|
'AND' => ['category' => Cat::CATEGORY_LOGICAL, 'functionCall' => [Operations::class, 'logicalAnd'], 'argumentCount' => '2'],
|
|
'IFS' => ['category' => Cat::CATEGORY_LOGICAL, 'functionCall' => [Functions::class, 'DUMMY'], 'argumentCount' => '3'],
|
|
],
|
|
<<<'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 //* @phpstan-ignore argument.type (deliberate run-time test)
|
|
);
|
|
}
|
|
|
|
public function testGenerateDocuments(): void
|
|
{
|
|
if (!self::$succeededByName || !self::$succeededByCategory) {
|
|
self::markTestSkipped('Not run because prior test failed');
|
|
}
|
|
$directory = 'docs/references/';
|
|
$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
|
|
)
|
|
));
|
|
self::assertNotFalse(file_put_contents(
|
|
$directory . 'function-list-by-name-compact.md',
|
|
DocumentGenerator::generateFunctionListByName(
|
|
$phpSpreadsheetFunctions,
|
|
true
|
|
)
|
|
));
|
|
}
|
|
}
|