Skip to content

Commit ec773bb

Browse files
committed
Phpstan Bleeding Edge Part 2 of Many
This will be the biggest of these changes. It takes care of all of the remaining problems in tests. I will handle the problems in src more slowly.
1 parent cd7386f commit ec773bb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+132
-678
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 395 deletions
Large diffs are not rendered by default.

tests/PhpSpreadsheetTests/Calculation/CalculationLoggingTest.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ public function testFormulaWithLogging(): void
3131
self::assertEquals(6.7, $cell->getCalculatedValue());
3232

3333
$log = $debugLog->getLog();
34-
self::assertIsArray($log);
3534
$entries = count($log);
3635
self::assertGreaterThan(0, $entries);
3736

@@ -71,7 +70,6 @@ public function testFormulaWithMultipleCellLogging(): void
7170

7271
$log = $debugLog->getLog();
7372

74-
self::assertIsArray($log);
7573
$entries = count($log);
7674
self::assertGreaterThan(0, $entries);
7775

@@ -114,14 +112,12 @@ public function testFlushLog(): void
114112
self::assertEquals(-0.75, $cell->getCalculatedValue());
115113

116114
$log = $debugLog->getLog();
117-
self::assertIsArray($log);
118115
$entries = count($log);
119116
self::assertGreaterThan(0, $entries);
120117

121118
$debugLog->clearLog();
122119

123120
$log = $debugLog->getLog();
124-
self::assertIsArray($log);
125-
self::assertEmpty($log);
121+
self::assertSame([], $log);
126122
}
127123
}

tests/PhpSpreadsheetTests/Calculation/CalculationTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ public function testBranchPruningFormulaParsingNoArgumentFunctionCase(): void
343343
// this used to raise a parser error, we keep it even though we don't
344344
// test the output
345345
$calculation->parseFormula($formula);
346-
self::assertTrue(true);
346+
self::assertSame(1, $calculation->cyclicFormulaCount);
347347
}
348348

349349
public function testBranchPruningFormulaParsingInequalitiesConditionsCase(): void

tests/PhpSpreadsheetTests/Calculation/DefinedNameConfusedForCellTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@ public function testDefinedName(): void
1717
$obj = new Spreadsheet();
1818
$sheet0 = $obj->setActiveSheetIndex(0);
1919
$sheet0->setCellValue('A1', 2);
20-
$obj->addNamedRange(new NamedRange('A1A', $sheet0, 'A1'));
20+
$obj->addNamedRange(new NamedRange('A1A', $sheet0, '$A$1'));
2121
$sheet0->setCellValue('B1', '=2*A1A');
2222
$writer = IOFactory::createWriter($obj, 'Xlsx');
2323
$filename = File::temporaryFilename();
2424
$writer->save($filename);
25-
self::assertTrue(true);
2625
unlink($filename);
26+
self::assertSame(4, $obj->getActiveSheet()->getCell('B1')->getCalculatedValue());
27+
$obj->disconnectWorksheets();
2728
}
2829
}

tests/PhpSpreadsheetTests/Calculation/Engine/FormattedNumberSlashTest.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
use PhpOffice\PhpSpreadsheet\Calculation\Engine\FormattedNumber;
88
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
9+
use PHPUnit\Framework\Attributes\DataProvider;
910
use PHPUnit\Framework\TestCase;
1011

1112
class FormattedNumberSlashTest extends TestCase
@@ -17,14 +18,16 @@ protected function tearDown(): void
1718
StringHelper::setThousandsSeparator(null);
1819
}
1920

20-
#[\PHPUnit\Framework\Attributes\DataProvider('providerNumbers')]
21+
#[DataProvider('providerNumbers')]
2122
public function testNumber(float $expected, string $value, string $thousandsSeparator = ',', string $decimalSeparator = '.'): void
2223
{
2324
StringHelper::setThousandsSeparator($thousandsSeparator);
2425
StringHelper::setDecimalSeparator($decimalSeparator);
2526
$result = FormattedNumber::convertToNumberIfFormatted($value);
2627
self::assertTrue($result);
27-
self::assertSame($expected, $value);
28+
// Call by ref convert... changed type from string to float.
29+
// Phpstan can't figure that out.
30+
self::assertSame($expected, $value); // @phpstan-ignore-line
2831
}
2932

3033
public static function providerNumbers(): array
@@ -36,7 +39,7 @@ public static function providerNumbers(): array
3639
];
3740
}
3841

39-
#[\PHPUnit\Framework\Attributes\DataProvider('providerPercentages')]
42+
#[DataProvider('providerPercentages')]
4043
public function testPercentage(string $expected, string $value, string $thousandsSeparator = ',', string $decimalSeparator = '.'): void
4144
{
4245
$originalValue = $value;
@@ -57,7 +60,7 @@ public static function providerPercentages(): array
5760
];
5861
}
5962

