Completed
Push — master ( ba1ce8...40abd1 )
by Adrien
22s queued 19s
created

DocumentGeneratorTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 137
Duplicated Lines 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
eloc 21
dl 0
loc 137
rs 10
c 3
b 1
f 0
wmc 5

5 Methods

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