Skip to content

Commit 9b239eb

Browse files
committed
Phpunit 10 and Phpstan 1.11
Dependabot suggested some changes this month which required an unusual effort to implement successfully. With the elimination of Php 8.0 as a supported environment, it became possible to use Phpunit 10 rather than 9. Among other considerations, the configuration file for Phpunit is changed. I preserved the Phpunit 9 version under a different name. Aside from the configuration change, several other changes needed to be made to accommodate the change: - Fix PHPOffice#3993. A peculiar problem indeed. One of the reporters said it had something to do with mocking, but I couldn't duplicate it. But Phpunit 10 revealed the problem in one test (Reader/Xlsx/AutoFilterTest), and that was sufficient for me to apply the trivial source code change to Worksheet/Worksheet. - Some extra stringency on data providers required extra work in Calculation/CalculationFunctionListTest. - There was a misplaced label in Calculation/ParseFormulaTest. Likewise in the data member CellGetRangeBoundaries. - More stringency required changes to data members Shared/Trend/ExponentialBestFit and Shared/Trend/LinearBestFit. - Issue3982Test testLoadAllRows seemed to go into a memory-acquiring loop in 10 that was not evident in 9. This particular test uses a lot of memory by design, but was included only to establish a base level for the other tests in that member. I feel it is acceptable to skip it for 10. Phpstan errors with a new release are not unusual. One of the problems this time around was, however, unusual - it is fixed when Phpstan runs under Php8.3, but not for earlier Php releases. Our tools currently use Php 8.1. It is on my to-do list to get Phpstan and other test tools running under 8.3 before 8.1 goes EOL. There are also some configuration file changes needed for Phpstan. Php-cs-fixer has been taking an increasingly long time to run. They've added an experimental option to permit it to run its checks in parallel. I've changed its configuration to use that option.
1 parent 101f903 commit 9b239eb

File tree

16 files changed

+314
-404
lines changed

16 files changed

+314
-404
lines changed

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
$config
1111
->setRiskyAllowed(true)
1212
->setFinder($finder)
13+
->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect())
1314
->setCacheFile(sys_get_temp_dir() . '/php-cs-fixer' . preg_replace('~\W~', '-', __DIR__))
1415
->setRules([
1516
'align_multiline_comment' => true,

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
"phpcompatibility/php-compatibility": "^9.3",
9696
"phpstan/phpstan": "^1.1",
9797
"phpstan/phpstan-phpunit": "^1.0",
98-
"phpunit/phpunit": "^9.6",
98+
"phpunit/phpunit": "^9.6 || ^10.5",
9999
"squizlabs/php_codesniffer": "^3.7",
100100
"tecnickcom/tcpdf": "^6.5"
101101
},

composer.lock

Lines changed: 248 additions & 365 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan.neon.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ parameters:
2222
- src/PhpSpreadsheet/Writer/ZipStream3.php
2323
parallel:
2424
processTimeout: 300.0
25-
checkMissingIterableValueType: false
26-
checkGenericClassInNonGenericObjectType: false
2725
ignoreErrors:
2826
# Accept a bit anything for assert methods
2927
- '~^Parameter \#2 .* of static method PHPUnit\\Framework\\Assert\:\:assert\w+\(\) expects .*, .* given\.$~'
3028
- '~^Variable \$helper might not be defined\.$~'
29+
- identifier: missingType.iterableValue
30+
- identifier: missingType.generics

phpunit.xml.dist

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="./tests/bootstrap.php" backupGlobals="true" colors="true" cacheResultFile="/tmp/.phpspreadsheet.phpunit.result.cache" convertDeprecationsToExceptions="true">
3-
<coverage>
4-
<include>
5-
<directory suffix=".php">./src</directory>
6-
</include>
7-
</coverage>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd" bootstrap="./tests/bootstrap.php" backupGlobals="true" colors="true" cacheResultFile="/tmp/.phpspreadsheet.phpunit.result.cache">
3+
<coverage/>
84
<php>
95
<ini name="memory_limit" value="2048M"/>
10-
<ini name="error_reporting" value="E_ALL"/>
116
</php>
127
<testsuite name="PhpSpreadsheet Unit Test Suite">
138
<directory>./tests/PhpSpreadsheetTests</directory>
149
</testsuite>
10+
<source>
11+
<include>
12+
<directory suffix=".php">./src</directory>
13+
</include>
14+
</source>
1515
</phpunit>

phpunit9.xml.dist

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" bootstrap="./tests/bootstrap.php" backupGlobals="true" colors="true" cacheResultFile="/tmp/.phpspreadsheet.phpunit.result.cache" convertDeprecationsToExceptions="true">
3+
<coverage>
4+
<include>
5+
<directory suffix=".php">./src</directory>
6+
</include>
7+
</coverage>
8+
<php>
9+
<ini name="memory_limit" value="2048M"/>
10+
<ini name="error_reporting" value="E_ALL"/>
11+
</php>
12+
<testsuite name="PhpSpreadsheet Unit Test Suite">
13+
<directory>./tests/PhpSpreadsheetTests</directory>
14+
</testsuite>
15+
</phpunit>

src/PhpSpreadsheet/Helper/Html.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ private function rgbToColour(string $rgbValue): string
694694
{
695695
preg_match_all('/\d+/', $rgbValue, $values);
696696
foreach ($values[0] as &$value) {
697-
$value = str_pad(dechex($value), 2, '0', STR_PAD_LEFT);
697+
$value = str_pad(dechex((int) $value), 2, '0', STR_PAD_LEFT);
698698
}
699699

700700
return implode('', $values[0]);

src/PhpSpreadsheet/Reader/Html.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ private function readBeginning(): string
169169
private function readEnding(): string
170170
{
171171
$meta = stream_get_meta_data($this->fileHandle);
172-
$filename = $meta['uri'];
172+
// Phpstan incorrectly flags following line for Php8.2-, corrected in 8.3
173+
$filename = $meta['uri']; //@phpstan-ignore-line
173174

174175
$size = (int) filesize($filename);
175176
if ($size === 0) {

src/PhpSpreadsheet/Worksheet/Worksheet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Worksheet implements IComparable
6767
/**
6868
* Parent spreadsheet.
6969
*/
70-
private ?Spreadsheet $parent;
70+
private ?Spreadsheet $parent = null;
7171

7272
/**
7373
* Collection of cells.

src/PhpSpreadsheet/Writer/Xls/Worksheet.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2374,7 +2374,7 @@ public function processBitmap(string $bitmap): array
23742374
{
23752375
// Open file.
23762376
$bmp_fd = @fopen($bitmap, 'rb');
2377-
if ($bmp_fd === false) {
2377+
if ($bmp_fd === false || 0 === (int) filesize($bitmap)) {
23782378
throw new WriterException("Couldn't import $bitmap");
23792379
}
23802380

0 commit comments

Comments
 (0)