DocumentGeneratorTest.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <?php
  2. namespace PhpOffice\PhpSpreadsheetTests;
  3. use PhpOffice\PhpSpreadsheet\Calculation\Category as Cat;
  4. use PhpOffice\PhpSpreadsheet\Calculation\Functions;
  5. use PhpOffice\PhpSpreadsheet\Calculation\Logical;
  6. use PhpOffice\PhpSpreadsheetInfra\DocumentGenerator;
  7. use PHPUnit\Framework\TestCase;
  8. use UnexpectedValueException;
  9. class DocumentGeneratorTest extends TestCase
  10. {
  11. /**
  12. * @dataProvider providerGenerateFunctionListByName
  13. */
  14. public function testGenerateFunctionListByName(array $phpSpreadsheetFunctions, string $expected): void
  15. {
  16. self::assertEquals($expected, DocumentGenerator::generateFunctionListByName($phpSpreadsheetFunctions));
  17. }
  18. /**
  19. * @dataProvider providerGenerateFunctionListByCategory
  20. */
  21. public function testGenerateFunctionListByCategory(array $phpSpreadsheetFunctions, string $expected): void
  22. {
  23. self::assertEquals($expected, DocumentGenerator::generateFunctionListByCategory($phpSpreadsheetFunctions));
  24. }
  25. public function providerGenerateFunctionListByName(): array
  26. {
  27. return [
  28. [
  29. [
  30. 'ABS' => ['category' => Cat::CATEGORY_MATH_AND_TRIG, 'functionCall' => 'abs'],
  31. 'AND' => ['category' => Cat::CATEGORY_LOGICAL, 'functionCall' => [Logical::class, 'logicalAnd']],
  32. 'IFS' => ['category' => Cat::CATEGORY_LOGICAL, 'functionCall' => [Functions::class, 'DUMMY']],
  33. ],
  34. <<<'EXPECTED'
  35. # Function list by name
  36. ## A
  37. Excel Function | Category | PhpSpreadsheet Function
  38. -------------------------|--------------------------------|--------------------------------------
  39. ABS | CATEGORY_MATH_AND_TRIG | abs
  40. AND | CATEGORY_LOGICAL | \PhpOffice\PhpSpreadsheet\Calculation\Logical::logicalAnd
  41. ## I
  42. Excel Function | Category | PhpSpreadsheet Function
  43. -------------------------|--------------------------------|--------------------------------------
  44. IFS | CATEGORY_LOGICAL | **Not yet Implemented**
  45. EXPECTED
  46. ],
  47. ];
  48. }
  49. public function providerGenerateFunctionListByCategory(): array
  50. {
  51. return [
  52. [
  53. [
  54. 'ABS' => ['category' => Cat::CATEGORY_MATH_AND_TRIG, 'functionCall' => 'abs'],
  55. 'AND' => ['category' => Cat::CATEGORY_LOGICAL, 'functionCall' => [Logical::class, 'logicalAnd']],
  56. 'IFS' => ['category' => Cat::CATEGORY_LOGICAL, 'functionCall' => [Functions::class, 'DUMMY']],
  57. ],
  58. <<<'EXPECTED'
  59. # Function list by category
  60. ## CATEGORY_CUBE
  61. Excel Function | PhpSpreadsheet Function
  62. -------------------------|--------------------------------------
  63. ## CATEGORY_DATABASE
  64. Excel Function | PhpSpreadsheet Function
  65. -------------------------|--------------------------------------
  66. ## CATEGORY_DATE_AND_TIME
  67. Excel Function | PhpSpreadsheet Function
  68. -------------------------|--------------------------------------
  69. ## CATEGORY_ENGINEERING
  70. Excel Function | PhpSpreadsheet Function
  71. -------------------------|--------------------------------------
  72. ## CATEGORY_FINANCIAL
  73. Excel Function | PhpSpreadsheet Function
  74. -------------------------|--------------------------------------
  75. ## CATEGORY_INFORMATION
  76. Excel Function | PhpSpreadsheet Function
  77. -------------------------|--------------------------------------
  78. ## CATEGORY_LOGICAL
  79. Excel Function | PhpSpreadsheet Function
  80. -------------------------|--------------------------------------
  81. AND | \PhpOffice\PhpSpreadsheet\Calculation\Logical::logicalAnd
  82. IFS | **Not yet Implemented**
  83. ## CATEGORY_LOOKUP_AND_REFERENCE
  84. Excel Function | PhpSpreadsheet Function
  85. -------------------------|--------------------------------------
  86. ## CATEGORY_MATH_AND_TRIG
  87. Excel Function | PhpSpreadsheet Function
  88. -------------------------|--------------------------------------
  89. ABS | abs
  90. ## CATEGORY_STATISTICAL
  91. Excel Function | PhpSpreadsheet Function
  92. -------------------------|--------------------------------------
  93. ## CATEGORY_TEXT_AND_DATA
  94. Excel Function | PhpSpreadsheet Function
  95. -------------------------|--------------------------------------
  96. ## CATEGORY_WEB
  97. Excel Function | PhpSpreadsheet Function
  98. -------------------------|--------------------------------------
  99. EXPECTED
  100. ],
  101. ];
  102. }
  103. public function testGenerateFunctionBadArray(): void
  104. {
  105. $this->expectException(UnexpectedValueException::class);
  106. $phpSpreadsheetFunctions = [
  107. 'ABS' => ['category' => Cat::CATEGORY_MATH_AND_TRIG, 'functionCall' => 1],
  108. ];
  109. DocumentGenerator::generateFunctionListByName($phpSpreadsheetFunctions);
  110. }
  111. }