1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace PhpOffice\PhpSpreadsheetTests; |
4
|
|
|
|
5
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation; |
6
|
|
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions; |
7
|
|
|
|
8
|
|
|
class CalculationTest extends \PHPUnit_Framework_TestCase |
9
|
|
|
{ |
10
|
|
|
public function setUp() |
11
|
|
|
{ |
12
|
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); |
13
|
|
|
} |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* @dataProvider providerBinaryComparisonOperation |
17
|
|
|
* |
18
|
|
|
* @param mixed $formula |
19
|
|
|
* @param mixed $expectedResultExcel |
20
|
|
|
* @param mixed $expectedResultOpenOffice |
21
|
|
|
*/ |
22
|
|
|
public function testBinaryComparisonOperation($formula, $expectedResultExcel, $expectedResultOpenOffice) |
23
|
|
|
{ |
24
|
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); |
25
|
|
|
$resultExcel = Calculation::getInstance()->_calculateFormulaValue($formula); |
26
|
|
|
$this->assertEquals($expectedResultExcel, $resultExcel, 'should be Excel compatible'); |
27
|
|
|
|
28
|
|
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE); |
29
|
|
|
$resultOpenOffice = Calculation::getInstance()->_calculateFormulaValue($formula); |
30
|
|
|
$this->assertEquals($expectedResultOpenOffice, $resultOpenOffice, 'should be OpenOffice compatible'); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function providerBinaryComparisonOperation() |
34
|
|
|
{ |
35
|
|
|
return require 'data/CalculationBinaryComparisonOperation.php'; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @dataProvider providerGetFunctions |
40
|
|
|
* |
41
|
|
|
* @param mixed $category |
42
|
|
|
* @param mixed $functionCall |
43
|
|
|
* @param mixed $argumentCount |
44
|
|
|
*/ |
45
|
|
|
public function testGetFunctions($category, $functionCall, $argumentCount) |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$this->assertInternalType('callable', $functionCall); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function providerGetFunctions() |
51
|
|
|
{ |
52
|
|
|
return Calculation::getInstance()->getFunctions(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function testIsImplemented() |
56
|
|
|
{ |
57
|
|
|
$calculation = Calculation::getInstance(); |
58
|
|
|
$this->assertFalse($calculation->isImplemented('non-existing-function')); |
59
|
|
|
$this->assertFalse($calculation->isImplemented('AREAS')); |
60
|
|
|
$this->assertTrue($calculation->isImplemented('coUNt')); |
61
|
|
|
$this->assertTrue($calculation->isImplemented('abs')); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.