From 36e9e864e6bb0df60a4124476a711323815b4b2b Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Fri, 10 Mar 2023 05:16:51 +0100 Subject: [PATCH] Additional edge-case tests --- CONTRIBUTING.md | 6 +++- .../Functions/DateTime/DateDifTest.php | 4 +++ .../Functions/DateTime/DateTest.php | 4 +++ .../Functions/DateTime/DateValueTest.php | 9 ++++-- .../Functions/DateTime/DayTest.php | 14 +++++++++- .../Functions/DateTime/Days360Test.php | 7 ++++- .../Functions/DateTime/DaysTest.php | 4 +++ .../Functions/DateTime/EDateTest.php | 24 ++++++++++++++++ .../Functions/DateTime/EoMonthTest.php | 24 ++++++++++++++++ .../Functions/DateTime/HourTest.php | 7 ++++- .../Functions/DateTime/IsoWeekNumTest.php | 28 ++++++++++++++++++- .../Functions/DateTime/MinuteTest.php | 7 ++++- .../Functions/DateTime/MonthTest.php | 7 ++++- .../Functions/DateTime/NetworkDaysTest.php | 4 +++ .../Functions/DateTime/SecondTest.php | 7 ++++- .../Functions/DateTime/TimeTest.php | 2 ++ .../Functions/DateTime/TimeValueTest.php | 7 ++++- .../Functions/DateTime/WeekDayTest.php | 7 ++++- .../Functions/DateTime/WeekNumTest.php | 8 +++++- .../Functions/DateTime/WorkDayTest.php | 4 +++ .../Functions/DateTime/YearFracTest.php | 4 +++ .../Functions/DateTime/YearTest.php | 7 ++++- .../Functions/FormulaArguments.php | 8 +++--- tests/data/Calculation/DateTime/TIME.php | 3 +- 24 files changed, 187 insertions(+), 19 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 957dc4811..09794b565 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -13,6 +13,7 @@ If you would like to contribute, here are some notes and guidelines: - Please include Unit Tests to verify that a bug exists, and that this PR fixes it. - Please include Unit Tests to show that a new Feature works as expected. - Please don't "bundle" several changes into a single PR; submit a PR for each discrete change/fix. + - Remember to update documentation if necessary. - [Helpful article about forking](https://help.github.com/articles/fork-a-repo/ "Forking a GitHub repository") - [Helpful article about pull requests](https://help.github.com/articles/using-pull-requests/ "Pull Requests") @@ -24,8 +25,11 @@ When writing Unit Tests, please - Put all assertions in the Test itself, not in an abstract class that the Test extends (even if this means code duplication between tests). - Include any necessary `setup()` and `tearDown()` in the Test itself. - If you change any global settings (such as system locale, or Compatibility Mode for Excel Function tests), make sure that you reset to the default in the `tearDown()`. + - Use the `ExcelError` functions in assertions for Excel Error values in Excel Function implementations. +
Not only does it reduce the risk of typos; but at some point in the future, ExcelError values will be an object rather than a string, and we won't then need to update all the tests. + - Don't over-complicate test code by testing happy and unhappy paths in the same test. -This makes it easier to see exactly what is being tested when reviewing the PR. I want to be able to see it in the PR, not have to hunt in other classes to see what the test is doing. +This makes it easier to see exactly what is being tested when reviewing the PR. I want to be able to see it in the PR, not have to hunt in other unchanged classes to see what the test is doing. ## How to release diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateDifTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateDifTest.php index 47476a83a..7d2ec9852 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateDifTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateDifTest.php @@ -61,6 +61,8 @@ class DateDifTest extends TestCase ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); + + $spreadsheet->disconnectWorksheets(); } public function providerDATEDIF(): array @@ -85,6 +87,8 @@ class DateDifTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyDATEDIF(): array diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateTest.php index 5fc0d9cac..a9210fe33 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateTest.php @@ -85,6 +85,8 @@ class DateTest extends TestCase ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); + + $spreadsheet->disconnectWorksheets(); } public function providerDATE(): array @@ -109,6 +111,8 @@ class DateTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyDATE(): array diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateValueTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateValueTest.php index a85c3111a..15dc6158f 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateValueTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DateValueTest.php @@ -48,7 +48,7 @@ class DateValueTest extends TestCase private function parseTemplatedExpectation(string $expectedResult): string { - return DateValue::fromString( + return (string) DateValue::fromString( (new DateTimeImmutable( str_replace('Y', (new DateTimeImmutable('now'))->format('Y'), $expectedResult) ))->format('Y-m-d') @@ -66,7 +66,8 @@ class DateValueTest extends TestCase $expectedResult = $this->parseTemplatedExpectation($expectedResult); } - $result = DateValue::fromString(/** @scrutinizer ignore-type */ ...$args); + /** @scrutinizer ignore-call */ + $result = DateValue::fromString(...$args); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-8); } @@ -112,6 +113,8 @@ class DateValueTest extends TestCase ->getCell('A1') ->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-8); + + $spreadsheet->disconnectWorksheets(); } public function providerDATEVALUE(): array @@ -136,6 +139,8 @@ class DateValueTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyDATEVALUE(): array diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DayTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DayTest.php index 2b1a49a56..73b5012f5 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DayTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DayTest.php @@ -38,7 +38,8 @@ class DayTest extends TestCase */ public function testDirectCallToDAY($expectedResultExcel, ...$args): void { - $result = DateParts::day(/** @scrutinizer ignore-type */ ...$args); + /** @scrutinizer ignore-call */ + $result = DateParts::day(...$args); self::assertSame($expectedResultExcel, $result); } @@ -76,6 +77,8 @@ class DayTest extends TestCase ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); + + $spreadsheet->disconnectWorksheets(); } public function providerDAY(): array @@ -92,6 +95,7 @@ class DayTest extends TestCase { Functions::setCompatibilityMode(Functions::COMPATIBILITY_OPENOFFICE); + /** @scrutinizer ignore-call */ $result = DateParts::day(...$args); self::assertSame($expectedResultOpenOffice, $result); } @@ -136,6 +140,8 @@ class DayTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyDAY(): array @@ -145,6 +151,12 @@ class DayTest extends TestCase ]; } + public function testDirectCallToDAYWithNull(): void + { + $result = DateParts::day(null); + self::assertSame(0, $result); + } + /** * @dataProvider providerDayArray */ diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/Days360Test.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/Days360Test.php index c2de9925b..f83010499 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/Days360Test.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/Days360Test.php @@ -23,7 +23,8 @@ class Days360Test extends TestCase */ public function testDirectCallToDAYS360($expectedResult, ...$args): void { - $result = Days360::between(/** @scrutinizer ignore-type */ ...$args); + /** @scrutinizer ignore-call */ + $result = Days360::between(...$args); self::assertSame($expectedResult, $result); } @@ -61,6 +62,8 @@ class Days360Test extends TestCase ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); + + $spreadsheet->disconnectWorksheets(); } public function providerDAYS360(): array @@ -85,6 +88,8 @@ class Days360Test extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyDAYS360(): array diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DaysTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DaysTest.php index 5daeb7ca2..4f2745574 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DaysTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/DaysTest.php @@ -60,6 +60,8 @@ class DaysTest extends TestCase ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); + + $spreadsheet->disconnectWorksheets(); } public function providerDAYS(): array @@ -84,6 +86,8 @@ class DaysTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyDAYS(): array diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EDateTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EDateTest.php index 38d6c6d8e..b43f4923b 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EDateTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EDateTest.php @@ -58,6 +58,28 @@ class EDateTest extends TestCase self::assertSame($expectedResult, $result); } + /** + * @dataProvider providerEDATE + * + * @param mixed $expectedResult + */ + public function testEDATEInWorksheet($expectedResult, ...$args): void + { + $arguments = new FormulaArguments(...$args); + + $spreadsheet = new Spreadsheet(); + $worksheet = $spreadsheet->getActiveSheet(); + $argumentCells = $arguments->populateWorksheet($worksheet); + $formula = "=EDATE({$argumentCells})"; + + $result = $worksheet->setCellValue('A1', $formula) + ->getCell('A1') + ->getCalculatedValue(); + self::assertSame($expectedResult, $result); + + $spreadsheet->disconnectWorksheets(); + } + public function providerEDATE(): array { return require 'tests/data/Calculation/DateTime/EDATE.php'; @@ -80,6 +102,8 @@ class EDateTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyEDATE(): array diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EoMonthTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EoMonthTest.php index 624fdb680..0ff99a667 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EoMonthTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/EoMonthTest.php @@ -58,6 +58,28 @@ class EoMonthTest extends TestCase self::assertSame($expectedResult, $result); } + /** + * @dataProvider providerEOMONTH + * + * @param mixed $expectedResult + */ + public function testEOMONTHInWorksheet($expectedResult, ...$args): void + { + $arguments = new FormulaArguments(...$args); + + $spreadsheet = new Spreadsheet(); + $worksheet = $spreadsheet->getActiveSheet(); + $argumentCells = $arguments->populateWorksheet($worksheet); + $formula = "=EOMONTH({$argumentCells})"; + + $result = $worksheet->setCellValue('A1', $formula) + ->getCell('A1') + ->getCalculatedValue(); + self::assertSame($expectedResult, $result); + + $spreadsheet->disconnectWorksheets(); + } + public function providerEOMONTH(): array { return require 'tests/data/Calculation/DateTime/EOMONTH.php'; @@ -80,6 +102,8 @@ class EoMonthTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyEOMONTH(): array diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/HourTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/HourTest.php index 4a1bb8d4d..d291d6d7d 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/HourTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/HourTest.php @@ -18,7 +18,8 @@ class HourTest extends TestCase */ public function testDirectCallToHOUR($expectedResult, ...$args): void { - $result = TimeParts::hour(/** @scrutinizer ignore-type */ ...$args); + /** @scrutinizer ignore-call */ + $result = TimeParts::hour(...$args); self::assertSame($expectedResult, $result); } @@ -56,6 +57,8 @@ class HourTest extends TestCase ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); + + $spreadsheet->disconnectWorksheets(); } public function providerHOUR(): array @@ -80,6 +83,8 @@ class HourTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyHOUR(): array diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/IsoWeekNumTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/IsoWeekNumTest.php index 4e034a436..5b99b4a91 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/IsoWeekNumTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/IsoWeekNumTest.php @@ -39,7 +39,8 @@ class IsoWeekNumTest extends TestCase */ public function testDirectCallToISOWEEKNUM($expectedResult, ...$args): void { - $result = Week::isoWeekNumber(/** @scrutinizer ignore-type */ ...$args); + /** @scrutinizer ignore-call */ + $result = Week::isoWeekNumber(...$args); self::assertSame($expectedResult, $result); } @@ -60,6 +61,28 @@ class IsoWeekNumTest extends TestCase self::assertSame($expectedResult, $result); } + /** + * @dataProvider providerISOWEEKNUM + * + * @param mixed $expectedResult + */ + public function testISOWEEKNUMInWorksheet($expectedResult, ...$args): void + { + $arguments = new FormulaArguments(...$args); + + $spreadsheet = new Spreadsheet(); + $worksheet = $spreadsheet->getActiveSheet(); + $argumentCells = $arguments->populateWorksheet($worksheet); + $formula = "=ISOWEEKNUM({$argumentCells})"; + + $result = $worksheet->setCellValue('A1', $formula) + ->getCell('A1') + ->getCalculatedValue(); + self::assertSame($expectedResult, $result); + + $spreadsheet->disconnectWorksheets(); + } + public function providerISOWEEKNUM(): array { return require 'tests/data/Calculation/DateTime/ISOWEEKNUM.php'; @@ -82,6 +105,8 @@ class IsoWeekNumTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyISOWEEKNUM(): array @@ -100,6 +125,7 @@ class IsoWeekNumTest extends TestCase { SharedDate::setExcelCalendar(SharedDate::CALENDAR_MAC_1904); + /** @scrutinizer ignore-call */ $result = Week::isoWeekNumber(...$args); self::assertSame($expectedResult, $result); } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MinuteTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MinuteTest.php index de00046a4..a01acdf11 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MinuteTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MinuteTest.php @@ -18,7 +18,8 @@ class MinuteTest extends TestCase */ public function testDirectCallToMINUTE($expectedResult, ...$args): void { - $result = TimeParts::MINUTE(/** @scrutinizer ignore-type */ ...$args); + /** @scrutinizer ignore-call */ + $result = TimeParts::MINUTE(...$args); self::assertSame($expectedResult, $result); } @@ -56,6 +57,8 @@ class MinuteTest extends TestCase ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); + + $spreadsheet->disconnectWorksheets(); } public function providerMINUTE(): array @@ -80,6 +83,8 @@ class MinuteTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyMINUTE(): array diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MonthTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MonthTest.php index bc007ee7a..8cdb81e3a 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MonthTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/MonthTest.php @@ -18,7 +18,8 @@ class MonthTest extends TestCase */ public function testDirectCallToMONTH($expectedResultExcel, ...$args): void { - $result = DateParts::month(/** @scrutinizer ignore-type */ ...$args); + /** @scrutinizer ignore-call */ + $result = DateParts::month(...$args); self::assertSame($expectedResultExcel, $result); } @@ -56,6 +57,8 @@ class MonthTest extends TestCase ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); + + $spreadsheet->disconnectWorksheets(); } public function providerMONTH(): array @@ -80,6 +83,8 @@ class MonthTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyMONTH(): array diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/NetworkDaysTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/NetworkDaysTest.php index 524a7c887..1685e6670 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/NetworkDaysTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/NetworkDaysTest.php @@ -55,6 +55,8 @@ class NetworkDaysTest extends TestCase ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); + + $spreadsheet->disconnectWorksheets(); } public function providerNETWORKDAYS(): array @@ -79,6 +81,8 @@ class NetworkDaysTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyNETWORKDAYS(): array diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/SecondTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/SecondTest.php index cfaba23e0..3c67c38cb 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/SecondTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/SecondTest.php @@ -17,7 +17,8 @@ class SecondTest extends TestCase */ public function testDirectCallToSECOND($expectedResult, ...$args): void { - $result = TimeParts::second(/** @scrutinizer ignore-type */ ...$args); + /** @scrutinizer ignore-call */ + $result = TimeParts::second(...$args); self::assertSame($expectedResult, $result); } @@ -55,6 +56,8 @@ class SecondTest extends TestCase ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); + + $spreadsheet->disconnectWorksheets(); } public function providerSECOND(): array @@ -79,6 +82,8 @@ class SecondTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappySECOND(): array diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeTest.php index d3c7d7afa..9fbe6b205 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeTest.php @@ -89,6 +89,8 @@ class TimeTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyTIME(): array diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeValueTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeValueTest.php index 63d078f0d..6ad3675c1 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeValueTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/TimeValueTest.php @@ -38,7 +38,8 @@ class TimeValueTest extends TestCase */ public function testDirectCallToTIMEVALUE($expectedResult, ...$args): void { - $result = TimeValue::fromString(/** @scrutinizer ignore-type */ ...$args); + /** @scrutinizer ignore-call */ + $result = TimeValue::fromString(...$args); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-8); } @@ -76,6 +77,8 @@ class TimeValueTest extends TestCase ->getCell('A1') ->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-8); + + $spreadsheet->disconnectWorksheets(); } public function providerTIMEVALUE(): array @@ -122,6 +125,8 @@ class TimeValueTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyTIMEVALUE(): array diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekDayTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekDayTest.php index 02ad1dabf..7316774f7 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekDayTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekDayTest.php @@ -37,7 +37,8 @@ class WeekDayTest extends TestCase */ public function testDirectCallToWEEKDAY($expectedResult, ...$args): void { - $result = Week::day(/** @scrutinizer ignore-type */ ...$args); + /** @scrutinizer ignore-call */ + $result = Week::day(...$args); self::assertSame($expectedResult, $result); } @@ -75,6 +76,8 @@ class WeekDayTest extends TestCase ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); + + $spreadsheet->disconnectWorksheets(); } public function providerWEEKDAY(): array @@ -99,6 +102,8 @@ class WeekDayTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyWEEKDAY(): array diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekNumTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekNumTest.php index fad7bc68e..a89760760 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekNumTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WeekNumTest.php @@ -38,7 +38,8 @@ class WeekNumTest extends TestCase */ public function testDirectCallToWEEKNUM($expectedResult, ...$args): void { - $result = Week::number(/** @scrutinizer ignore-type */ ...$args); + /** @scrutinizer ignore-call */ + $result = Week::number(...$args); self::assertSame($expectedResult, $result); } @@ -76,6 +77,8 @@ class WeekNumTest extends TestCase ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); + + $spreadsheet->disconnectWorksheets(); } public function providerWEEKNUM(): array @@ -100,6 +103,8 @@ class WeekNumTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyWEEKNUM(): array @@ -118,6 +123,7 @@ class WeekNumTest extends TestCase { SharedDate::setExcelCalendar(SharedDate::CALENDAR_MAC_1904); + /** @scrutinizer ignore-call */ $result = Week::number(...$args); self::assertSame($expectedResult, $result); } diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WorkDayTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WorkDayTest.php index c126e95fd..5db9dfb8f 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WorkDayTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/WorkDayTest.php @@ -55,6 +55,8 @@ class WorkDayTest extends TestCase ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); + + $spreadsheet->disconnectWorksheets(); } public function providerWORKDAY(): array @@ -79,6 +81,8 @@ class WorkDayTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyWORKDAY(): array diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/YearFracTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/YearFracTest.php index 825317794..c241ec2ac 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/YearFracTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/YearFracTest.php @@ -56,6 +56,8 @@ class YearFracTest extends TestCase ->getCell('A1') ->getCalculatedValue(); self::assertEqualsWithDelta($expectedResult, $result, 1.0e-6); + + $spreadsheet->disconnectWorksheets(); } public function providerYEARFRAC(): array @@ -80,6 +82,8 @@ class YearFracTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyYEARFRAC(): array diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/YearTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/YearTest.php index f7be47883..1f99c5e96 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/YearTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/DateTime/YearTest.php @@ -17,7 +17,8 @@ class YearTest extends TestCase */ public function testDirectCallToYEAR($expectedResultExcel, ...$args): void { - $result = DateParts::year(/** @scrutinizer ignore-type */ ...$args); + /** @scrutinizer ignore-call */ + $result = DateParts::year(...$args); self::assertSame($expectedResultExcel, $result); } @@ -55,6 +56,8 @@ class YearTest extends TestCase ->getCell('A1') ->getCalculatedValue(); self::assertSame($expectedResult, $result); + + $spreadsheet->disconnectWorksheets(); } public function providerYEAR(): array @@ -79,6 +82,8 @@ class YearTest extends TestCase $worksheet->setCellValue('A1', $formula) ->getCell('A1') ->getCalculatedValue(); + + $spreadsheet->disconnectWorksheets(); } public function providerUnhappyYEAR(): array diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/FormulaArguments.php b/tests/PhpSpreadsheetTests/Calculation/Functions/FormulaArguments.php index 7b0ed08e9..eea1ac3db 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/FormulaArguments.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/FormulaArguments.php @@ -52,7 +52,7 @@ class FormulaArguments { $columns = []; foreach ($value as $column) { - $columns[] = self::stringify($column); + $columns[] = $this->stringify($column); } return implode(',', $columns); @@ -66,9 +66,9 @@ class FormulaArguments $matrix = []; foreach ($value as $row) { if (is_array($row)) { - $matrix[] = self::matrixRows($row); + $matrix[] = $this->matrixRows($row); } else { - $matrix[] = self::stringify($row); + $matrix[] = $this->stringify($row); } } @@ -81,7 +81,7 @@ class FormulaArguments private function stringify($value): string { if (is_array($value)) { - return '{' . self::makeMatrix($value) . '}'; + return '{' . $this->makeMatrix($value) . '}'; } elseif (null === $value) { return ''; } elseif (is_string($value)) { diff --git a/tests/data/Calculation/DateTime/TIME.php b/tests/data/Calculation/DateTime/TIME.php index 59a8bb2b0..36460cdc3 100644 --- a/tests/data/Calculation/DateTime/TIME.php +++ b/tests/data/Calculation/DateTime/TIME.php @@ -9,7 +9,8 @@ return [ [0.781539351852, 18, 45, 25], [0.647800925926, 15, 32, 50], [0.458321759259, 11, false, -1], - [0.584780092593, 13, 62, 5], + [0.584780092593, 13, 62, 5], // Minutes > 60 + [0.550868055556, 13, 12, 75], // Seconds > 60 [0.319641203704, 9, -80, 17], [ExcelError::NAN(), 2, -120, -1], [1.1574074E-5, 2, -120, 1],