Restoring State After Static Changes in Tests (#1571)

This request does not change any source code, only tests.

For a change on which I was working, a test passed when run on its own,
but failed when run as part of the full test suite. It turned out that
an existing test had changed a static value,
thousands separator in this case, and failed to restore it.
The test turned out to be AdvancedBinderTest.

The search for the offending test was more difficult than it should have
been because 26 test scripts which had nothing to do with thousands
separator nevertheless changed that value. They all changed
decimal separator, currency code, and compatibility mode as well,
again for no reason. I changed all of those to eliminate those operations.

I changed the following tests, which actually do change the static
properties identified above for a reason, to restore them as part of teardown.
- CalculationTest sets compatibilityMode and locale
- DayTest sets compatibilityMode, returnDateType, and excelCalendar
- CountTest sets compatibilityMode
- FunctionsTest sets compatibilityMode and returnDateType
- AdvancedValueBinderTest sets currencyCode, decimalSeparator, thousandsSeparator
- StringHelperTest sets currencyCode, decimalSeparator, thousandsSeparator
- NumberFormatTest sets currencyCode, decimalSeparator, thousandsSeparator
- HtmlNumberFormatTest sets currencyCode, decimalSeparator, thousandsSeparator
This commit is contained in:
oleibman 2020-07-15 04:23:00 -07:00 committed by GitHub
parent b89968d206
commit 165034ad70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
32 changed files with 110 additions and 435 deletions

View File

@ -9,15 +9,23 @@ use PHPUnit\Framework\TestCase;
class CalculationTest extends TestCase class CalculationTest extends TestCase
{ {
private $compatibilityMode;
private $locale;
protected function setUp(): void protected function setUp(): void
{ {
$this->compatibilityMode = Functions::getCompatibilityMode();
$calculation = Calculation::getInstance();
$this->locale = $calculation->getLocale();
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
} }
protected function tearDown(): void protected function tearDown(): void
{ {
Functions::setCompatibilityMode($this->compatibilityMode);
$calculation = Calculation::getInstance(); $calculation = Calculation::getInstance();
$calculation->setLocale('en_us'); $calculation->setLocale($this->locale);
} }
/** /**

View File

@ -9,13 +9,29 @@ use PHPUnit\Framework\TestCase;
class DayTest extends TestCase class DayTest extends TestCase
{ {
private $compatibilityMode;
private $returnDateType;
private $excelCalendar;
protected function setUp(): void protected function setUp(): void
{ {
$this->compatibilityMode = Functions::getCompatibilityMode();
$this->returnDateType = Functions::getReturnDateType();
$this->excelCalendar = Date::getExcelCalendar();
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900); Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
} }
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
Functions::setReturnDateType($this->returnDateType);
Date::setExcelCalendar($this->excelCalendar);
}
/** /**
* @dataProvider providerDAY * @dataProvider providerDAY
* *

View File

@ -8,11 +8,19 @@ use PHPUnit\Framework\TestCase;
class CountTest extends TestCase class CountTest extends TestCase
{ {
private $compatibilityMode;
protected function setUp(): void protected function setUp(): void
{ {
$this->compatibilityMode = Functions::getCompatibilityMode();
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
} }
protected function tearDown(): void
{
Functions::setCompatibilityMode($this->compatibilityMode);
}
/** /**
* @dataProvider providerBasicCOUNT * @dataProvider providerBasicCOUNT
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class CharTest extends TestCase class CharTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerCHAR * @dataProvider providerCHAR
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class CleanTest extends TestCase class CleanTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerCLEAN * @dataProvider providerCLEAN
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class CodeTest extends TestCase class CodeTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerCODE * @dataProvider providerCODE
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class ConcatenateTest extends TestCase class ConcatenateTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerCONCATENATE * @dataProvider providerCONCATENATE
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class DollarTest extends TestCase class DollarTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerDOLLAR * @dataProvider providerDOLLAR
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class ExactTest extends TestCase class ExactTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerEXACT * @dataProvider providerEXACT
* *
@ -33,10 +15,6 @@ class ExactTest extends TestCase
*/ */
public function testEXACT($expectedResult, ...$args): void public function testEXACT($expectedResult, ...$args): void
{ {
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(' ');
StringHelper::setCurrencyCode('$');
$result = TextData::EXACT(...$args); $result = TextData::EXACT(...$args);
self::assertSame($expectedResult, $result); self::assertSame($expectedResult, $result);
} }

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class FindTest extends TestCase class FindTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerFIND * @dataProvider providerFIND
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class FixedTest extends TestCase class FixedTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerFIXED * @dataProvider providerFIXED
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class LeftTest extends TestCase class LeftTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerLEFT * @dataProvider providerLEFT
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class LenTest extends TestCase class LenTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerLEN * @dataProvider providerLEN
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class LowerTest extends TestCase class LowerTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerLOWER * @dataProvider providerLOWER
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class MidTest extends TestCase class MidTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerMID * @dataProvider providerMID
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class NumberValueTest extends TestCase class NumberValueTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerNUMBERVALUE * @dataProvider providerNUMBERVALUE
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class ProperTest extends TestCase class ProperTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerPROPER * @dataProvider providerPROPER
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class ReplaceTest extends TestCase class ReplaceTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerREPLACE * @dataProvider providerREPLACE
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class RightTest extends TestCase class RightTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerRIGHT * @dataProvider providerRIGHT
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class SearchTest extends TestCase class SearchTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerSEARCH * @dataProvider providerSEARCH
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class SubstituteTest extends TestCase class SubstituteTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerSUBSTITUTE * @dataProvider providerSUBSTITUTE
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class TTest extends TestCase class TTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerT * @dataProvider providerT
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class TextJoinTest extends TestCase class TextJoinTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerTEXTJOIN * @dataProvider providerTEXTJOIN
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class TextTest extends TestCase class TextTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerTEXT * @dataProvider providerTEXT
* *
@ -32,11 +14,6 @@ class TextTest extends TestCase
*/ */
public function testTEXT($expectedResult, ...$args): void public function testTEXT($expectedResult, ...$args): void
{ {
// Enforce decimal and thousands separator values to UK/US, and currency code to USD
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
$result = TextData::TEXTFORMAT(...$args); $result = TextData::TEXTFORMAT(...$args);
self::assertEquals($expectedResult, $result); self::assertEquals($expectedResult, $result);
} }

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class TrimTest extends TestCase class TrimTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerTRIM * @dataProvider providerTRIM
* *

View File

@ -2,29 +2,11 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class UpperTest extends TestCase class UpperTest extends TestCase
{ {
protected function setUp(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
protected function tearDown(): void
{
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
}
/** /**
* @dataProvider providerUPPER * @dataProvider providerUPPER
* *

View File

@ -2,27 +2,30 @@
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData; namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\TextData;
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
use PhpOffice\PhpSpreadsheet\Calculation\TextData; use PhpOffice\PhpSpreadsheet\Calculation\TextData;
use PhpOffice\PhpSpreadsheet\Shared\StringHelper; use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
class ValueTest extends TestCase class ValueTest extends TestCase
{ {
private $currencyCode;
private $decimalSeparator;
private $thousandsSeparator;
protected function setUp(): void protected function setUp(): void
{ {
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); $this->currencyCode = StringHelper::getCurrencyCode();
StringHelper::setDecimalSeparator('.'); $this->decimalSeparator = StringHelper::getDecimalSeparator();
StringHelper::setThousandsSeparator(','); $this->thousandsSeparator = StringHelper::getThousandsSeparator();
StringHelper::setCurrencyCode('$');
} }
protected function tearDown(): void protected function tearDown(): void
{ {
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); StringHelper::setCurrencyCode($this->currencyCode);
StringHelper::setDecimalSeparator('.'); StringHelper::setDecimalSeparator($this->decimalSeparator);
StringHelper::setThousandsSeparator(','); StringHelper::setThousandsSeparator($this->thousandsSeparator);
StringHelper::setCurrencyCode('$');
} }
/** /**

View File

@ -10,16 +10,22 @@ use PHPUnit\Framework\TestCase;
class FunctionsTest extends TestCase class FunctionsTest extends TestCase
{ {
private $compatibilityMode;
private $returnDate;
protected function setUp(): void protected function setUp(): void
{ {
$this->compatibilityMode = Functions::getCompatibilityMode();
$this->returnDate = Functions::getReturnDateType();
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); Functions::setReturnDateType(Functions::RETURNDATE_EXCEL);
} }
protected function tearDown(): void protected function tearDown(): void
{ {
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); Functions::setCompatibilityMode($this->compatibilityMode);
Functions::setReturnDateType(Functions::RETURNDATE_EXCEL); Functions::setReturnDateType($this->returnDate);
} }
public function testCompatibilityMode(): void public function testCompatibilityMode(): void

View File

@ -13,6 +13,26 @@ use PHPUnit\Framework\TestCase;
class AdvancedValueBinderTest extends TestCase class AdvancedValueBinderTest extends TestCase
{ {
private $currencyCode;
private $decimalSeparator;
private $thousandsSeparator;
protected function setUp(): void
{
$this->currencyCode = StringHelper::getCurrencyCode();
$this->decimalSeparator = StringHelper::getDecimalSeparator();
$this->thousandsSeparator = StringHelper::getThousandsSeparator();
}
protected function tearDown(): void
{
StringHelper::setCurrencyCode($this->currencyCode);
StringHelper::setDecimalSeparator($this->decimalSeparator);
StringHelper::setThousandsSeparator($this->thousandsSeparator);
}
public function provider() public function provider()
{ {
$currencyUSD = NumberFormat::FORMAT_CURRENCY_USD_SIMPLE; $currencyUSD = NumberFormat::FORMAT_CURRENCY_USD_SIMPLE;

View File

@ -7,14 +7,30 @@ use PHPUnit\Framework\TestCase;
class StringHelperTest extends TestCase class StringHelperTest extends TestCase
{ {
private $currencyCode;
private $decimalSeparator;
private $thousandsSeparator;
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$this->currencyCode = StringHelper::getCurrencyCode();
$this->decimalSeparator = StringHelper::getDecimalSeparator();
$this->thousandsSeparator = StringHelper::getThousandsSeparator();
// Reset Currency Code // Reset Currency Code
StringHelper::setCurrencyCode(null); StringHelper::setCurrencyCode(null);
} }
protected function tearDown(): void
{
StringHelper::setCurrencyCode($this->currencyCode);
StringHelper::setDecimalSeparator($this->decimalSeparator);
StringHelper::setThousandsSeparator($this->thousandsSeparator);
}
public function testGetIsIconvEnabled(): void public function testGetIsIconvEnabled(): void
{ {
$result = StringHelper::getIsIconvEnabled(); $result = StringHelper::getIsIconvEnabled();

View File

@ -8,12 +8,28 @@ use PHPUnit\Framework\TestCase;
class NumberFormatTest extends TestCase class NumberFormatTest extends TestCase
{ {
private $currencyCode;
private $decimalSeparator;
private $thousandsSeparator;
protected function setUp(): void protected function setUp(): void
{ {
$this->currencyCode = StringHelper::getCurrencyCode();
$this->decimalSeparator = StringHelper::getDecimalSeparator();
$this->thousandsSeparator = StringHelper::getThousandsSeparator();
StringHelper::setDecimalSeparator('.'); StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(','); StringHelper::setThousandsSeparator(',');
} }
protected function tearDown(): void
{
StringHelper::setCurrencyCode($this->currencyCode);
StringHelper::setDecimalSeparator($this->decimalSeparator);
StringHelper::setThousandsSeparator($this->thousandsSeparator);
}
/** /**
* @dataProvider providerNumberFormat * @dataProvider providerNumberFormat
* *

View File

@ -10,12 +10,16 @@ use PhpOffice\PhpSpreadsheetTests\Functional;
class HtmlNumberFormatTest extends Functional\AbstractFunctional class HtmlNumberFormatTest extends Functional\AbstractFunctional
{ {
private $currency;
private $decsep; private $decsep;
private $thosep; private $thosep;
protected function setUp(): void protected function setUp(): void
{ {
$this->currency = StringHelper::getCurrencyCode();
StringHelper::setCurrencyCode('$');
$this->decsep = StringHelper::getDecimalSeparator(); $this->decsep = StringHelper::getDecimalSeparator();
StringHelper::setDecimalSeparator('.'); StringHelper::setDecimalSeparator('.');
$this->thosep = StringHelper::getThousandsSeparator(); $this->thosep = StringHelper::getThousandsSeparator();
@ -24,6 +28,7 @@ class HtmlNumberFormatTest extends Functional\AbstractFunctional
protected function tearDown(): void protected function tearDown(): void
{ {
StringHelper::setCurrencyCode($this->currency);
StringHelper::setDecimalSeparator($this->decsep); StringHelper::setDecimalSeparator($this->decsep);
StringHelper::setThousandsSeparator($this->thosep); StringHelper::setThousandsSeparator($this->thosep);
} }