Skip to content

Commit 3dcdbca

Browse files
committed
Redo ComplexAssert
Its use is already causes an issue with Phpstan. It uses interfaces marked as internal by Phpunit, and it will not work with Phpunit 12. It is more complicated than needed. This PR corrects all these problems. It also corrects a handful of other problems that will show up with Phpunit 12. Only tests are changed - no source code.
1 parent 8f7a401 commit 3dcdbca

32 files changed

+288
-826
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/analysis
33
/vendor/
44
/phpunit.xml
5+
.phpunit.result.cache
56

67
## IDE support
78
*.buildpath

tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ComplexTest.php

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ public function testDirectCallToCOMPLEX(mixed $expectedResult, mixed ...$args):
2020
self::assertSame($expectedResult, $result);
2121
}
2222

23-
private function trimIfQuoted(string $value): string
24-
{
25-
return trim($value, '"');
26-
}
27-
2823
#[DataProvider('providerCOMPLEX')]
2924
public function testCOMPLEXAsFormula(mixed $expectedResult, mixed ...$args): void
3025
{
@@ -34,8 +29,8 @@ public function testCOMPLEXAsFormula(mixed $expectedResult, mixed ...$args): voi
3429
$formula = "=COMPLEX({$arguments})";
3530

3631
/** @var float|int|string */
37-
$result = $calculation->_calculateFormulaValue($formula);
38-
self::assertSame($expectedResult, $this->trimIfQuoted((string) $result));
32+
$result = $calculation->calculateFormula($formula);
33+
self::assertSame($expectedResult, $result);
3934
}
4035

4136
#[DataProvider('providerCOMPLEX')]
@@ -68,7 +63,7 @@ public function testComplexArray(array $expectedResult, string $real, string $im
6863
$calculation = Calculation::getInstance();
6964

7065
$formula = "=COMPLEX({$real}, {$imaginary})";
71-
$result = $calculation->_calculateFormulaValue($formula);
66+
$result = $calculation->calculateFormula($formula);
7267
self::assertEquals($expectedResult, $result);
7368
}
7469

tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImConjugateTest.php

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,21 @@
77
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
88
use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions;
99
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException;
10-
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
1110
use PhpOffice\PhpSpreadsheet\Spreadsheet;
1211
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
1312
use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert;
14-
use PHPUnit\Framework\TestCase;
13+
use PHPUnit\Framework\Attributes\DataProvider;
1514

