You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.9 KiB
62 lines
1.9 KiB
2 months ago
|
<?php
|
||
|
|
||
|
namespace PhpOffice\PhpSpreadsheetTests\Calculation;
|
||
|
|
||
|
use PhpOffice\PhpSpreadsheet\Calculation\BinaryComparison;
|
||
|
use PhpOffice\PhpSpreadsheet\Calculation\Exception;
|
||
|
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
|
||
|
use PHPUnit\Framework\TestCase;
|
||
|
|
||
|
class BinaryComparisonTest extends TestCase
|
||
|
{
|
||
|
/**
|
||
|
* @var string
|
||
|
*/
|
||
|
private $compatibilityMode;
|
||
|
|
||
|
protected function setUp(): void
|
||
|
{
|
||
|
$this->compatibilityMode = Functions::getCompatibilityMode();
|
||
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||
|
}
|
||
|
|
||
|
protected function tearDown(): void
|
||
|
{
|
||
|
Functions::setCompatibilityMode($this->compatibilityMode);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @dataProvider providerBinaryComparison
|
||
|
*
|
||
|
* @param mixed $operand1
|
||
|
* @param mixed $operand2
|
||
|
*/
|
||
|
public function testBinaryComparisonOperation(
|
||
|
$operand1,
|
||
|
$operand2,
|
||
|
string $operator,
|
||
|
bool $expectedResultExcel,
|
||
|
bool $expectedResultOpenOffice
|
||
|
): void {
|
||
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
|
||
|
$resultExcel = BinaryComparison::compare($operand1, $operand2, $operator);
|
||
|
self::assertEquals($expectedResultExcel, $resultExcel, 'should be Excel compatible');
|
||
|
|
||
|
Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE);
|
||
|
$resultOpenOffice = BinaryComparison::compare($operand1, $operand2, $operator);
|
||
|
self::assertEquals($expectedResultOpenOffice, $resultOpenOffice, 'should be OpenOffice compatible');
|
||
|
}
|
||
|
|
||
|
public static function providerBinaryComparison(): array
|
||
|
{
|
||
|
return require 'tests/data/Calculation/BinaryComparisonOperations.php';
|
||
|
}
|
||
|
|
||
|
public function testInvalidOperator(): void
|
||
|
{
|
||
|
$this->expectException(Exception::class);
|
||
|
$this->expectExceptionMessage('Unsupported binary comparison operator');
|
||
|
BinaryComparison::compare(1, 2, '!=');
|
||
|
}
|
||
|
}
|