Completed
Push — develop ( 782b4e...557e80 )
by Adrien
43:38
created

providerBinaryComparisonOperation()   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 0
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\Calculation;
6
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
7
use PHPUnit_Framework_TestCase;
8
9
class CalculationTest extends PHPUnit_Framework_TestCase
10
{
11
    public function setUp()
12
    {
13
        Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
14
    }
15
16
    public function tearDown()
17
    {
18
        $calculation = Calculation::getInstance();
19
        $calculation->setLocale('en_us');
20
    }
21
22
    /**
23
     * @dataProvider providerBinaryComparisonOperation
24
     *
25
     * @param mixed $formula
26
     * @param mixed $expectedResultExcel
27
     * @param mixed $expectedResultOpenOffice
28
     */
29
    public function testBinaryComparisonOperation($formula, $expectedResultExcel, $expectedResultOpenOffice)
30
    {
31
        Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
32
        $resultExcel = Calculation::getInstance()->_calculateFormulaValue($formula);
33
        self::assertEquals($expectedResultExcel, $resultExcel, 'should be Excel compatible');
34
35
        Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
36
        $resultOpenOffice = Calculation::getInstance()->_calculateFormulaValue($formula);
37
        self::assertEquals($expectedResultOpenOffice, $resultOpenOffice, 'should be OpenOffice compatible');
38
    }
39
40
    public function providerBinaryComparisonOperation()
41
    {
42
        return require 'data/CalculationBinaryComparisonOperation.php';
43
    }
44
45
    /**
46
     * @dataProvider providerGetFunctions
47
     *
48
     * @param string $category
49
     * @param array|string $functionCall
50
     * @param string $argumentCount
51
     */
52
    public function testGetFunctions($category, $functionCall, $argumentCount)
0 ignored issues
show
Unused Code introduced by
The parameter $category is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $argumentCount is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
53
    {
54
        self::assertInternalType('callable', $functionCall);
55
    }
56
57
    public function providerGetFunctions()
58
    {
59
        return Calculation::getInstance()->getFunctions();
60
    }
61
62
    public function testIsImplemented()
63
    {
64
        $calculation = Calculation::getInstance();
65
        self::assertFalse($calculation->isImplemented('non-existing-function'));
66
        self::assertFalse($calculation->isImplemented('AREAS'));
67
        self::assertTrue($calculation->isImplemented('coUNt'));
68
        self::assertTrue($calculation->isImplemented('abs'));
69
    }
70
71
    /**
72
     * @dataProvider providerCanLoadAllSupportedLocales
73
     *
74
     * @param string $locale
75
     */
76
    public function testCanLoadAllSupportedLocales($locale)
77
    {
78
        $calculation = Calculation::getInstance();
79
        self::assertTrue($calculation->setLocale($locale));
80
    }
81
82
    public function providerCanLoadAllSupportedLocales()
83
    {
84
        return [
85
            ['bg'],
86
            ['cs'],
87
            ['da'],
88
            ['de'],
89
            ['en_us'],
90
            ['es'],
91
            ['fi'],
92
            ['fr'],
93
            ['hu'],
94
            ['it'],
95
            ['nl'],
96
            ['no'],
97
            ['pl'],
98
            ['pt'],
99
            ['pt_br'],
100
            ['ru'],
101
            ['sv'],
102
            ['tr'],
103
        ];
104
    }
105
}
106