16-
class ImConjugateTest extends TestCase
15+
class ImConjugateTest extends ComplexAssert
1716
{
18-
const COMPLEX_PRECISION = 1E-12;
19-
20-
private ComplexAssert $complexAssert;
21-
22-
protected function setUp(): void
23-
{
24-
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
25-
$this->complexAssert = new ComplexAssert();
26-
}
27-
28-
#[\PHPUnit\Framework\Attributes\DataProvider('providerIMCONJUGATE')]
17+
#[DataProvider('providerIMCONJUGATE')]
2918
public function testDirectCallToIMCONJUGATE(string $expectedResult, string $arg): void
3019
{
3120
$result = ComplexFunctions::IMCONJUGATE($arg);
32-
self::assertTrue(
33-
$this->complexAssert->assertComplexEquals($expectedResult, $result, self::COMPLEX_PRECISION),
34-
$this->complexAssert->getErrorMessage()
35-
);
36-
}
37-
38-
private function trimIfQuoted(string $value): string
39-
{
40-
return trim($value, '"');
21+
$this->assertComplexEquals($expectedResult, $result);
4122
}
4223

43-
#[\PHPUnit\Framework\Attributes\DataProvider('providerIMCONJUGATE')]
24+
#[DataProvider('providerIMCONJUGATE')]
4425
public function testIMCONJUGATEAsFormula(mixed $expectedResult, mixed ...$args): void
4526
{
4627
$arguments = new FormulaArguments(...$args);
@@ -49,14 +30,11 @@ public function testIMCONJUGATEAsFormula(mixed $expectedResult, mixed ...$args):
4930
$formula = "=IMCONJUGATE({$arguments})";
5031

5132
/** @var float|int|string */
52-
$result = $calculation->_calculateFormulaValue($formula);
53-
self::assertTrue(
54-
$this->complexAssert->assertComplexEquals($expectedResult, $this->trimIfQuoted((string) $result), self::COMPLEX_PRECISION),
55-
$this->complexAssert->getErrorMessage()
56-
);
33+
$result = $calculation->calculateFormula($formula);
34+
$this->assertComplexEquals($expectedResult, $result);
5735
}
5836

59-
#[\PHPUnit\Framework\Attributes\DataProvider('providerIMCONJUGATE')]
37+
#[DataProvider('providerIMCONJUGATE')]
6038
public function testIMCONJUGATEInWorksheet(mixed $expectedResult, mixed ...$args): void
6139
{
6240
$arguments = new FormulaArguments(...$args);
@@ -69,10 +47,7 @@ public function testIMCONJUGATEInWorksheet(mixed $expectedResult, mixed ...$args
6947
$result = $worksheet->setCellValue('A1', $formula)
7048
->getCell('A1')
7149
->getCalculatedValue();
72-
self::assertTrue(
73-
$this->complexAssert->assertComplexEquals($expectedResult, $result, self::COMPLEX_PRECISION),
74-
$this->complexAssert->getErrorMessage()
75-
);
50+
$this->assertComplexEquals($expectedResult, $result);
7651

7752
$spreadsheet->disconnectWorksheets();
7853
}
@@ -82,7 +57,7 @@ public static function providerIMCONJUGATE(): array
8257
return require 'tests/data/Calculation/Engineering/IMCONJUGATE.php';
8358
}
8459

85-
#[\PHPUnit\Framework\Attributes\DataProvider('providerUnhappyIMCONJUGATE')]
60+
#[DataProvider('providerUnhappyIMCONJUGATE')]
8661
public function testIMCONJUGATEUnhappyPath(string $expectedException, mixed ...$args): void
8762
{
8863
$arguments = new FormulaArguments(...$args);
@@ -108,13 +83,13 @@ public static function providerUnhappyIMCONJUGATE(): array
10883
];
10984
}
11085

111-
#[\PHPUnit\Framework\Attributes\DataProvider('providerImConjugateArray')]
86+
#[DataProvider('providerImConjugateArray')]
11287
public function testImConjugateArray(array $expectedResult, string $complex): void
11388
{
11489
$calculation = Calculation::getInstance();
11590

11691
$formula = "=IMCONJUGATE({$complex})";
117-
$result = $calculation->_calculateFormulaValue($formula);
92+
$result = $calculation->calculateFormula($formula);
11893
self::assertEquals($expectedResult, $result);
11994
}
12095

tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImCosTest.php

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,21 @@
77
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
88
use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions;
99
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException;
10-
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
1110
use PhpOffice\PhpSpreadsheet\Spreadsheet;
1211
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
1312
use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert;
14-
use PHPUnit\Framework\TestCase;
13+
use PHPUnit\Framework\Attributes\DataProvider;
1514

