Merge pull request #1113 from PHPOffice/Further-Test-Refactoring

Further test refactoring
This commit is contained in:
Adrien Crivelli 2019-09-20 16:15:29 -07:00 committed by GitHub
commit 8972d370a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 409 additions and 233 deletions

View File

@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org).
### Added
- ...
- Implementation of IFNA() logical function
### Fixed

View File

@ -220,11 +220,10 @@ class MathTrig
return Functions::NAN();
}
$factLoop = floor($factVal);
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) {
if ($factVal > $factLoop) {
if ((Functions::getCompatibilityMode() == Functions::COMPATIBILITY_GNUMERIC) &&
($factVal > $factLoop)) {
return Functions::NAN();
}
}
$factorial = 1;
while ($factLoop > 1) {

View File

@ -52,7 +52,7 @@ class TextData
return ($stringValue) ? Calculation::getTRUE() : Calculation::getFALSE();
}
if (self::$invalidChars == null) {
if (self::$invalidChars === null) {
self::$invalidChars = range(chr(0), chr(31));
}
@ -84,6 +84,15 @@ class TextData
return null;
}
private static function convertBooleanValue($value)
{
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
return (int) $value;
}
return ($value) ? Calculation::getTRUE() : Calculation::getFALSE();
}
/**
* ASCIICODE.
*
@ -98,11 +107,7 @@ class TextData
}
$characters = Functions::flattenSingleValue($characters);
if (is_bool($characters)) {
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
$characters = (int) $characters;
} else {
$characters = ($characters) ? Calculation::getTRUE() : Calculation::getFALSE();
}
$characters = self::convertBooleanValue($characters);
}
$character = $characters;
@ -126,11 +131,7 @@ class TextData
$aArgs = Functions::flattenArray($args);
foreach ($aArgs as $arg) {
if (is_bool($arg)) {
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
$arg = (int) $arg;
} else {
$arg = ($arg) ? Calculation::getTRUE() : Calculation::getFALSE();
}
$arg = self::convertBooleanValue($arg);
}
$returnValue .= $arg;
}
@ -197,7 +198,7 @@ class TextData
}
if (($offset > 0) && (StringHelper::countCharacters($haystack) > $offset)) {
if (StringHelper::countCharacters($needle) == 0) {
if (StringHelper::countCharacters($needle) === 0) {
return $offset;
}
@ -232,7 +233,7 @@ class TextData
}
if (($offset > 0) && (StringHelper::countCharacters($haystack) > $offset)) {
if (StringHelper::countCharacters($needle) == 0) {
if (StringHelper::countCharacters($needle) === 0) {
return $offset;
}
@ -659,11 +660,7 @@ class TextData
if ($ignoreEmpty && trim($arg) == '') {
unset($aArgs[$key]);
} elseif (is_bool($arg)) {
if (Functions::getCompatibilityMode() == Functions::COMPATIBILITY_OPENOFFICE) {
$arg = (int) $arg;
} else {
$arg = ($arg) ? Calculation::getTRUE() : Calculation::getFALSE();
}
$arg = self::convertBooleanValue($arg);
}
}

View File

@ -13,38 +13,6 @@ class FinancialTest extends TestCase
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerACCRINT
*
* @param mixed $expectedResult
*/
public function testACCRINT($expectedResult, ...$args)
{
$result = Financial::ACCRINT(...$args);
self::assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerACCRINT()
{
return require 'data/Calculation/Financial/ACCRINT.php';
}
/**
* @dataProvider providerACCRINTM
*
* @param mixed $expectedResult
*/
public function testACCRINTM($expectedResult, ...$args)
{
$result = Financial::ACCRINTM(...$args);
self::assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerACCRINTM()
{
return require 'data/Calculation/Financial/ACCRINTM.php';
}
/**
* @dataProvider providerAMORDEGRC
*

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase;
class AccrintMTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerACCRINTM
*
* @param mixed $expectedResult
*/
public function testACCRINTM($expectedResult, ...$args)
{
$result = Financial::ACCRINTM(...$args);
self::assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerACCRINTM()
{
return require 'data/Calculation/Financial/ACCRINTM.php';
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Financial;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PHPUnit\Framework\TestCase;
class AccrintTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerACCRINT
*
* @param mixed $expectedResult
*/
public function testACCRINT($expectedResult, ...$args)
{
$result = Financial::ACCRINT(...$args);
$this->assertEquals($expectedResult, $result, '', 1E-8);
}
public function providerACCRINT()
{
return require 'data/Calculation/Financial/ACCRINT.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 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

@ -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 HLookupTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerHLOOKUP
*
* @param mixed $expectedResult
*/
public function testHLOOKUP($expectedResult, ...$args)
{
$result = LookupRef::HLOOKUP(...$args);
$this->assertEquals($expectedResult, $result);
}
public function providerHLOOKUP()
{
return require 'data/Calculation/LookupRef/HLOOKUP.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 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

@ -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 LookupTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerLOOKUP
*
* @param mixed $expectedResult
*/
public function testLOOKUP($expectedResult, ...$args)
{
$result = LookupRef::LOOKUP(...$args);
$this->assertEquals($expectedResult, $result);
}
public function providerLOOKUP()
{
return require 'data/Calculation/LookupRef/LOOKUP.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 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

@ -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 VLookupTest extends TestCase
{
public function setUp()
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerVLOOKUP
*
* @param mixed $expectedResult
*/
public function testVLOOKUP($expectedResult, ...$args)
{
$result = LookupRef::VLOOKUP(...$args);
$this->assertEquals($expectedResult, $result);
}
public function providerVLOOKUP()
{
return require 'data/Calculation/LookupRef/VLOOKUP.php';
}
}

View File

@ -19,118 +19,6 @@ class LookupRefTest extends TestCase
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
}
/**
* @dataProvider providerHLOOKUP
*
* @param mixed $expectedResult
*/
public function testHLOOKUP($expectedResult, ...$args)
{
$result = LookupRef::HLOOKUP(...$args);
self::assertEquals($expectedResult, $result);
}
public function providerHLOOKUP()
{
return require 'data/Calculation/LookupRef/HLOOKUP.php';
}
/**
* @dataProvider providerVLOOKUP
*
* @param mixed $expectedResult
*/
public function testVLOOKUP($expectedResult, ...$args)
{
$result = LookupRef::VLOOKUP(...$args);
self::assertEquals($expectedResult, $result);
}
public function providerVLOOKUP()
{
return require 'data/Calculation/LookupRef/VLOOKUP.php';
}
/**
* @dataProvider providerLOOKUP
*
* @param mixed $expectedResult
*/
public function testLOOKUP($expectedResult, ...$args)
{
$result = LookupRef::LOOKUP(...$args);
self::assertEquals($expectedResult, $result);
}
public function providerLOOKUP()
{
return require 'data/Calculation/LookupRef/LOOKUP.php';
}
/**
* @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

@ -1,52 +1,43 @@
<?php
// Year, Month, Day, Result, Comments
return [
[
6890,
'Year without century specified' => [
6890, // '11th November 1918'
18, 11, 11,
],
// Excel 1900 Calendar Base Date
[
'Excel 1900 Calendar Base Date' => [
1,
1900, 1, 1,
],
// Day before Excel mythical 1900 leap day
[
'Day before Excel mythical 1900 leap day' => [
59,
1900, 2, 28,
],
// Excel mythical 1900 leap day
[
'Excel mythical 1900 leap day' => [
60,
1900, 2, 29,
],
[
// Day after Excel mythical 1900 leap day
'Day after Excel mythical 1900 leap day' => [
61,
1900, 3, 1,
],
// Day after Excel actual 1904 leap day
[
'Day after Excel actual 1904 leap day' => [
713,
1901, 12, 13,
],
// PHP 32-bit Earliest Date (unix timestamp)
[
'signed 32-bit Unix Timestamp Earliest Date' => [
714,
1901, 12, 14,
],
[
'Day before Excel 1904 Calendar Base Date' => [
1461,
1903, 12, 31,
],
// Excel 1904 Calendar Base Date
[
'Excel 1904 Calendar Base Date' => [
1462,
1904, 1, 1,
],
[
'Day after Excel 1904 Calendar Base Date' => [
1463,
1904, 1, 2,
],
@ -54,8 +45,7 @@ return [
22269,
1960, 12, 19,
],
// PHP (unix timestamp) Base Date
[
'Unix Timestamp Base Date' => [
25569,
1970, 1, 1,
],
@ -67,13 +57,11 @@ return [
39611,
2008, 6, 12,
],
// PHP (unix timestamp) 32-bit Latest Date
[
'32-bit signed Unix Timestamp Latest Date' => [
50424,
2038, 1, 19,
],
// Day after PHP (unix timestamp) 32-bit Latest Date
[
'Day after 32-bit signed Unix Timestamp Latest Date' => [
50425,
2038, 1, 20,
],
@ -245,13 +233,11 @@ return [
'#NUM!',
-20, 6, 15,
],
// Excel Maximum Date
[
'Excel Maximum Date' => [
2958465,
9999, 12, 31,
],
// Exceeded Excel Maximum Date
[
'Exceeded Excel Maximum Date' => [
'#NUM!',
10000, 1, 1,
],
@ -329,5 +315,5 @@ return [
[
'#VALUE!',
2010, 3, 'GHI',
],
]
];

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",
],
];

View File

@ -102,147 +102,147 @@ return [
3,
'x',
[[0], [0], ['x'], ['x'], ['x']],
0
0,
],
[
2,
'a',
[false, 'a', 1],
-1
-1,
],
[
'#N/A', // Expected
0,
['x', true, false],
-1
-1,
],
[
'#N/A', // Expected
true,
['a', 'b', 'c'],
-1
-1,
],
[
'#N/A', // Expected
true,
[0, 1, 2],
-1
-1,
],
[
'#N/A', // Expected
true,
[0, 1, 2],
0
0,
],
[
'#N/A', // Expected
true,
[0, 1, 2],
1
1,
],
[
1, // Expected
true,
[true, true, true],
-1
-1,
],
[
1, // Expected
true,
[true, true, true],
0
0,
],
[
3, // Expected
true,
[true, true, true],
1
1,
],
// lookup stops when value < searched one
[
5, // Expected
6,
[true, false, 'a', 'z', 222222, 2, 99999999],
-1
-1,
],
// if element of same data type met and it is < than searched one #N/A - no further processing
[
'#N/A', // Expected
6,
[true, false, 'a', 'z', 2, 888],
-1
-1,
],
[
'#N/A', // Expected
6,
['6'],
-1
-1,
],
// expression match
[
2, // Expected
'a?b',
['a', 'abb', 'axc'],
0
0,
],
[
1, // Expected
'a*',
['aAAAAAAA', 'as', 'az'],
0
0,
],
[
3, // Expected
'1*11*1',
['abc', 'efh', '1a11b1'],
0
0,
],
[
3, // Expected
'1*11*1',
['abc', 'efh', '1a11b1'],
0
0,
],
[
2, // Expected
'a*~*c',
['aAAAAA', 'a123456*c', 'az'],
0
0,
],
[
3, // Expected
'a*123*b',
['aAAAAA', 'a123456*c', 'a99999123b'],
0
0,
],
[
1, // Expected
'*',
['aAAAAA', 'a111123456*c', 'qq'],
0
0,
],
[
2, // Expected
'?',
['aAAAAA', 'a', 'a99999123b'],
0
0,
],
[
'#N/A', // Expected
'?',
[1, 22, 333],
0
0,
],
[
3, // Expected
'???',
[1, 22, 'aaa'],
0
0,
],
[
3, // Expected
'*',
[1, 22, 'aaa'],
0
0,
],
];