Passed
Push — develop ( 3028c6...9b44cf )
by Mark
29:23
created

LookupRefTest   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 156
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 54
dl 0
loc 156
rs 10
c 0
b 0
f 0
wmc 16

15 Methods

Rating   Name   Duplication   Size   Complexity  
A testVLOOKUP() 0 4 1
A setUp() 0 3 1
A testFormulaText() 0 41 2
A testMATCH() 0 4 1
A testHLOOKUP() 0 4 1
A testCOLUMNS() 0 4 1
A providerINDEX() 0 3 1
A testROWS() 0 4 1
A providerVLOOKUP() 0 3 1
A providerMATCH() 0 3 1
A providerHLOOKUP() 0 3 1
A testINDEX() 0 4 1
A providerFormulaText() 0 3 1
A providerROWS() 0 3 1
A providerCOLUMNS() 0 3 1
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 providerMATCH
56
     *
57
     * @param mixed $expectedResult
58
     */
59
    public function testMATCH($expectedResult, ...$args)
60
    {
61
        $result = LookupRef::MATCH(...$args);
62
        self::assertEquals($expectedResult, $result);
63
    }
64
65
    public function providerMATCH()
66
    {
67
        return require 'data/Calculation/LookupRef/MATCH.php';
68
    }
69
70
    /**
71
     * @dataProvider providerINDEX
72
     *
73
     * @param mixed $expectedResult
74
     */
75
    public function testINDEX($expectedResult, ...$args)
76
    {
77
        $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

77
        $result = LookupRef::INDEX(/** @scrutinizer ignore-type */ ...$args);
Loading history...
78
        self::assertEquals($expectedResult, $result);
79
    }
80
81
    public function providerINDEX()
82
    {
83
        return require 'data/Calculation/LookupRef/INDEX.php';
84
    }
85
86
    /**
87
     * @dataProvider providerCOLUMNS
88
     *
89
     * @param mixed $expectedResult
90
     */
91
    public function testCOLUMNS($expectedResult, ...$args)
92
    {
93
        $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

93
        $result = LookupRef::COLUMNS(/** @scrutinizer ignore-type */ ...$args);
Loading history...
94
        self::assertEquals($expectedResult, $result);
95
    }
96
97
    public function providerCOLUMNS()
98
    {
99
        return require 'data/Calculation/LookupRef/COLUMNS.php';
100
    }
101
102
    /**
103
     * @dataProvider providerROWS
104
     *
105
     * @param mixed $expectedResult
106
     */
107
    public function testROWS($expectedResult, ...$args)
108
    {
109
        $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

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