16-
class ImCosTest extends TestCase
15+
class ImCosTest extends ComplexAssert
1716
{
18-
const COMPLEX_PRECISION = 1E-12;
19-
20-
private ComplexAssert $complexAssert;
21-
22-
protected function setUp(): void
23-
{
24-
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
25-
$this->complexAssert = new ComplexAssert();
26-
}
27-
28-
#[\PHPUnit\Framework\Attributes\DataProvider('providerIMCOS')]
17+
#[DataProvider('providerIMCOS')]
2918
public function testDirectCallToIMCOS(string $expectedResult, string $arg): void
3019
{
3120
$result = ComplexFunctions::IMCOS($arg);
32-
self::assertTrue(
33-
$this->complexAssert->assertComplexEquals($expectedResult, $result, self::COMPLEX_PRECISION),
34-
$this->complexAssert->getErrorMessage()
35-
);
36-
}
37-
38-
private function trimIfQuoted(string $value): string
39-
{
40-
return trim($value, '"');
21+
$this->assertComplexEquals($expectedResult, $result);
4122
}
4223

43-
#[\PHPUnit\Framework\Attributes\DataProvider('providerIMCOS')]
24+
#[DataProvider('providerIMCOS')]
4425
public function testIMCOSAsFormula(mixed $expectedResult, mixed ...$args): void
4526
{
4627
$arguments = new FormulaArguments(...$args);
@@ -49,14 +30,11 @@ public function testIMCOSAsFormula(mixed $expectedResult, mixed ...$args): void
4930
$formula = "=IMCOS({$arguments})";
5031

5132
/** @var float|int|string */
52-
$result = $calculation->_calculateFormulaValue($formula);
53-
self::assertTrue(
54-
$this->complexAssert->assertComplexEquals($expectedResult, $this->trimIfQuoted((string) $result), self::COMPLEX_PRECISION),
55-
$this->complexAssert->getErrorMessage()
56-
);
33+
$result = $calculation->calculateFormula($formula);
34+
$this->assertComplexEquals($expectedResult, $result);
5735
}
5836

59-
#[\PHPUnit\Framework\Attributes\DataProvider('providerIMCOS')]
37+
#[DataProvider('providerIMCOS')]
6038
public function testIMCOSInWorksheet(mixed $expectedResult, mixed ...$args): void
6139
{
6240
$arguments = new FormulaArguments(...$args);
@@ -69,10 +47,7 @@ public function testIMCOSInWorksheet(mixed $expectedResult, mixed ...$args): voi
6947
$result = $worksheet->setCellValue('A1', $formula)
7048
->getCell('A1')
7149
->getCalculatedValue();
72-
self::assertTrue(
73-
$this->complexAssert->assertComplexEquals($expectedResult, $result, self::COMPLEX_PRECISION),
74-
$this->complexAssert->getErrorMessage()
75-
);
50+
$this->assertComplexEquals($expectedResult, $result);
7651

7752
$spreadsheet->disconnectWorksheets();
7853
}
@@ -82,7 +57,7 @@ public static function providerIMCOS(): array
8257
return require 'tests/data/Calculation/Engineering/IMCOS.php';
8358
}
8459

85-
#[\PHPUnit\Framework\Attributes\DataProvider('providerUnhappyIMCOS')]
60+
#[DataProvider('providerUnhappyIMCOS')]
8661
public function testIMCOSUnhappyPath(string $expectedException, mixed ...$args): void
8762
{
8863
$arguments = new FormulaArguments(...$args);
@@ -108,13 +83,13 @@ public static function providerUnhappyIMCOS(): array
10883
];
10984
}
11085

111-
#[\PHPUnit\Framework\Attributes\DataProvider('providerImCosArray')]
86+
#[DataProvider('providerImCosArray')]
11287
public function testImCosArray(array $expectedResult, string $complex): void
11388
{
11489
$calculation = Calculation::getInstance();
11590

11691
$formula = "=IMCOS({$complex})";
117-
$result = $calculation->_calculateFormulaValue($formula);
92+
$result = $calculation->calculateFormula($formula);
11893
self::assertEquals($expectedResult, $result);
11994
}
12095

tests/PhpSpreadsheetTests/Calculation/Functions/Engineering/ImCoshTest.php

Lines changed: 12 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,21 @@
77
use PhpOffice\PhpSpreadsheet\Calculation\Calculation;
88
use PhpOffice\PhpSpreadsheet\Calculation\Engineering\ComplexFunctions;
99
use PhpOffice\PhpSpreadsheet\Calculation\Exception as CalculationException;
10-
use PhpOffice\PhpSpreadsheet\Calculation\Functions;
1110
use PhpOffice\PhpSpreadsheet\Spreadsheet;
1211
use PhpOffice\PhpSpreadsheetTests\Calculation\Functions\FormulaArguments;
1312
use PhpOffice\PhpSpreadsheetTests\Custom\ComplexAssert;
14-
use PHPUnit\Framework\TestCase;
13+
use PHPUnit\Framework\Attributes\DataProvider;
1514

