Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,47 @@
#[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);

Check failure on line 62 in tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.2

Failed asserting that 63 matches expected 99.

Check failure on line 62 in tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.3

Failed asserting that 63 matches expected 99.

Check failure on line 62 in tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.5

Failed asserting that 63 matches expected 99.

Check failure on line 62 in tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php

View workflow job for this annotation

GitHub Actions / PHP nightly

Failed asserting that 63 matches expected 99.

Check failure on line 62 in tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.1

Failed asserting that 63 matches expected 99.

Check failure on line 62 in tests/PhpSpreadsheetTests/Calculation/Functions/TextData/CodeTest.php

View workflow job for this annotation

GitHub Actions / PHP 8.4

Failed asserting that 63 matches expected 99.
}

public static function providerCODE(): array
Expand Down
7 changes: 5 additions & 2 deletions tests/data/Calculation/TextData/CODE.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
'ƒ',
],
[
[63, 0x2105],
[99, 0x2105, 63],
'℅',
],
[
Expand All @@ -91,5 +91,8 @@
2,
"\x02",
],
'omitted argument' => ['exception'],
'omitted argument' => [
'exception',
'omitted',
],
];
Loading