Completed
Push — develop ( 360db8...810f17 )
by Adrien
18:39
created

LookupRefTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 75
rs 10
c 0
b 0
f 0
wmc 9
lcom 1
cbo 3

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A testHLOOKUP() 0 5 1
A providerHLOOKUP() 0 4 1
A testVLOOKUP() 0 5 1
A providerVLOOKUP() 0 4 1
A testMATCH() 0 5 1
A providerMATCH() 0 4 1
A testINDEX() 0 5 1
A providerINDEX() 0 4 1
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
4
5
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
6
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
7
use PHPUnit_Framework_TestCase;
8
9
/**
10
 * Class LookupRefTest.
11
 */
12
class LookupRefTest extends PHPUnit_Framework_TestCase
13
{
14
    public function setUp()
15
    {
16
        Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
17
    }
18
19
    /**
20
     * @dataProvider providerHLOOKUP
21
     * @group fail19
22
     *
23
     * @param mixed $expectedResult
24
     */
25
    public function testHLOOKUP($expectedResult, ...$args)
26
    {
27
        $result = LookupRef::HLOOKUP(...$args);
0 ignored issues
show
Bug introduced by
The call to HLOOKUP() misses some required arguments starting with $lookup_array.
Loading history...
Documentation introduced by
$args is of type array<integer,?>, but the function expects a object<PhpOffice\PhpSpreadsheet\Calculation\The>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
28
        self::assertEquals($expectedResult, $result);
29
    }
30
31
    public function providerHLOOKUP()
32
    {
33
        return require 'data/Calculation/LookupRef/HLOOKUP.php';
34
    }
35
36
    /**
37
     * @dataProvider providerVLOOKUP
38
     * @group fail19
39
     *
40
     * @param mixed $expectedResult
41
     */
42
    public function testVLOOKUP($expectedResult, ...$args)
43
    {
44
        $result = LookupRef::VLOOKUP(...$args);
0 ignored issues
show
Bug introduced by
The call to VLOOKUP() misses some required arguments starting with $lookup_array.
Loading history...
Documentation introduced by
$args is of type array<integer,?>, but the function expects a object<PhpOffice\PhpSpreadsheet\Calculation\The>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
45
        self::assertEquals($expectedResult, $result);
46
    }
47
48
    public function providerVLOOKUP()
49
    {
50
        return require 'data/Calculation/LookupRef/VLOOKUP.php';
51
    }
52
53
    /**
54
     * @dataProvider providerMATCH
55
     * @group fail19
56
     *
57
     * @param mixed $expectedResult
58
     */
59
    public function testMATCH($expectedResult, ...$args)
60
    {
61
        $result = LookupRef::MATCH(...$args);
0 ignored issues
show
Bug introduced by
The call to MATCH() misses a required argument $lookupArray.

This check looks for function calls that miss required arguments.

Loading history...
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
     * @group fail19
73
     *
74
     * @param mixed $expectedResult
75
     */
76
    public function testINDEX($expectedResult, ...$args)
77
    {
78
        $result = LookupRef::INDEX(...$args);
79
        self::assertEquals($expectedResult, $result);
80
    }
81
82
    public function providerINDEX()
83
    {
84
        return require 'data/Calculation/LookupRef/INDEX.php';
85
    }
86
}
87