16-
class ImCoshTest extends TestCase
15+
class ImCoshTest extends ComplexAssert
1716
{
18-
const COMPLEX_PRECISION = 1E-12;
19-
20-
private ComplexAssert $complexAssert;
21-
22-
protected function setUp(): void
23-
{
24-
Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL);
25-
$this->complexAssert = new ComplexAssert();
26-
}
27-
28-
#[\PHPUnit\Framework\Attributes\DataProvider('providerIMCOSH')]
17+
#[DataProvider('providerIMCOSH')]
2918
public function testDirectCallToIMCOSH(string $expectedResult, string $arg): void
3019
{
3120
$result = ComplexFunctions::IMCOSH($arg);
32-
self::assertTrue(
33-
$this->complexAssert->assertComplexEquals($expectedResult, $result, self::COMPLEX_PRECISION),
34-
$this->complexAssert->getErrorMessage()
35-
);
36-
}
37-
38-
private function trimIfQuoted(string $value): string
39-
{
40-
return trim($value, '"');
21+
$this->assertComplexEquals($expectedResult, $result);
4122
}
4223

43-
#[\PHPUnit\Framework\Attributes\DataProvider('providerIMCOSH')]
24+
#[DataProvider('providerIMCOSH')]
4425
public function testIMCOSHAsFormula(mixed $expectedResult, mixed ...$args): void
4526
{
4627
$arguments = new FormulaArguments(...$args);
@@ -49,14 +30,11 @@ public function testIMCOSHAsFormula(mixed $expectedResult, mixed ...$args): void
4930
$formula = "=IMCOSH({$arguments})";
5031

5132
/** @var float|int|string */
52-
$result = $calculation->_calculateFormulaValue($formula);
53-
self::assertTrue(
54-
$this->complexAssert->assertComplexEquals($expectedResult, $this->trimIfQuoted((string) $result), self::COMPLEX_PRECISION),
55-
$this->complexAssert->getErrorMessage()
56-
);
33+
$result = $calculation->calculateFormula($formula);
34+
$this->assertComplexEquals($expectedResult, $result);
5735
}
5836

59-
#[\PHPUnit\Framework\Attributes\DataProvider('providerIMCOSH')]
37+
#[DataProvider('providerIMCOSH')]
6038
public function testIMCOSHInWorksheet(mixed $expectedResult, mixed ...$args): void
6139
{
6240
$arguments = new FormulaArguments(...$args);
@@ -69,10 +47,7 @@ public function testIMCOSHInWorksheet(mixed $expectedResult, mixed ...$args): vo
6947
$result = $worksheet->setCellValue('A1', $formula)
7048
->getCell('A1')
7149
->getCalculatedValue();
72-
self::assertTrue(
73-
$this->complexAssert->assertComplexEquals($expectedResult, $result, self::COMPLEX_PRECISION),
74-
$this->complexAssert->getErrorMessage()
75-
);
50+
$this->assertComplexEquals($expectedResult, $result);
7651

7752
$spreadsheet->disconnectWorksheets();
7853
}
@@ -82,7 +57,7 @@ public static function providerIMCOSH(): array
8257
return require 'tests/data/Calculation/Engineering/IMCOSH.php';
8358
}
8459

85-
#[\PHPUnit\Framework\Attributes\DataProvider('providerUnhappyIMCOSH')]
60+
#[DataProvider('providerUnhappyIMCOSH')]
8661
public function testIMCOSHUnhappyPath(string $expectedException, mixed ...$args): void
8762
{
8863
$arguments = new FormulaArguments(...$args);
@@ -108,13 +83,13 @@ public static function providerUnhappyIMCOSH(): array
10883
];
10984
}
11085

111-
#[\PHPUnit\Framework\Attributes\DataProvider('providerImCoshArray')]
86+
#[DataProvider('providerImCoshArray')]
11287
public function testImCoshArray(array $expectedResult, string $complex): void
11388
{
11489
$calculation = Calculation::getInstance();
11590

11691
$formula = "=IMCOSH({$complex})";
117-
$result = $calculation->_calculateFormulaValue($formula);
92+
$result = $calculation->calculateFormula($formula);
11893
self::assertEquals($expectedResult, $result);
11994
}
12095

0 commit comments

Comments
 (0)