diff --git a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php index ddfe1fa554..e33eb5d8f3 100644 --- a/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php +++ b/tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php @@ -19,40 +19,45 @@ protected function tearDown(): void #[DataProvider('providerCODE')] public function testCODE(mixed $expectedResult, mixed $character = 'omitted'): void { - // If expected is array, 1st is for CODE, 2nd for UNICODE, - // 3rd is for Mac CODE if different from Windows. - if (is_array($expectedResult)) { - $expectedResult = $expectedResult[0]; - } - $this->mightHaveException($expectedResult); - $sheet = $this->getSheet(); - if ($character === 'omitted') { - $sheet->getCell('B1')->setValue('=CODE()'); - } else { - $this->setCell('A1', $character); - $sheet->getCell('B1')->setValue('=CODE(A1)'); - } - $result = $sheet->getCell('B1')->getCalculatedValue(); - self::assertEquals($expectedResult, $result); + $this->runCodeTest($expectedResult, $character, false); } #[DataProvider('providerCODE')] public function testMacCODE(mixed $expectedResult, mixed $character = 'omitted'): void { CC::setMacCharacterSet(); - // If expected is array, 1st is for CODE, 2nd for UNICODE, - // 3rd is for Mac CODE if different from Windows. + $this->runCodeTest($expectedResult, $character, true); + } + + /** + * Helper method for running CODE tests. + * + * @param mixed $expectedResult Expected result (can be an array for CODE/UNICODE/Mac) + * @param mixed $character Symbol for testing + * @param bool $isMacMode Use Mac character set + */ + private function runCodeTest(mixed $expectedResult, mixed $character, bool $isMacMode): void + { + // If the expected result is an array: + // 1st element for CODE (Windows) + // 2nd element for UNICODE + // 3rd element for Mac CODE (if different from Windows) if (is_array($expectedResult)) { - $expectedResult = $expectedResult[2] ?? $expectedResult[0]; + $expectedResult = $isMacMode + ? ($expectedResult[2] ?? $expectedResult[0]) + : $expectedResult[0]; } + $this->mightHaveException($expectedResult); $sheet = $this->getSheet(); + if ($character === 'omitted') { $sheet->getCell('B1')->setValue('=CODE()'); } else { $this->setCell('A1', $character); $sheet->getCell('B1')->setValue('=CODE(A1)'); } + $result = $sheet->getCell('B1')->getCalculatedValue(); self::assertEquals($expectedResult, $result); } diff --git a/tests/data/Calculation/TextData/CODE.php b/tests/data/Calculation/TextData/CODE.php index 32bb0ff198..9b9dcda6d0 100644 --- a/tests/data/Calculation/TextData/CODE.php +++ b/tests/data/Calculation/TextData/CODE.php @@ -64,7 +64,7 @@ 'ƒ', ], [ - [63, 0x2105], + [99, 0x2105, 63], '℅', ], [ @@ -91,5 +91,8 @@ 2, "\x02", ], - 'omitted argument' => ['exception'], + 'omitted argument' => [ + 'exception', + 'omitted', + ], ];