60-
#[\PHPUnit\Framework\Attributes\DataProvider('providerCurrencies')]
63+
#[DataProvider('providerCurrencies')]
6164
public function testCurrencies(string $expected, string $value, string $thousandsSeparator = ',', string $decimalSeparator = '.', ?string $currencyCode = null): void
6265
{
6366
$originalValue = $value;

tests/PhpSpreadsheetTests/Calculation/Engine/FormattedNumberTest.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,18 @@
66

77
use PhpOffice\PhpSpreadsheet\Calculation\Engine\FormattedNumber;
88
use PhpOffice\PhpSpreadsheet\Shared\StringHelper;
9+
use PHPUnit\Framework\Attributes\DataProvider;
910
use PHPUnit\Framework\TestCase;
1011

1112
class FormattedNumberTest extends TestCase
1213
{
13-
#[\PHPUnit\Framework\Attributes\DataProvider('providerNumbers')]
14+
#[DataProvider('providerNumbers')]
1415
public function testNumber(float $expected, string $value): void
1516
{
1617
FormattedNumber::convertToNumberIfFormatted($value);
17-
self::assertSame($expected, $value);
18+
// Call by ref convert... changed type from string to float.
19+
// Phpstan can't figure that out.
20+
self::assertSame($expected, $value); // @phpstan-ignore-line
1821
}
1922

2023
public static function providerNumbers(): array
@@ -29,7 +32,7 @@ public static function providerNumbers(): array
2932
];
3033
}
3134

32-
#[\PHPUnit\Framework\Attributes\DataProvider('providerFractions')]
35+
#[DataProvider('providerFractions')]
3336
public function testFraction(string $expected, string $value): void
3437
{
3538
$originalValue = $value;
@@ -56,7 +59,7 @@ public static function providerFractions(): array
5659
];
5760
}
5861

59-
#[\PHPUnit\Framework\Attributes\DataProvider('providerPercentages')]
62+
#[DataProvider('providerPercentages')]
6063
public function testPercentage(string $expected, string $value): void
6164
{
6265
$originalValue = $value;
@@ -183,7 +186,7 @@ public static function providerPercentages(): array
183186
];
184187
}
185188

186-
#[\PHPUnit\Framework\Attributes\DataProvider('providerCurrencies')]
189+
#[DataProvider('providerCurrencies')]
187190
public function testCurrencies(string $expected, string $value): void
188191
{
189192
$originalValue = $value;

tests/PhpSpreadsheetTests/Calculation/Functions/FormulaArguments.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private function stringify(mixed $value): string
9292
public function __toString(): string
9393
{
9494
$args = array_map(
95-
[self::class, 'stringify'],
95+
self::stringify(...),
9696
$this->args
9797
);
9898

tests/PhpSpreadsheetTests/Cell/DataTypeTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class DataTypeTest extends TestCase
1313
public function testGetErrorCodes(): void
1414
{
1515
$result = DataType::getErrorCodes();
16-
self::assertIsArray($result);
1716
self::assertGreaterThan(0, count($result));
1817
self::assertArrayHasKey('#NULL!', $result);
1918
}

tests/PhpSpreadsheetTests/Cell/HyperlinkTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public function testSetUrl(): void
2626

2727
$testInstance = new Hyperlink($initialUrlValue);
2828
$result = $testInstance->setUrl($newUrlValue);
29-
self::assertInstanceOf(Hyperlink::class, $result);
3029

3130
$result = $testInstance->getUrl();
3231
self::assertEquals($newUrlValue, $result);
@@ -49,7 +48,6 @@ public function testSetTooltip(): void
4948

5049
$testInstance = new Hyperlink('', $initialTooltipValue);
5150
$result = $testInstance->setTooltip($newTooltipValue);
52-
self::assertInstanceOf(Hyperlink::class, $result);
5351

5452
$result = $testInstance->getTooltip();
5553
self::assertEquals($newTooltipValue, $result);

tests/PhpSpreadsheetTests/Chart/DataSeriesValues2Test.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ public function testDataSeriesValues(): void
145145
$plotArea2 = $chart2->getPlotArea();
146146
self::assertNotNull($plotArea2);
147147
$plotGroup2 = $plotArea2->getPlotGroup()[0];
148-
self::assertNotNull($plotGroup2);
149148
$plotValues2 = $plotGroup2->getPlotValues();
150149
self::assertCount(3, $plotValues2);
151150
self::assertSame([15.0, 73.0, 61.0, 32.0], $plotValues2[1]->getDataValues());

0 commit comments

Comments
 (0)