1
0
Fork 0
composer/tests/Composer/Test
Juliette f5a0dfeb50
PHP 8.1: fix deprecation warnings about incorrect default values (#10036)
* PHP 8.1/Tests: fix some deprecation warnings

The default value for the `preg_split()` `$limit` parameter is `-1`, not `null`.

Fixes numerous `preg_split(): Passing null to parameter #3 ($limit) of type int is deprecated` notices when running the test suite.

Ref: https://www.php.net/manual/en/function.preg-split.php

* PHP 8.1/NoProxyPattern: fix deprecation warning

The default value for the `preg_split()` `$limit` parameter is `-1`, not `null`.

Fixes some `preg_split(): Passing null to parameter #3 ($limit) of type int is deprecated` notices when running the test suite.

```
Deprecation triggered by Composer\Test\Util\Http\ProxyManagerTest::testGetProxyForRequest:
preg_split(): Passing null to parameter #3 ($limit) of type int is deprecated

Stack trace:
0 [internal function]: Symfony\Bridge\PhpUnit\DeprecationErrorHandler->handleError(8192, '...', '...', 42)
1 src/Composer/Util/NoProxyPattern.php(42): preg_split('...', '...', NULL, 1)
2 src/Composer/Util/Http/ProxyManager.php(148): Composer\Util\NoProxyPattern->__construct('...')
3 src/Composer/Util/Http/ProxyManager.php(50): Composer\Util\Http\ProxyManager->initProxyData()
4 src/Composer/Util/Http/ProxyManager.php(59): Composer\Util\Http\ProxyManager->__construct()
5 tests/Composer/Test/Util/Http/ProxyManagerTest.php(75): Composer\Util\Http\ProxyManager::getInstance()
...
```

Ref: https://www.php.net/manual/en/function.preg-split.php

* PHP 8.1: fix deprecation warnings / http_build_query()

This fixes all relevant calls to the PHP native `http_build_query()` function.
The second parameter of which is the _optional_ `$numeric_prefix` parameter which expects a `string`.

A parameter being optional, however, does not automatically make it nullable.

As of PHP 8.1, passing `null` to a non-nullable PHP native function will generate a deprecation notice.
In this case, these function calls yielded a `http_build_query(): Passing null to parameter #2 ($numeric_prefix) of type string is deprecated` notice.

Changing the `null` to an empty string fixes this without BC-break.

Fixes a few deprecation warnings found when running the tests.

Refs:
* https://www.php.net/manual/en/function.http-build-query.php
* https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg

* PHP 8.1: fix deprecation notices / PharData::__construct()

This fixes all relevant calls to the PHP native `PharData::__construct()` method.

The second parameter of this method is the _optional_ `$flags` parameter which expects an `int` of flags to be passed to the `Phar` parent class `RecursiveDirectoryIterator`.
Fixed by passing the default value for the `$flags` parameter as per the `RecursiveDirectoryIterator::__construct()` method.

The third parameter of the method is the _optional_ `$alias` parameter which expects an `string`.
Fixed by passing an empty string.

Fixes various notices along the lines of:
```
Deprecation triggered by Composer\Test\Package\Archiver\ArchiveManagerTest::testArchiveTar:
PharData::__construct(): Passing null to parameter #2 ($flags) of type int is deprecated

Stack trace:
0 [internal function]: Symfony\Bridge\PhpUnit\DeprecationErrorHandler->handleError(8192, '...', '...', 55)
1 src/Composer/Package/Archiver/PharArchiver.php(55): PharData->__construct('...', NULL, NULL, 2)
2 src/Composer/Package/Archiver/ArchiveManager.php(193): Composer\Package\Archiver\PharArchiver->archive('...', '...', '...', Array, false)
3 tests/Composer/Test/Package/Archiver/ArchiveManagerTest.php(65): Composer\Package\Archiver\ArchiveManager->archive(Object(Composer\Package\CompletePackage), '...', '...')
...
```

Refs:
* https://www.php.net/manual/en/phardata.construct.php
* https://www.php.net/manual/en/recursivedirectoryiterator.construct.php

Co-authored-by: jrfnl <jrfnl@users.noreply.github.com>
2021-08-11 13:05:45 +02:00
..
Autoload Add support for autoloading Enums 2021-02-06 15:51:18 +07:00
Command Fix CS 2021-06-03 10:38:38 +02:00
Config Make sure empty objects are not left behind when removing requires/.. fixes #9462 2020-11-12 11:09:15 +01:00
Console PHPStan fixes 2020-02-07 23:10:10 +01:00
DependencyResolver PHP 8.1: fix deprecation warnings about incorrect default values (#10036) 2021-08-11 13:05:45 +02:00
Downloader Fix CS 2021-06-03 10:38:38 +02:00
EventDispatcher CS fixes 2020-11-22 14:52:39 +01:00
Fixtures Pin versions to avoid new dependencies breaking tests 2021-08-04 16:39:19 +02:00
IO Fix warnings on higher phpunit versions 2020-09-11 11:01:32 +02:00
Installer Remove OperationInterface::getReason, closes #9230, closes #9263 2020-10-12 12:31:54 +02:00
Json Fix JsonFile when using custom json schema with no "name" and "description" properties 2021-06-03 20:15:35 +02:00
Mock Fix support for writing into UNC paths, and comparing UNC paths correctly in InstalledVersions, fixes #9993 2021-07-12 14:03:00 +02:00
Package Use a simpler suggested require version of * to keep things simple for extensions which are versioned like PHP, fixes #9483 2021-05-17 14:36:46 +02:00
Platform Fix some PHP 8.1 deprecation warnings, fixes #10008 2021-07-21 15:13:24 +02:00
Plugin Merge pull request #9822 from phenaproxima/post-file-download 2021-04-09 14:53:20 +02:00
Question CS fixes 2020-11-22 14:52:39 +01:00
Repository Fix only/exclude to avoid matching names as sub-strings of full package names, fixes #10001 2021-07-22 13:47:31 +02:00
Script Some phpstan level 4 fixes 2021-06-03 11:29:00 +02:00
Util Fix some PHP 8.1 deprecation warnings, fixes #10008 2021-07-21 15:13:24 +02:00
AllFunctionalTest.php PHP 8.1: fix deprecation warnings about incorrect default values (#10036) 2021-08-11 13:05:45 +02:00
ApplicationTest.php Fix env var handling when variables_order includes E and symfony/console 3.3.15+ is used, fixes #9930 2021-06-03 10:17:54 +02:00
CacheTest.php CS fixes 2020-11-22 14:52:39 +01:00
ComposerTest.php CS fixes 2020-11-22 14:52:39 +01:00
ConfigTest.php Fix/add tests and also handle case where a json object is used 2021-02-11 11:13:58 +01:00
DefaultConfigTest.php CS fixes 2020-11-22 14:52:39 +01:00
FactoryTest.php Fix factory test 2019-01-14 17:29:23 +01:00
InstalledVersionsTest.php Fix handling of metapackages with null paths, and handling of paths which do not have a shortest-path and require an absolute path to be addressed 2021-05-21 14:33:10 +02:00
InstallerTest.php PHP 8.1: fix deprecation warnings about incorrect default values (#10036) 2021-08-11 13:05:45 +02:00
PolyfillTestCase.php CS fixes 2020-11-22 14:52:39 +01:00
TestCase.php Bump phpstan to level 3 (#9734) 2021-03-09 15:49:40 +01:00