More refactoring Excel of Calculation Function Unit Tests

This commit is contained in:
MarkBaker 2019-07-27 16:35:27 +02:00
parent 905a697639
commit f14e5ea837
11 changed files with 187 additions and 68 deletions

View File

@ -87,7 +87,7 @@ class TextData
private static function convertBooleanValue($value)
{
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
return (int)$value;
return (int) $value;
}
return ($value) ? Calculation::getTRUE() : Calculation::getFALSE();

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PHPUnit\Framework\TestCase;
class ChooseTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerCHOOSE
*
* @param mixed $expectedResult
*/
public function testCHOOSE($expectedResult, ...$args)
{
$result = LookupRef::CHOOSE(...$args);
$this->assertEquals($expectedResult, $result);
}
public function providerCHOOSE()
{
return require 'data/Calculation/LookupRef/CHOOSE.php';
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PHPUnit\Framework\TestCase;
class ColumnsTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerCOLUMNS
*
* @param mixed $expectedResult
*/
public function testCOLUMNS($expectedResult, ...$args)
{
$result = LookupRef::COLUMNS(...$args);
$this->assertEquals($expectedResult, $result);
}
public function providerCOLUMNS()
{
return require 'data/Calculation/LookupRef/COLUMNS.php';
}
}

View File

@ -2,8 +2,8 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PHPUnit\Framework\TestCase;
class HLookupTest extends TestCase

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PHPUnit\Framework\TestCase;
class IndexTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerINDEX
*
* @param mixed $expectedResult
*/
public function testINDEX($expectedResult, ...$args)
{
$result = LookupRef::INDEX(...$args);
$this->assertEquals($expectedResult, $result);
}
public function providerINDEX()
{
return require 'data/Calculation/LookupRef/INDEX.php';
}
}

View File

@ -2,8 +2,8 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PHPUnit\Framework\TestCase;
class LookupTest extends TestCase

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PHPUnit\Framework\TestCase;
class MatchTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerMATCH
*
* @param mixed $expectedResult
*/
public function testMATCH($expectedResult, ...$args)
{
$result = LookupRef::MATCH(...$args);
$this->assertEquals($expectedResult, $result);
}
public function providerMATCH()
{
return require 'data/Calculation/LookupRef/MATCH.php';
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PHPUnit\Framework\TestCase;
class RowsTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerROWS
*
* @param mixed $expectedResult
*/
public function testROWS($expectedResult, ...$args)
{
$result = LookupRef::ROWS(...$args);
$this->assertEquals($expectedResult, $result);
}
public function providerROWS()
{
return require 'data/Calculation/LookupRef/ROWS.php';
}
}

View File

@ -2,8 +2,8 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\LookupRef;
use PHPUnit\Framework\TestCase;
class VLookupTest extends TestCase

View File

@ -19,70 +19,6 @@ class LookupRefTest extends TestCase
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerMATCH
*
* @param mixed $expectedResult
*/
public function testMATCH($expectedResult, ...$args)
{
$result = LookupRef::MATCH(...$args);
self::assertEquals($expectedResult, $result);
}
public function providerMATCH()
{
return require 'data/Calculation/LookupRef/MATCH.php';
}
/**
* @dataProvider providerINDEX
*
* @param mixed $expectedResult
*/
public function testINDEX($expectedResult, ...$args)
{
$result = LookupRef::INDEX(...$args);
self::assertEquals($expectedResult, $result);
}
public function providerINDEX()
{
return require 'data/Calculation/LookupRef/INDEX.php';
}
/**
* @dataProvider providerCOLUMNS
*
* @param mixed $expectedResult
*/
public function testCOLUMNS($expectedResult, ...$args)
{
$result = LookupRef::COLUMNS(...$args);
self::assertEquals($expectedResult, $result);
}
public function providerCOLUMNS()
{
return require 'data/Calculation/LookupRef/COLUMNS.php';
}
/**
* @dataProvider providerROWS
*
* @param mixed $expectedResult
*/
public function testROWS($expectedResult, ...$args)
{
$result = LookupRef::ROWS(...$args);
self::assertEquals($expectedResult, $result);
}
public function providerROWS()
{
return require 'data/Calculation/LookupRef/ROWS.php';
}
/**
* @dataProvider providerFormulaText
*

View File

@ -0,0 +1,28 @@
<?php
return [
[
"brown",
4, "red", "blue", "green", "brown",
],
[
"blue",
2, "red", "blue", "green", "brown",
],
[
"green",
3, "red", "blue", "green", "brown",
],
[
"red",
1, "red", "blue", "green", "brown",
],
[
"#VALUE!",
5, "red", "blue", "green", "brown",
],
[
"#VALUE!",
0, "red", "blue", "green", "brown",
],
];