mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-08-30 12:07:56 +00:00
e9cf27354d
Successor to PR #3523. There are 494 single-line changes (`public function provider` to `public static function provider`) in this PR. None of these were made manually; they were all created with the following script (adapted from https://stackoverflow.com/questions/25909820/how-to-recursively-iterate-through-files-in-php): ```php $dir = 'C:/git/unit10prep2/tests/PhpSpreadsheetTests'; $it = new RecursiveDirectoryIterator($dir); // Loop through files foreach(new RecursiveIteratorIterator($it) as $file) { if ($file->getExtension() === 'php') { $contents = file_get_contents($file); $new = preg_replace('/public function (\\w*)([Pp])rovider/', 'public static function $1$2rovider', $contents); if ($new !== $contents) { echo "changing $file\n"; file_put_contents($file, $new); } } } ``` After this PR, there will be one more, with a small number of test changes, and enabling PhpUnit 10 for Php 8.1+.
156 lines
6.1 KiB
PHP
156 lines
6.1 KiB
PHP
<?php
|
|
|
|
namespace PhpOffice\PhpSpreadsheetTests;
|
|
|
|
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
|
|
{
|
|
/**
|
|
* @dataProvider providerGenerateFunctionListByName
|
|
*/
|
|
public function testGenerateFunctionListByName(array $phpSpreadsheetFunctions, string $expected): void
|
|
{
|
|
self::assertEquals($expected, DocumentGenerator::generateFunctionListByName($phpSpreadsheetFunctions));
|
|
}
|
|
|
|
/**
|
|
* @dataProvider providerGenerateFunctionListByCategory
|
|
*/
|
|
public function testGenerateFunctionListByCategory(array $phpSpreadsheetFunctions, string $expected): void
|
|
{
|
|
self::assertEquals($expected, DocumentGenerator::generateFunctionListByCategory($phpSpreadsheetFunctions));
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|