Passed
Push — develop ( f0e694...db2621 )
by Adrien
27:12
created

LookupRefTest::testLOOKUP()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
4
5
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
6
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
7
use PhpOffice\PhpSpreadsheet\Cell\Cell;
8
use PhpOffice\PhpSpreadsheet\Spreadsheet;
9
use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet;
10
use PHPUnit\Framework\TestCase;
11
12
/**
13
 * Class LookupRefTest.
14
 */
15
class LookupRefTest extends TestCase
16
{
17
    public function setUp()
18
    {
19
        Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
20
    }
21
22
    /**
23
     * @dataProvider providerHLOOKUP
24
     *
25
     * @param mixed $expectedResult
26
     */
27
    public function testHLOOKUP($expectedResult, ...$args)
28
    {
29
        $result = LookupRef::HLOOKUP(...$args);
30
        self::assertEquals($expectedResult, $result);
31
    }
32
33
    public function providerHLOOKUP()
34
    {
35
        return require 'data/Calculation/LookupRef/HLOOKUP.php';
36
    }
37
38
    /**
39
     * @dataProvider providerVLOOKUP
40
     *
41
     * @param mixed $expectedResult
42
     */
43
    public function testVLOOKUP($expectedResult, ...$args)
44
    {
45
        $result = LookupRef::VLOOKUP(...$args);
46
        self::assertEquals($expectedResult, $result);
47
    }
48
49
    public function providerVLOOKUP()
50
    {
51
        return require 'data/Calculation/LookupRef/VLOOKUP.php';
52
    }
53
54
    /**
55
     * @dataProvider providerLOOKUP
56
     *
57
     * @param mixed $expectedResult
58
     */
59
    public function testLOOKUP($expectedResult, ...$args)
60
    {
61
        $result = LookupRef::LOOKUP(...$args);
62
        self::assertEquals($expectedResult, $result);
63
    }
64
65
    public function providerLOOKUP()
66
    {
67
        return require 'data/Calculation/LookupRef/LOOKUP.php';
68
    }
69
70
    /**
71
     * @dataProvider providerMATCH
72
     *
73
     * @param mixed $expectedResult
74
     */
75
    public function testMATCH($expectedResult, ...$args)
76
    {
77
        $result = LookupRef::MATCH(...$args);
78
        self::assertEquals($expectedResult, $result);
79
    }
80
81
    public function providerMATCH()
82
    {
83
        return require 'data/Calculation/LookupRef/MATCH.php';
84
    }
85
86
    /**
87
     * @dataProvider providerINDEX
88
     *
89
     * @param mixed $expectedResult
90
     */
91
    public function testINDEX($expectedResult, ...$args)
92
    {
93
        $result = LookupRef::INDEX(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $arrayValues of PhpOffice\PhpSpreadsheet...tion\LookupRef::INDEX() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

93
        $result = LookupRef::INDEX(/** @scrutinizer ignore-type */ ...$args);
Loading history...
94
        self::assertEquals($expectedResult, $result);
95
    }
96
97
    public function providerINDEX()
98
    {
99
        return require 'data/Calculation/LookupRef/INDEX.php';
100
    }
101
102
    /**
103
     * @dataProvider providerCOLUMNS
104
     *
105
     * @param mixed $expectedResult
106
     */
107
    public function testCOLUMNS($expectedResult, ...$args)
108
    {
109
        $result = LookupRef::COLUMNS(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $cellAddress of PhpOffice\PhpSpreadsheet...on\LookupRef::COLUMNS() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

109
        $result = LookupRef::COLUMNS(/** @scrutinizer ignore-type */ ...$args);
Loading history...
110
        self::assertEquals($expectedResult, $result);
111
    }
112
113
    public function providerCOLUMNS()
114
    {
115
        return require 'data/Calculation/LookupRef/COLUMNS.php';
116
    }
117
118
    /**
119
     * @dataProvider providerROWS
120
     *
121
     * @param mixed $expectedResult
122
     */
123
    public function testROWS($expectedResult, ...$args)
124
    {
125
        $result = LookupRef::ROWS(...$args);
1 ignored issue
show
Bug introduced by
$args is expanded, but the parameter $cellAddress of PhpOffice\PhpSpreadsheet...ation\LookupRef::ROWS() does not expect variable arguments. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

125
        $result = LookupRef::ROWS(/** @scrutinizer ignore-type */ ...$args);
Loading history...
126
        self::assertEquals($expectedResult, $result);
127
    }
128
129
    public function providerROWS()
130
    {
131
        return require 'data/Calculation/LookupRef/ROWS.php';
132
    }
133
134
    /**
135
     * @dataProvider providerFormulaText
136
     *
137
     * @param mixed $expectedResult
138
     * @param mixed $reference       Reference to the cell we wish to test
139
     * @param mixed $value           Value of the cell we wish to test
140
     */
141
    public function testFormulaText($expectedResult, $reference, $value = 'undefined')
142
    {
143
        $ourCell = null;
144
        if ($value !== 'undefined') {
145
            $remoteCell = $this->getMockBuilder(Cell::class)
146
                ->disableOriginalConstructor()
147
                ->getMock();
148
            $remoteCell->method('isFormula')
149
                ->will($this->returnValue(substr($value, 0, 1) == '='));
150
            $remoteCell->method('getValue')
151
                ->will($this->returnValue($value));
152
153
            $remoteSheet = $this->getMockBuilder(Worksheet::class)
154
                ->disableOriginalConstructor()
155
                ->getMock();
156
            $remoteSheet->method('getCell')
157
                ->will($this->returnValue($remoteCell));
158
159
            $workbook = $this->getMockBuilder(Spreadsheet::class)
160
                ->disableOriginalConstructor()
161
                ->getMock();
162
            $workbook->method('getSheetByName')
163
                ->will($this->returnValue($remoteSheet));
164
165
            $sheet = $this->getMockBuilder(Worksheet::class)
166
                ->disableOriginalConstructor()
167
                ->getMock();
168
            $sheet->method('getCell')
169
                ->will($this->returnValue($remoteCell));
170
            $sheet->method('getParent')
171
                ->will($this->returnValue($workbook));
172
173
            $ourCell = $this->getMockBuilder(Cell::class)
174
                ->disableOriginalConstructor()
175
                ->getMock();
176
            $ourCell->method('getWorksheet')
177
                ->will($this->returnValue($sheet));
178
        }
179
180
        $result = LookupRef::FORMULATEXT($reference, $ourCell);
181
        self::assertEquals($expectedResult, $result, null, 1E-8);
182
    }
183
184
    public function providerFormulaText()
185
    {
186
        return require 'data/Calculation/LookupRef/FORMULATEXT.php';
187
    }
188
}
189