Passed
Push — master ( a97294...8972d3 )
by Adrien
28:45 queued 21:13
created

LookupRefTest::testVLOOKUP()   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 providerFormulaText
24
     *
25
     * @param mixed $expectedResult
26
     * @param mixed $reference       Reference to the cell we wish to test
27
     * @param mixed $value           Value of the cell we wish to test
28
     */
29
    public function testFormulaText($expectedResult, $reference, $value = 'undefined')
30
    {
31
        $ourCell = null;
32
        if ($value !== 'undefined') {
33
            $remoteCell = $this->getMockBuilder(Cell::class)
34
                ->disableOriginalConstructor()
35
                ->getMock();
36
            $remoteCell->method('isFormula')
37
                ->will($this->returnValue(substr($value, 0, 1) == '='));
38
            $remoteCell->method('getValue')
39
                ->will($this->returnValue($value));
40
41
            $remoteSheet = $this->getMockBuilder(Worksheet::class)
42
                ->disableOriginalConstructor()
43
                ->getMock();
44
            $remoteSheet->method('getCell')
45
                ->will($this->returnValue($remoteCell));
46
47
            $workbook = $this->getMockBuilder(Spreadsheet::class)
48
                ->disableOriginalConstructor()
49
                ->getMock();
50
            $workbook->method('getSheetByName')
51
                ->will($this->returnValue($remoteSheet));
52
53
            $sheet = $this->getMockBuilder(Worksheet::class)
54
                ->disableOriginalConstructor()
55
                ->getMock();
56
            $sheet->method('getCell')
57
                ->will($this->returnValue($remoteCell));
58
            $sheet->method('getParent')
59
                ->will($this->returnValue($workbook));
60
61
            $ourCell = $this->getMockBuilder(Cell::class)
62
                ->disableOriginalConstructor()
63
                ->getMock();
64
            $ourCell->method('getWorksheet')
65
                ->will($this->returnValue($sheet));
66
        }
67
68
        $result = LookupRef::FORMULATEXT($reference, $ourCell);
69
        self::assertEquals($expectedResult, $result, '', 1E-8);
70
    }
71
72
    public function providerFormulaText()
73
    {
74
        return require 'data/Calculation/LookupRef/FORMULATEXT.php';
75
    }
76
}
77